Scientific Computing Property-Based Test Harness Generator
Generate a property-based test script to verify numerical stability and mathematical invariants across floating-point boundaries.
Use this template when validating mathematical functions, scientific algorithms, or numerical libraries against precision limits and edge cases. It provides a production-grade test harness using property-based testing and ULP assertions.
Role: Principal Research Software Engineer specializing in Numerical Stability and Scientific Computing.
Context
- Target mathematical function: {{target_math_function}}
- Invariants and algebraic properties: {{mathematical_invariants}}
- Floating-point precision target: {{floating_point_precision}}
- Testing framework and language: {{framework_language}}
- Edge-case domains and boundaries: {{edge_case_domains}}
- Failure tolerance threshold: {{failure_tolerance_threshold}}
Task
Develop an end-to-end property-based testing script that rigorously verifies mathematical invariants, edge-case handling, and numerical precision stability across extreme dynamic ranges for scientific research synthesis algorithms.
Method
- Parse {{target_math_function}} against the formal mathematical invariants defined in {{mathematical_invariants}}.
- Define parameter sampling strategies in {{framework_language}} to cover {{edge_case_domains}}, including denormalized numbers, infinities, and NaN boundaries.
- Formulate metamorphic relations and invariant properties as parameterized test assertions.
- Implement numerical stability assertion checks enforcing {{floating_point_precision}} limits with ULP (Unit in the Last Place) comparison logic.
- Structure shrinkers and custom generators to isolate the minimal failing inputs when invariants break.
- Inject bounded perturbation tests to evaluate error propagation under {{failure_tolerance_threshold}}.
- Embed automated report logging capturing failure distributions, seed reproducibility, and floating-point condition numbers.
Constraints
- Generated code MUST compile and run directly within {{framework_language}} without placeholder implementations.
- Numerical comparisons MUST NOT rely on raw equality (
==) for floating-point calculations; explicit epsilon or ULP bounds are mandatory. - Include explicit setup fixtures, parameterized strategy generators, and tear-down harnesses.
- Inline documentation MUST explain the mathematical rationale behind every property assertion.
Output format
Provide a single executable test script organized into:
- Strategy and Custom Generator Definitions
- Precision Comparator Utility Functions
- Parametric Property Assertion Test Cases (minimum 4 distinct property tests)
- Execution Harness with Reproducible Seed Configuration
Self-review
- Ensure all properties in {{mathematical_invariants}} map to distinct test functions.
- Verify that {{floating_point_precision}} bounds use correct tolerance tolerances.
- Confirm no mock imports or pseudo-code exist in the script.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.