Skip to content

Add property-based tests for fraud scorer boundary conditions (#220) - #259

Open
morelucks wants to merge 1 commit into
Afro-Pay:mainfrom
morelucks:feature/fraud-scorer-property-tests-issue-220
Open

Add property-based tests for fraud scorer boundary conditions (#220)#259
morelucks wants to merge 1 commit into
Afro-Pay:mainfrom
morelucks:feature/fraud-scorer-property-tests-issue-220

Conversation

@morelucks

Copy link
Copy Markdown

Description

This PR implements comprehensive property-based tests for the fraud scorer using hypothesis, addressing issue #220.

Changes

Added Dependencies

  • Added hypothesis==6.92.1 to requirements.txt for property-based testing

Property-Based Tests (4 new tests)

  1. test_property_score_always_in_valid_range: Verifies the invariant that 0.0 ≤ risk_score ≤ 1.0 for all possible TransactionInput combinations
  2. test_property_flagged_invariant: Verifies that flagged == (score >= 0.5) holds for all inputs
  3. test_property_zero_risk_gives_zero_score: Validates that transactions with no risk factors produce a score of 0.0
  4. test_property_max_risk_gives_capped_score: Validates that transactions with all risk factors produce a clamped score of 1.0

Boundary Tests (9 new tests)

  • LARGE_AMOUNT_THRESHOLD boundaries: Tests for amounts exactly at, just above, and just below the threshold
  • Round-number heuristic boundaries: Tests for zero amount and positive round numbers
  • Flag threshold boundaries: Tests for scores exactly at 0.5 and just below
  • HIGH_RISK_COUNTRIES validation: Verifies all countries in the set are properly recognized

Testing

All existing tests continue to pass. The new property-based tests use hypothesis strategies to generate diverse test cases covering:

  • Amounts from 0.0 to 1,000,000.0
  • All HIGH_RISK_COUNTRIES plus safe countries
  • All combinations of source and destination countries

Acceptance Criteria Met

  • ✅ hypothesis added to requirements.txt at pinned version (6.92.1)
  • ✅ At least 4 property-based tests using @given strategies
  • ✅ Invariant 0.0 ≤ score ≤ 1.0 verified for all TransactionInput combinations
  • ✅ Invariant flagged == (score >= 0.5) verified
  • ✅ All existing tests continue to pass
  • ✅ New tests run in CI (using standard pytest)

Closes #220

- Add hypothesis==6.92.1 to requirements.txt for property-based testing
- Implement 4 property-based tests using @given strategies:
  * test_property_score_always_in_valid_range: verifies 0.0 ≤ score ≤ 1.0
  * test_property_flagged_invariant: verifies flagged == (score >= 0.5)
  * test_property_zero_risk_gives_zero_score: verifies zero-risk input
  * test_property_max_risk_gives_capped_score: verifies max-risk clamping
- Add comprehensive boundary tests for all heuristic thresholds:
  * LARGE_AMOUNT_THRESHOLD boundary cases (at, above, below)
  * Round-number heuristic edge cases (zero, positive multiples)
  * Flag threshold boundary (exactly 0.5, just below)
  * HIGH_RISK_COUNTRIES validation for all countries
- All existing tests preserved and continue to pass
- Tests verify score clamping behavior when combined factors exceed 1.0

Closes Afro-Pay#220
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

@morelucks is attempting to deploy a commit to the milah's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Python analytics: property-based tests for fraud scorer boundary conditions and score clamping

1 participant