11"""
2- Unit tests for bot.core.curve.BezierCurve .
2+ Unit tests for bot.core.curve.SplineModel .
33
4- The external Rust dependency (nurbslib ) is mocked to allow testing the
4+ The external Rust dependency (ferrispline ) is mocked to allow testing the
55Python bridge and logic without requiring the compiled engine.
66"""
77
88import unittest
99from unittest .mock import MagicMock , patch
1010import numpy as np
1111
12- from bot .core .curve import BezierCurve
12+ from bot .core .spline import SplineModel
1313
1414
15- class TestBezierCurve (unittest .TestCase ):
16- @patch ("bot.core.curve.nurbslib " )
15+ class TestSplineModel (unittest .TestCase ):
16+ @patch ("bot.core.spline.ferrispline " )
1717 def test_initialization_and_attributes (self , mock_nurbslib ):
1818 """Tests the initialization of the curve and access to its basic attributes."""
1919 # 1. Data preparation
2020 tag = "curve_1"
2121 control_points = [[0.0 , 0.0 , 0.0 ], [5.0 , 5.0 , 0.0 ], [10.0 , 0.0 , 0.0 ]]
2222 degree = 2
2323
24- # 2. Mock configuration to simulate the nurbslib engine
25- mock_engine_instance = MagicMock ()
26- mock_engine_instance . get_control_points .return_value = np . array ( control_points )
27- mock_engine_instance . get_degree .return_value = degree
28- mock_nurbslib .PyBezierCurve .return_value = mock_engine_instance
24+ # 2. Mock configuration to simulate the ferrispline engine
25+ mock_model_instance = MagicMock ()
26+ mock_model_instance . create_bezier .return_value = "curve-1"
27+ mock_model_instance . evaluate .return_value = np . array ( control_points )
28+ mock_nurbslib .PyModel .return_value = mock_model_instance
2929
3030 # 3. Object creation
31- curve = BezierCurve (tag , control_points , degree )
31+ curve = SplineModel (tag , control_points , degree )
3232
3333 # 4. Verifications (Assertions)
3434 self .assertEqual (curve .get_tag (), "curve_1" )
3535 self .assertEqual (curve .get_control_points (), control_points )
3636 self .assertEqual (curve .get_degree (), degree )
3737
38- # Ensure the Rust engine was called with the correct arguments
39- mock_nurbslib .PyBezierCurve .assert_called_once ()
40- args , kwargs = mock_nurbslib . PyBezierCurve .call_args
38+ # Ensure the Rust model was called with the correct arguments
39+ mock_nurbslib .PyModel .assert_called_once ()
40+ args , kwargs = mock_model_instance . create_bezier .call_args
4141 self .assertEqual (args [0 ], degree )
4242 np .testing .assert_array_equal (args [1 ], np .array (control_points ))
4343 self .assertIsNone (args [2 ])
@@ -48,7 +48,7 @@ def test_default_control_points_default_degree(self):
4848 coords_b = [30.0 , 0.0 , 0.0 ]
4949
5050 # Call WITHOUT specifying the degree
51- pts = BezierCurve ._default_control_points (coords_a , coords_b )
51+ pts = SplineModel ._default_control_points (coords_a , coords_b )
5252
5353 # Since the default degree is 3, we expect 3 + 1 = 4 points
5454 expected_pts = [
@@ -67,7 +67,7 @@ def test_default_control_points_distribution(self):
6767 degree = 2
6868
6969 # Execute static method
70- pts = BezierCurve ._default_control_points (coords_a , coords_b , degree )
70+ pts = SplineModel ._default_control_points (coords_a , coords_b , degree )
7171
7272 # We expect 3 points: point A, middle point, and point B
7373 expected_pts = [[0.0 , 0.0 , 0.0 ], [5.0 , 0.0 , 0.0 ], [10.0 , 0.0 , 0.0 ]]
@@ -80,21 +80,21 @@ def test_default_control_points_count(self):
8080
8181 # We check for several different degrees
8282 for degree in [1 , 3 , 5 , 10 ]:
83- pts = BezierCurve ._default_control_points (coords_a , coords_b , degree )
83+ pts = SplineModel ._default_control_points (coords_a , coords_b , degree )
8484 self .assertEqual (len (pts ), degree + 1 )
8585
8686 def test_default_control_points_degree_zero (self ):
8787 """Tests the edge case where the curve degree is 0."""
8888 coords_a = [1.0 , 2.0 , 3.0 ]
8989 coords_b = [4.0 , 5.0 , 6.0 ]
9090
91- pts = BezierCurve ._default_control_points (coords_a , coords_b , degree = 0 )
91+ pts = SplineModel ._default_control_points (coords_a , coords_b , degree = 0 )
9292
9393 # For degree 0, there must be only one point (point A)
9494 self .assertEqual (len (pts ), 1 )
9595 self .assertEqual (pts [0 ], coords_a )
9696
97- @patch ("bot.core.curve.nurbslib " )
97+ @patch ("bot.core.spline.ferrispline " )
9898 def test_get_render_data (self , mock_nurbslib ):
9999 """Tests the structure and content of the render dictionary (used by the viewer)."""
100100 tag = "42"
@@ -105,14 +105,13 @@ def test_get_render_data(self, mock_nurbslib):
105105 mock_curve_eval = [[0.0 , 0.0 , 0.0 ], [0.5 , 0.5 , 0.5 ], [1.0 , 1.0 , 1.0 ]]
106106
107107 # Mock configuration
108- mock_engine_instance = MagicMock ()
109- mock_engine_instance .get_control_points .return_value = np .array (control_points )
110- mock_engine_instance .get_degree .return_value = degree
111- mock_engine_instance .evaluate .return_value = np .array (mock_curve_eval )
112- mock_nurbslib .PyBezierCurve .return_value = mock_engine_instance
108+ mock_model_instance = MagicMock ()
109+ mock_model_instance .create_bezier .return_value = "curve-42"
110+ mock_model_instance .evaluate .return_value = np .array (mock_curve_eval )
111+ mock_nurbslib .PyModel .return_value = mock_model_instance
113112
114113 # Object creation and data retrieval
115- curve = BezierCurve (tag , control_points , degree )
114+ curve = SplineModel (tag , control_points , degree )
116115 data = curve .get_render_data ()
117116
118117 # Verification of the presence of all required keys
@@ -128,7 +127,7 @@ def test_get_render_data(self, mock_nurbslib):
128127 self .assertEqual (data ["curve" ], mock_curve_eval )
129128
130129 # Ensure the engine was called to generate 100 points
131- mock_engine_instance .evaluate .assert_called_once_with (100 , False )
130+ mock_model_instance .evaluate .assert_called_once_with ("curve-42" , 100 )
132131
133132
134133if __name__ == "__main__" :
0 commit comments