Skip to content

Commit 11536a6

Browse files
0xC000005claude
andcommitted
v0.17: close coverage gaps — Slider partial classification + validation tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 04a50ff commit 11536a6

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

tests/test_calculus_completion.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,73 @@ def f(x, _):
450450
result = slider.integrate(dims=[0])
451451
assert result.get_descriptor() == "source"
452452

453+
def test_partial_with_multi_dim_group(self):
454+
"""Multi-dim slide group, partially integrated → exercises the 'partial' classification.
455+
456+
partition=[[0, 1]] is one 2D slide; integrating dim 0 leaves a 1D slide over dim 1.
457+
"""
458+
def f(x, _):
459+
return math.sin(x[0]) * math.cos(x[1])
460+
461+
slider = ChebyshevSlider(
462+
f, 2, [[-1, 1], [-1, 1]], [10, 10],
463+
partition=[[0, 1]], pivot_point=[0.0, 0.0],
464+
)
465+
slider.build(verbose=False)
466+
result = slider.integrate(dims=[0])
467+
assert isinstance(result, ChebyshevSlider)
468+
assert result.num_dimensions == 1
469+
470+
# ∫_{-1}^{1} sin(x) cos(y) dx = cos(y) * [-cos(x)]_{-1}^{1} = 0
471+
# So the integrated function should be ≈ 0 for all y
472+
assert result.eval([0.5], [0]) == pytest.approx(0.0, abs=1e-6)
473+
474+
def test_partial_with_3d_group_partial_integration(self):
475+
"""3D slide group with one dim integrated → 2D reduced slide.
476+
477+
partition=[[0, 1, 2]] is a 3D slide; integrate=[1] reduces it to 2D over (0, 2).
478+
"""
479+
def f(x, _):
480+
return math.sin(x[0]) + math.cos(x[1]) + x[2] ** 2
481+
482+
slider = ChebyshevSlider(
483+
f, 3, [[-1, 1]] * 3, [8, 8, 8],
484+
partition=[[0, 1, 2]], pivot_point=[0.0, 0.0, 0.0],
485+
)
486+
slider.build(verbose=False)
487+
result = slider.integrate(dims=[1])
488+
assert isinstance(result, ChebyshevSlider)
489+
assert result.num_dimensions == 2
490+
491+
# ∫_{-1}^{1} (sin(x) + cos(y) + z^2) dy = 2*sin(x) + 2*sin(1) + 2*z^2
492+
# At x=0, z=0: 0 + 2*sin(1) + 0 ≈ 1.683
493+
expected = 2.0 * math.sin(1.0)
494+
assert result.eval([0.0, 0.0], [0, 0]) == pytest.approx(expected, abs=1e-3)
495+
496+
def test_partial_mixed_classifications(self):
497+
"""Two slides where one undergoes 'partial' and another 'none'.
498+
499+
partition=[[0, 1], [2]]; integrate=[0] →
500+
- slide 0 (group [0,1]): "partial" — reduces to 1D over dim 1
501+
- slide 1 (group [2]): "none" — passes through unchanged
502+
"""
503+
def f(x, _):
504+
return math.sin(x[0]) * math.cos(x[1]) + x[2]
505+
506+
slider = ChebyshevSlider(
507+
f, 3, [[-1, 1]] * 3, [8, 8, 8],
508+
partition=[[0, 1], [2]], pivot_point=[0.0, 0.0, 0.0],
509+
)
510+
slider.build(verbose=False)
511+
result = slider.integrate(dims=[0])
512+
assert isinstance(result, ChebyshevSlider)
513+
assert result.num_dimensions == 2
514+
515+
# ∫_{-1}^{1} (sin(x) cos(y) + z) dx = 0 + 2z = 2z
516+
# So result(y, z) ≈ 2z for any y
517+
assert result.eval([0.0, 0.5], [0, 0]) == pytest.approx(1.0, abs=1e-6)
518+
assert result.eval([0.5, 0.5], [0, 0]) == pytest.approx(1.0, abs=1e-6)
519+
453520

454521
# ============================================================================
455522
# T8: Cross-class consistency
@@ -522,3 +589,53 @@ def f(x, _):
522589
# ∫_{-1}^{1} (x*y + x) dx = 0 + 0 = 0 → result is 0 for all y
523590
result_tt = tt.integrate(dims=[0])
524591
assert result_tt.eval([0.5]) == pytest.approx(0.0, abs=1e-10)
592+
593+
594+
# ============================================================================
595+
# T9: Slider integrate() validation
596+
# ============================================================================
597+
598+
class TestSliderIntegrateValidation:
599+
def test_integrate_on_unbuilt_slider_raises(self):
600+
def f(x, _):
601+
return x[0]
602+
slider = ChebyshevSlider(
603+
f, 1, [[-1, 1]], [4],
604+
partition=[[0]], pivot_point=[0.0],
605+
)
606+
# Don't build
607+
with pytest.raises(RuntimeError, match="not.*built|build"):
608+
slider.integrate()
609+
610+
def test_integrate_dims_oob(self):
611+
def f(x, _):
612+
return x[0]
613+
slider = ChebyshevSlider(
614+
f, 1, [[-1, 1]], [4],
615+
partition=[[0]], pivot_point=[0.0],
616+
)
617+
slider.build(verbose=False)
618+
with pytest.raises(ValueError, match="out-of-range|negative"):
619+
slider.integrate(dims=[5])
620+
621+
def test_integrate_negative_dim(self):
622+
def f(x, _):
623+
return x[0]
624+
slider = ChebyshevSlider(
625+
f, 1, [[-1, 1]], [4],
626+
partition=[[0]], pivot_point=[0.0],
627+
)
628+
slider.build(verbose=False)
629+
with pytest.raises(ValueError):
630+
slider.integrate(dims=[-1])
631+
632+
def test_integrate_bounds_outside_domain(self):
633+
def f(x, _):
634+
return x[0]
635+
slider = ChebyshevSlider(
636+
f, 1, [[-1, 1]], [4],
637+
partition=[[0]], pivot_point=[0.0],
638+
)
639+
slider.build(verbose=False)
640+
with pytest.raises(ValueError):
641+
slider.integrate(dims=[0], bounds=[(-2.0, 2.0)])

0 commit comments

Comments
 (0)