test: tighten wall-check to consecutive run; add warp_endpoints no-mutation test
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,9 +128,17 @@ def test_no_sharp_turns_or_walls_near_endpoint() -> None:
|
|||||||
# Vertical wall: >=4 consecutive tail points within 2 px of
|
# Vertical wall: >=4 consecutive tail points within 2 px of
|
||||||
# the target x while spanning >10 px of y.
|
# the target x while spanning >10 px of y.
|
||||||
near_x = np.abs(tail[:, 0] - end[0]) <= 2.0
|
near_x = np.abs(tail[:, 0] - end[0]) <= 2.0
|
||||||
|
run_start = 0
|
||||||
run = 0
|
run = 0
|
||||||
for i, flag in enumerate(near_x[:-1]): # exclude final point
|
for j, flag in enumerate(near_x[:-1]): # exclude final point
|
||||||
run = run + 1 if flag else 0
|
if flag:
|
||||||
assert run < 4 or np.ptp(tail[near_x][:, 1]) <= 10.0, (
|
if run == 0:
|
||||||
f"{start}->{end} seed={seed}: vertical wall at target x"
|
run_start = j
|
||||||
)
|
run += 1
|
||||||
|
else:
|
||||||
|
run = 0
|
||||||
|
if run >= 4:
|
||||||
|
span = np.ptp(tail[run_start : j + 1, 1])
|
||||||
|
assert span <= 10.0, (
|
||||||
|
f"{start}->{end} seed={seed}: vertical wall at target x"
|
||||||
|
)
|
||||||
|
|||||||
@@ -199,3 +199,12 @@ def test_warp_endpoints_correction_local_to_each_end() -> None:
|
|||||||
f[0] = 0.08 # start residual only
|
f[0] = 0.08 # start residual only
|
||||||
fo, _ = warp_endpoints(f, l)
|
fo, _ = warp_endpoints(f, l)
|
||||||
assert np.abs(fo[24:] - f[24:]).max() < 0.02
|
assert np.abs(fo[24:] - f[24:]).max() < 0.02
|
||||||
|
|
||||||
|
|
||||||
|
def test_warp_endpoints_does_not_mutate_inputs() -> None:
|
||||||
|
f = np.linspace(0.05, 1.10, 32)
|
||||||
|
l = np.linspace(0.03, -0.07, 32)
|
||||||
|
f_orig, l_orig = f.copy(), l.copy()
|
||||||
|
warp_endpoints(f, l)
|
||||||
|
assert np.array_equal(f, f_orig)
|
||||||
|
assert np.array_equal(l, l_orig)
|
||||||
|
|||||||
Reference in New Issue
Block a user