diff --git a/agent-notes/fix-integer-distance-issue-3.md b/agent-notes/fix-integer-distance-issue-3.md new file mode 100644 index 0000000..d7b16d5 --- /dev/null +++ b/agent-notes/fix-integer-distance-issue-3.md @@ -0,0 +1,21 @@ +# Assignment-selection issue 3 + +## Goal +Fix integer distance precision and open a draft PR without merging or changing Propstore pins/source. + +## State +Separate worktree/branch fix/integer-distance-issue-3, based on published d855496. Global instructions and repo source/tests/CI read; no local AGENTS.md/CLAUDE.md found. Focused dependency fixes and regression tests explicitly authorized by parent delegation. + +## Smallest change and decision +About four source lines: subtract int/int endpoints exactly, then convert the difference to the existing float distance type. Preserve float/numeric-coercion/categorical behavior for all other input pairs. About forty regression-test lines cover adjacent signed-64-bit integers and SIGMA's unique majority winner. No new metric policy or broader numeric redesign. + +## Next step +The new tests failed in all six cases before the change (four unit-distance cases and two SIGMA winner cases). After the four-line source fix, the same command passed all six in 0.49s: + +`uv run --no-project --offline --python C:/Users/Q/code/assignment-selection/.venv/Scripts/python.exe python -B -m pytest -p no:cacheprovider tests/test_integer_distances.py -q` + +PYTHONPATH selected this worktree's src; UV_CACHE_DIR selected its isolated cache. No dependencies installed. Full suite and typing will run in PR CI. + +Q separately approved the citation-only edit to issue #3. Replaced only the Propstore solve-owner line anchor 265 with 236, fetched the issue, and verified exact body equality with that one substitution. + +Published draft PR https://github.com/ctoth/assignment-selection/pull/4 at source commit 175d32533dc233cb25969154b9f8ca383a996294. Fetched the PR and verified its draft status and exact head. CI run 39339378017 passed all typing/test jobs on Python 3.11, 3.12, and 3.13. No merge or ready transition performed. This final note update records that outcome; verify the note-only final head before handoff. diff --git a/src/assignment_selection/solver.py b/src/assignment_selection/solver.py index 1357918..359b5a1 100644 --- a/src/assignment_selection/solver.py +++ b/src/assignment_selection/solver.py @@ -25,7 +25,10 @@ class EnumerationExceeded: def claim_distance(a: Any, b: Any) -> float: """Distance between two claim values.""" try: - distance = abs(float(a) - float(b)) + if isinstance(a, int) and isinstance(b, int): + distance = float(abs(a - b)) + else: + distance = abs(float(a) - float(b)) except (ValueError, TypeError): return 0.0 if a == b else 1.0 if not isfinite(distance): diff --git a/tests/test_integer_distances.py b/tests/test_integer_distances.py new file mode 100644 index 0000000..64d01e6 --- /dev/null +++ b/tests/test_integer_distances.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +import pytest + +from assignment_selection import Assignment, Problem, SourceAssignment, solve +from assignment_selection.solver import claim_distance + + +@pytest.mark.parametrize( + "left,right", + [ + (2**53, 2**53 + 1), + (2**63 - 2, 2**63 - 1), + (-(2**53), -(2**53) - 1), + (-(2**63), -(2**63) + 1), + ], +) +def test_adjacent_large_integers_have_unit_distance(left: int, right: int) -> None: + assert claim_distance(left, right) == 1.0 + assert claim_distance(right, left) == 1.0 + + +@pytest.mark.parametrize("majority", [2**53, -(2**63)]) +def test_sigma_selects_the_majority_of_adjacent_large_integers(majority: int) -> None: + minority = majority + 1 + sources = tuple( + SourceAssignment(str(index), Assignment({"x": value})) + for index, value in enumerate((majority, majority, minority)) + ) + + result = solve(Problem(("x",), sources)) + + assert tuple(winner.value_for("x") for winner in result.winners) == (majority,) + assert tuple( + (candidate.assignment.value_for("x"), candidate.score) + for candidate in result.scored_candidates + ) == ((majority, 1.0), (minority, 2.0))