Skip to content

Expand Hypothesis and edge-case tests for elections, strategies, and methods#49

Draft
endolith wants to merge 3 commits into
masterfrom
cursor/hypothesis-election-scenarios-8718
Draft

Expand Hypothesis and edge-case tests for elections, strategies, and methods#49
endolith wants to merge 3 commits into
masterfrom
cursor/hypothesis-election-scenarios-8718

Conversation

@endolith
Copy link
Copy Markdown
Owner

@endolith endolith commented May 11, 2026

Summary

Adds property-based and explicit edge-case tests so tie-breaking, degenerate ballots, and spatial corner cases are exercised beyond line coverage alone.

Elections (test_elections.py)

  • Hypothesis checks shapes and value ranges for random_utilities, valid permutations for impartial_culture, and finite outputs for normal_electorate (with constraints so the correlation scaling stays real).
  • normed_dist_utilities: when every voter has distinct nearest/farthest distances, utilities stay in [0, 1] with correct row min/max; when two candidates share the same coordinates, documents current nan behavior from 0/0 normalization.

Strategies (test_strategies.py)

  • honest_rankings: ballots remain permutations; constant utilities tie-break toward higher candidate ids first (NumPy argsort behavior).
  • approval_optimal: all-equal utilities yield no approvals; every approval implies strictly above the row mean.
  • vote_for_k: with strictly ordered utilities per row, each ballot has exactly k approvals.
  • honest_normed_scores: explicit all-equal case; property test perturbs rows slightly so min/max normalization is well-defined without heavy assume filtering.

Condorcet / pairwise (test_condorcet.py)

  • Hypothesis test_ranked_election_to_matrix (shape, diagonal, min/max bounds) unchanged in intent alongside new tests.
  • Pairwise matrix: for i < j, M[i,j] + M[j,i] == n_voters.
  • Any Condorcet winner strictly beats every other candidate pairwise.

Methods (test_methods.py)

  • Black’s method matches the Condorcet winner when one exists, otherwise the Borda result (default tiebreaker behavior).
  • SNTV with n=1 and tiebreaker='order' agrees with FPTP with the same tiebreaker (including None when both are tied).
  • Hypothesis: ranked methods return a candidate index or None as appropriate; utility_winner(..., 'order') matches argmax of column sums.
  • Explicit ties: utility_winner with two-way total tie; combined_approval with symmetric +1/-1 ballots.
Open in Web Open in Cursor 

…, methods

- Elections: property tests for random_utilities, impartial_culture, and
  normal_electorate; spatial utilities bounded when distances spread; document
  NaN output when two candidates coincide for a voter.
- Strategies: honest_rankings permutation and tie-order invariants; approval
  threshold strictness; vote_for_k approval counts with strict utilities;
  honest_normed_scores degenerate and stabilized property cases.
- Condorcet: pairwise matrix rows partition voters; Condorcet winner beats all
  others pairwise.
- Methods: Black agrees with Condorcet or Borda branch; SNTV n=1 vs FPTP with
  order tiebreak; ranked methods return valid IDs; utility_winner vs column
  sums; explicit ties for utility_winner and combined approval.

Co-authored-by: endolith <endolith@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.31%. Comparing base (8a7213f) to head (ac8acc3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #49   +/-   ##
=======================================
  Coverage   96.31%   96.31%           
=======================================
  Files          19       19           
  Lines         489      489           
=======================================
  Hits          471      471           
  Misses         18       18           
Flag Coverage Δ
no-numba 95.50% <ø> (ø)
numba 89.16% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

cursoragent and others added 2 commits May 11, 2026 21:12
…istake)

Co-authored-by: endolith <endolith@gmail.com>
- Elections: extend random_utilities, impartial_culture, normal_electorate,
  and normed_dist_utilities in place; remove duplicate property tests.
- Strategies: merge uniform utilities, indifferent scores, strict approval
  threshold, and strict vote_for_k counts into existing tests.
- Methods: restore test_methods to shared tiebreaker/degeneracy tests only;
  move Black composition and SNTV-vs-FPTP checks to test_black and test_sntv.
- Approval: add combined-approval balanced-ballot tie next to CAV examples.

Condorcet pairwise matrix properties unchanged.

Co-authored-by: endolith <endolith@gmail.com>
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.

2 participants