Testing¶
Test suite and validation.
Running Tests¶
Run all tests:
Run specific test file:
Run with coverage:
Test Coverage¶
The test suite includes:
Sampling Combinations¶
All 7 combinations of (f, g, h):
- f only
- g only
- h only
- f + g
- f + h
- g + h
- f + g + h
def test_all_combinations():
"""Test all valid sampling combinations."""
# Tests each combination with assertions
Mathematical Relationships¶
Integral Relationship¶
Verify g matches numerical integration of f:
def test_integral_relationship():
"""g should match cumulative integral of f."""
# Compare analytical g with numerical integration
Derivative Relationship¶
Verify h correlates with numerical gradient of f:
def test_derivative_relationship():
"""h should correlate with numerical gradient of f."""
# Compare analytical h with finite differences
Cross-Validation¶
Derivative of integral recovers f:
Posterior Interpolation¶
Mean passes through training points:
def test_posterior_interpolation():
"""Posterior mean should interpolate training data."""
# Check f_mean at x_train matches y_train
Numerical Stability¶
Different Grid Sizes¶
Length Scale Range¶
Derivative Stability¶
Reproducibility¶
Same seed produces same results:
Input Validation¶
Invalid Specifications¶
Mismatched Observations¶
Invalid Parameters¶
Test Organization¶
tests/
├── test_gp4c.py # Core sampling tests
├── test_flexible_sampler.py # Flexible API tests
└── test_posterior.py # Posterior sampling tests
Custom Test¶
Write your own validation:
import numpy as np
from gp4c import sample_prior, SamplingSpec
def test_custom():
"""Custom test case."""
x = np.linspace(0, 5, 100)
spec = SamplingSpec(x_f=x, x_h=x)
result = sample_prior(spec, ell=0.5, n_samples=10)
# Verify shapes
assert result.f.shape == (10, 100)
assert result.h.shape == (10, 100)
assert result.g is None
# Verify finite values
assert np.all(np.isfinite(result.f))
assert np.all(np.isfinite(result.h))
Continuous Integration¶
Tests run automatically on:
- Pull requests
- Commits to main branch
- Scheduled daily builds
Next Steps¶
- Troubleshooting - Common issues
- Contributing - Development workflow