Skip to content

Commit 75046c6

Browse files
committed
tests added
1 parent 2bc315b commit 75046c6

5 files changed

Lines changed: 109 additions & 5 deletions

File tree

File renamed without changes.

pyproject.toml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["hatchling >= 1.26"]
33
build-backend = "hatchling.build"
44

55
[tool.hatch.build.targets.wheel]
6-
packages = ["knitting_pattern"]
6+
packages = ["src/knitting_pattern"]
77

88
[project]
99
name = "knitting_pattern"
@@ -15,14 +15,23 @@ description = "Kitting pattern calculator tool for my programming course"
1515
readme = "README.md"
1616
requires-python = ">=3.9"
1717
dependencies = [
18-
"numpy"
18+
"numpy",
19+
"Pillow",
20+
"streamlit"
1921
]
2022
classifiers = [
2123
"Programming Language :: Python :: 3",
2224
"Operating System :: OS Independent",
2325
]
24-
license = "MIT"
25-
license-files = ["LICEN[CS]E*"]
26+
license = {text = "MIT"}
27+
28+
[project.optional-dependencies]
29+
dev = [
30+
"pytest",
31+
]
2632

2733
[project.urls]
2834
Homepage = "https://github.com/Programming-The-Next-Step-2026/knitting_pattern.git"
35+
36+
[tool.pytest.ini_options]
37+
pythonpath = ["src"]

src/tests/test_example.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/test_image_engine.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed May 20 15:30:57 2026
5+
6+
@author: kasteivanauskaite
7+
"""
8+
from knitting_pattern.math_engine import (
9+
generate_panel_grid,
10+
apply_back_short_rows_to_grid
11+
)
12+
13+
# ==========================================
14+
# 1. GRID GENERATION TESTS
15+
# ==========================================
16+
def test_generate_panel_grid():
17+
# Create a small 10 stitch wide by 5 row tall test grid
18+
grid = generate_panel_grid(width_sts=10, length_rows=5)
19+
20+
# Check that it generated exactly 5 rows (Y-axis)
21+
assert len(grid) == 5
22+
# Check that the first row is exactly 10 stitches wide (X-axis)
23+
assert len(grid[0]) == 10
24+
# Check that it is initialized with zeroes
25+
assert grid[0][0] == 0
26+
27+
28+
# ==========================================
29+
# 2. SHAPING MATRIX MANIPULATION TESTS
30+
# ==========================================
31+
def test_apply_back_short_rows_to_grid():
32+
# Create a clean 20x10 test grid
33+
grid = generate_panel_grid(width_sts=20, length_rows=10)
34+
35+
# We will pass in 'mock' shaping data so we know exactly what to expect
36+
mock_shaping = {
37+
"total_short_row_steps": 2,
38+
"middle_stitch": 10,
39+
"neck_half_width": 2,
40+
"sts_per_step": 2
41+
}
42+
43+
carved_grid = apply_back_short_rows_to_grid(grid, mock_shaping)
44+
45+
# THE TEST: The outer corners should now be 'dead' canvas space (-1)
46+
assert carved_grid[0][0] == -1
47+
assert carved_grid[0][-1] == -1
48+
49+
# THE TEST: The active center neck stitches should remain untouched (0)
50+
assert carved_grid[0][10] == 0

src/tests/test_math_engine.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed May 20 15:14:10 2026
5+
6+
@author: kasteivanauskaite
7+
"""
8+
from knitting_pattern.math_engine import (
9+
calculate_stitches,
10+
calculate_rows,
11+
get_standard_body_measurements
12+
)
13+
14+
# ==========================================
15+
# 1. GAUGE CALCULATOR TESTS
16+
# ==========================================
17+
def test_calculate_stitches():
18+
# If a fabric is 10cm wide, and gauge is 20 sts per 10cm, we expect 20 stitches.
19+
assert calculate_stitches(10.0, 20.0) == 20
20+
21+
# If fabric is 15cm wide, and gauge is 22 sts per 10cm (2.2 sts/cm)
22+
# 15 * 2.2 = 33 stitches
23+
assert calculate_stitches(15.0, 22.0) == 33
24+
25+
# Testing rounding: 10.5cm * 2.2 = 23.1. Should round up to 24.
26+
assert calculate_stitches(10.5, 22.0) == 24
27+
28+
def test_calculate_rows():
29+
# 10cm length at 30 rows/10cm should equal 30 rows
30+
assert calculate_rows(10.0, 30.0) == 30
31+
32+
# ==========================================
33+
# 2. SIZING DATA TESTS
34+
# ==========================================
35+
def test_get_standard_body_measurements():
36+
# Test that size Medium returns the correct dictionary
37+
m_size = get_standard_body_measurements("M")
38+
assert m_size["chest_circ_cm"] == 96.0
39+
40+
# Test that lowercase inputs are handled properly
41+
s_size = get_standard_body_measurements("s")
42+
assert s_size["chest_circ_cm"] == 86.0
43+
44+
# Test fallback: an invalid size should default to Medium (96.0)
45+
invalid_size = get_standard_body_measurements("NONEXISTENT")
46+
assert invalid_size["chest_circ_cm"] == 96.0

0 commit comments

Comments
 (0)