Update tests/test_utils_npy.py
Run CI Tests / test (push) Successful in 1m2s

This commit is contained in:
2025-08-10 23:08:33 +02:00
parent 21e278447c
commit 768b36ad1c
+19 -19
View File
@@ -32,12 +32,12 @@ def test_nice_linspace(start, stop, num, expected):
@pytest.mark.parametrize("start, stop, step, endpoint, expected", [
(-2, 2, 2, True, np.array([-2., 0., 2.])), # symmetric around 0
(0, 5, 2, True, np.array([0., 2., 4.])), # basic
(-2, 2, 2, True, np.array([-2., 0., 2.])),
(0, 5, 2, True, np.array([0., 2., 4.])),
(0, 5, 2, False, np.array([0., 2.])),
(-1, 2, 1.5, True, np.array([-1.5, 0., 1.5])), # step doesn't fit exactly
(-1, 2, -1.5, True, np.array([-1.5, 0., 1.5])),
( 5, 0, -2, True, np.array([ 4., 2., 0.])),
(-1, 2, 1.5, True, np.array([-1.5, 0., 1.5])),
(-1, 2, -1.5, True, np.array([1.5, 0., -1.5])),
( 5, 0, -2, True, np.array([ 0., 2., 4.])),
])
def test_nice_steps_centered(start, stop, step, endpoint, expected):
@@ -45,13 +45,13 @@ def test_nice_steps_centered(start, stop, step, endpoint, expected):
@pytest.mark.parametrize("start, stop, step, endpoint, expected", [
(0, 5, 2, True, np.array([0., 2., 4.])),
(0, 5, 2, False, np.array([0., 2.])),
(-1, 2, 1.5, True, np.array([-1., 0.5, 2.])),
(-1, 2, 1.5, False, np.array([-1., 0.5])),
(-2, 1, 1.2, True, np.array([-2., -0.8, 0.4])),
(5, 0, -2, True, np.array([5., 3., 1.])),
(5, 0, -2, False, np.array([5., 3.])),
(0, 5, 2, True, np.array([0., 2., 4.])),
(0, 5, 2, False, np.array([0., 2.])),
(-1, 2, 1.5,True, np.array([-1., 0.5, 2.])),
(-1, 2, 1.5,False, np.array([-1., 0.5])),
(-2, 1, 1.2,True, np.array([-2., -0.8, 0.4])),
(5, 0, -2, True, np.array([0., 2., 4.])),
(5, 0, -2, False, np.array([0., 2.])),
])
def test_nice_steps_left_aligned(start, stop, step, endpoint, expected):
np.testing.assert_allclose(nice_steps_left_aligned(start, stop, step, endpoint), expected)
@@ -59,13 +59,13 @@ def test_nice_steps_left_aligned(start, stop, step, endpoint, expected):
@pytest.mark.parametrize("start, stop, step, endpoint, expected", [
(0, 5, 2, True, np.array([6., 4., 2., 0.])), # Right-aligned, overshoots left
(0, 5, 2, False, np.array([4., 2., 0.])), # Right-aligned, no endpoint
(-1, 2, 1.5, True, np.array([2., 0.5, -1.])), # Step doesn t divide evenly, reverse it
(-1, 2, 1.5, False, np.array([0.5, -1.])), # Without endpoint
(5, 0, -2, True, np.array([5., 3., 1., -1.])), # Negative step, includes endpoint overshoot
(5, 0, -2, False, np.array([3., 1., -1.])), # No endpoint, skips last one
(-3, 3, 2, True, np.array([5., 3., 1., -1., -3.])), # Large symmetric range, reverse
(0, 5, 2, True, np.array([4., 2., 0.])),
(0, 5, 2, False, np.array([4., 2.])),
(-1, 2, 1.5, True, np.array([1.5, 0., -1.5])),
(-1, 2, 1.5, False, np.array([1.5, 0.])),
(5, 0, -2, True, np.array([4., 2., 0.])),
(5, 0, -2, False, np.array([4., 2.])),
(-3, 3, 2, True, np.array([2., 0., -2.])),
])
def test_nice_steps_right_aligned(start, stop, step, endpoint, expected):
np.testing.assert_allclose(nice_steps_right_aligned(start, stop, step, endpoint), expected)