@@ -49,31 +49,40 @@ def test_valid_total_errors() -> None:
4949
5050
5151def test_smoothness_less_than_three_points () -> None :
52- """Test smoothness calculation with less than three points ."""
52+ """Less than 3 points cannot define curvature ."""
5353 points = pd .DataFrame ({"x" : [0 , 1 ], "y" : [0 , 1 ]})
5454 assert drawing_metrics .calculate_smoothness (points ) == 0.0
5555
5656
5757def test_smoothness_straight_line () -> None :
58- """Collinear points should produce zero smoothness ."""
58+ """Collinear points have zero curvature ."""
5959 points = pd .DataFrame ({"x" : [0 , 1 , 2 , 3 ], "y" : [0 , 0 , 0 , 0 ]})
6060 assert drawing_metrics .calculate_smoothness (points ) == 0.0
6161
6262
6363def test_smoothness_single_right_angle () -> None :
64- """A single 90-degree turn should produce an std of 0."""
64+ """A single 90-degree corner should produce a large smoothness value.
65+
66+ (non-zero), since sharp turns are penalized.
67+ """
6568 points = pd .DataFrame ({"x" : [0 , 1 , 1 ], "y" : [0 , 0 , 1 ]})
69+ expected = np .pi / 2
6670 smoothness = drawing_metrics .calculate_smoothness (points )
67- assert smoothness == 0.0
71+ assert np . isclose ( smoothness , expected )
6872
6973
7074def test_smoothness_varied_angles () -> None :
71- """Test smoothness with two different angles to ensure std is computed correctly."""
75+ """Multiple angles should produce RMS curvature.
76+
77+ Path has a 90° turn followed by a 45° turn.
78+ """
7279 points = pd .DataFrame ({"x" : [0 , 1 , 1 , 2 ], "y" : [0 , 0 , 1 , 2 ]})
80+ c1 = np .pi / 2
81+ c2 = (np .pi / 4 ) / ((1 + np .sqrt (2 )) / 2 )
82+ expected = np .sqrt ((c1 ** 2 + c2 ** 2 ) / 2 )
7383
7484 smoothness = drawing_metrics .calculate_smoothness (points )
7585
76- expected = np .std ([90 , 45 ])
7786 assert np .isclose (smoothness , expected )
7887
7988
@@ -82,3 +91,17 @@ def test_smoothness_zero_length_segments() -> None:
8291 points = pd .DataFrame ({"x" : [0 , 1 , 1 , 2 ], "y" : [0 , 0 , 0 , 0 ]})
8392 smoothness = drawing_metrics .calculate_smoothness (points )
8493 assert smoothness == 0.0
94+
95+
96+ def test_smoothness_single_180_degree_turn () -> None :
97+ """A single 180-degree turn should produce a very large smoothness value.
98+
99+ Since it represents maximal curvature.
100+ """
101+ points = pd .DataFrame ({
102+ "x" : [0 , 1 , 0 ],
103+ "y" : [0 , 0 , 0 ],
104+ })
105+ expected = np .pi
106+ smoothness = drawing_metrics .calculate_smoothness (points )
107+ assert np .isclose (smoothness , expected )
0 commit comments