|
9 | 9 | from graphomotor.utils import trails_utils |
10 | 10 |
|
11 | 11 |
|
| 12 | +@pytest.mark.parametrize( |
| 13 | + "points_data,start_params,end_params,expected_start,expected_end,test_id", |
| 14 | + [ |
| 15 | + ( |
| 16 | + {"x": [0, 1, 2, 3, 4, 5], "y": [0, 1, 2, 3, 4, 5]}, |
| 17 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 0.5}, |
| 18 | + {"order": 2, "label": "B", "center_x": 5, "center_y": 5, "radius": 0.5}, |
| 19 | + 1, |
| 20 | + 5, |
| 21 | + "valid_trajectory", |
| 22 | + ), |
| 23 | + ( |
| 24 | + {"x": [0.1, 0.2, 0.3], "y": [0.1, 0.2, 0.3]}, |
| 25 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 1.0}, |
| 26 | + {"order": 2, "label": "B", "center_x": 10, "center_y": 10, "radius": 1.0}, |
| 27 | + None, |
| 28 | + None, |
| 29 | + "no_exit_from_start", |
| 30 | + ), |
| 31 | + ( |
| 32 | + {"x": [0, 1, 2, 3], "y": [0, 1, 2, 3]}, |
| 33 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 0.5}, |
| 34 | + {"order": 2, "label": "B", "center_x": 10, "center_y": 10, "radius": 0.5}, |
| 35 | + 1, |
| 36 | + None, |
| 37 | + "never_reaches_end", |
| 38 | + ), |
| 39 | + ( |
| 40 | + {"x": [], "y": []}, |
| 41 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 1.0}, |
| 42 | + {"order": 2, "label": "B", "center_x": 5, "center_y": 5, "radius": 1.0}, |
| 43 | + None, |
| 44 | + None, |
| 45 | + "empty_dataframe", |
| 46 | + ), |
| 47 | + ( |
| 48 | + {"x": [0.1], "y": [0.1]}, |
| 49 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 1.0}, |
| 50 | + {"order": 2, "label": "B", "center_x": 5, "center_y": 5, "radius": 1.0}, |
| 51 | + None, |
| 52 | + None, |
| 53 | + "single_point_in_start", |
| 54 | + ), |
| 55 | + ( |
| 56 | + {"x": [2], "y": [2]}, |
| 57 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 0.5}, |
| 58 | + {"order": 2, "label": "B", "center_x": 5, "center_y": 5, "radius": 0.5}, |
| 59 | + 0, |
| 60 | + None, |
| 61 | + "single_point_outside_start", |
| 62 | + ), |
| 63 | + ( |
| 64 | + {"x": [0, 2.5, 5], "y": [0, 2.5, 5]}, |
| 65 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 0.5}, |
| 66 | + {"order": 2, "label": "B", "center_x": 2.5, "center_y": 2.5, "radius": 1.0}, |
| 67 | + 1, |
| 68 | + 1, |
| 69 | + "immediate_transition", |
| 70 | + ), |
| 71 | + ( |
| 72 | + {"x": [3, 4, 5], "y": [3, 4, 5]}, |
| 73 | + {"order": 1, "label": "A", "center_x": 0, "center_y": 0, "radius": 0.5}, |
| 74 | + {"order": 2, "label": "B", "center_x": 5, "center_y": 5, "radius": 0.5}, |
| 75 | + 0, |
| 76 | + 2, |
| 77 | + "first_point_outside_start", |
| 78 | + ), |
| 79 | + ], |
| 80 | + ids=lambda x: x if isinstance(x, str) else "", |
| 81 | +) |
| 82 | +def test_valid_ink_trajectory_scenarios( |
| 83 | + points_data: Dict[str, list], |
| 84 | + start_params: Dict, |
| 85 | + end_params: Dict, |
| 86 | + expected_start: int, |
| 87 | + expected_end: int, |
| 88 | + test_id: str, |
| 89 | +) -> None: |
| 90 | + """Test various trajectory scenarios between start and end circles.""" |
| 91 | + points = pd.DataFrame(points_data) |
| 92 | + start_circle = models.CircleTarget(**start_params) |
| 93 | + end_circle = models.CircleTarget(**end_params) |
| 94 | + |
| 95 | + ink_start, ink_end = trails_utils.valid_ink_trajectory( |
| 96 | + points, start_circle, end_circle |
| 97 | + ) |
| 98 | + |
| 99 | + assert ink_start == expected_start, f"Failed on {test_id}: ink_start" |
| 100 | + assert ink_end == expected_end, f"Failed on {test_id}: ink_end" |
| 101 | + |
| 102 | + |
12 | 103 | @pytest.fixture |
13 | 104 | def circles() -> Dict[str, Dict[str, models.CircleTarget]]: |
14 | 105 | """Return a minimal set of CircleTarget dictionaries for each trail.""" |
|
0 commit comments