-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_generate_reference_spiral.py
More file actions
37 lines (31 loc) · 1.29 KB
/
test_generate_reference_spiral.py
File metadata and controls
37 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Test cases for generate_reference_spiral.py functions."""
import numpy as np
from graphomotor.core import config
from graphomotor.utils import generate_reference_spiral
def test_generate_reference_spiral() -> None:
"""Test the generation of a reference spiral."""
spiral_config = config.SpiralConfig()
expected_mean_arc_length = generate_reference_spiral._calculate_arc_length_between(
spiral_config.start_angle, spiral_config.end_angle, spiral_config
) / (spiral_config.num_points - 1)
spiral = generate_reference_spiral.generate_reference_spiral(spiral_config)
arc_lengths = np.linalg.norm(spiral[1:] - spiral[:-1], axis=1)
mean_arc_length = np.mean(arc_lengths)
assert isinstance(spiral, np.ndarray)
assert spiral.shape == (spiral_config.num_points, 2)
assert np.array_equal(
spiral[0],
[spiral_config.center_x, spiral_config.center_y],
)
assert np.allclose(
spiral[-1],
[
spiral_config.center_x
+ spiral_config.growth_rate * spiral_config.end_angle,
spiral_config.center_y,
],
atol=0,
rtol=1e-8,
)
assert np.allclose(arc_lengths, mean_arc_length, atol=0, rtol=1e-3)
assert np.isclose(mean_arc_length, expected_mean_arc_length, atol=0, rtol=1e-6)