| import numpy as np |
|
|
| from symbolic_recursion.coherence import benchmark_operators, coherence_retention |
| from symbolic_recursion.kernel import MetaOperator, SymbolicRecursionKernel, composite_q, run_worked_examples |
|
|
|
|
| def test_composite_q(): |
| q = composite_q(1.0, 2.0, 3.0, 4.0) |
| assert q == 10.0 |
|
|
|
|
| def test_kernel_integration_bounded(): |
| t = np.linspace(0, 5, 100) |
| f = np.sin(t) + np.cos(t) |
| k = SymbolicRecursionKernel(a=1.0) |
| dx = k.integrate_series(f, dt=t[1] - t[0]) |
| assert len(dx) == len(f) |
| assert np.all(np.isfinite(dx)) |
|
|
|
|
| def test_meta_operator(): |
| m = MetaOperator(b=0.091) |
| out = m.apply_series(np.ones(50) * 0.1, dt=0.01) |
| assert out[-1] > 0 |
|
|
|
|
| def test_worked_examples_all_modes(): |
| results = run_worked_examples(n_points=100) |
| assert set(results.keys()) == {"oscillatory", "decaying", "accelerating", "fractal_impulse", "hybrid_echo"} |
| for r in results.values(): |
| assert "bounded" in r |
|
|
|
|
| def test_coherence_retention_identity(): |
| x = np.sin(np.linspace(0, 10, 200)) |
| score = coherence_retention(x, x) |
| assert score > 0.9 |
|
|
|
|
| def test_benchmark_returns_20_operators(): |
| rows = benchmark_operators(n_points=200) |
| assert len(rows) == 20 |
| assert all("gain_pct" in r for r in rows) |