Skip to content

test: rate clamp ordering proptest - #1

Open
iexwr wants to merge 1 commit into
mainfrom
task/rate-clamp-order
Open

test: rate clamp ordering proptest#1
iexwr wants to merge 1 commit into
mainfrom
task/rate-clamp-order

Conversation

@iexwr

@iexwr iexwr commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds property-based tests verifying that per-borrower rate clamping is order-independent across operations.

Tests Added

Test Type Cases What it verifies
prop_clamp_modularity Proptest 1024 max(min(r,c),f) == min(max(r,f),c) for all valid f ≤ c
prop_clamp_contract_integration Proptest 256 Contract matches mathematical clamp
prop_clamp_floor_ceiling_set_order Proptest 128 Setting floor/ceiling in either order yields same final rate
clamp_zero_bounds Deterministic 4 Floor = ceiling = 0 clamps everything to 0
clamp_global_cap_boundary Deterministic 2 10_000 bps hard cap is respected
clamp_floor_exceeds_ceiling Deterministic 4 Degenerate case: ceiling wins when floor > ceiling
clamp_no_bounds Deterministic 4 Rate passes through unchanged
clamp_floor_only Deterministic 2 Floor raises sub-floor rates
clamp_ceiling_only Deterministic 2 Ceiling caps above-ceiling rates
clamp_modularity_deterministic Deterministic 12 Identity for 12 representative triples
clamp_modularity_boundary_sweep Deterministic 9 Identity at boundary values

Verification

  • cargo test -p creditra-credit --test proptest_rate_clamp - all 11 tests pass
  • cargo check -p creditra-credit - no new warnings
  • cargo clippy - no new warnings

Also fixes a pre-existing compilation error in query.rs (u128::from(i128) is invalid; changed to as u128).

Closes Creditra#585

Add property-based tests to verify that per-borrower rate clamping is
order-independent across operations.

Includes:
- prop_clamp_modularity: verifies max(min(r,c),f) == min(max(r,f),c)
  for 1024 random (rate, floor, ceiling) triples
- prop_clamp_contract_integration: end-to-end contract test (256 cases)
  matching update_risk_parameters output to the mathematical clamp
- prop_clamp_floor_ceiling_set_order: verifies setting floor/ceiling
  in either order yields the same final rate (128 cases)
- 8 deterministic edge-case tests covering zero bounds, global cap,
  degenerate ranges, floor-only, ceiling-only, and no-bounds paths

Also fixes a pre-existing compilation error in query.rs where u128::from(i128)
was used, which is not a valid conversion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add rate-clamp ordering proptest

1 participant