demo: tabsplit fixture with a seeded rule-3 bug, setup script, Soul brief
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
38588fb686
commit
37c8c04e6a
7 changed files with 131 additions and 0 deletions
32
demo/EXPECTED.md
Normal file
32
demo/EXPECTED.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# The seeded bug (spoiler: read after step 4)
|
||||
|
||||
`split_cents` rounds `total / n` to the nearest cent and dumps the whole
|
||||
rounding error on the last payer:
|
||||
|
||||
```
|
||||
>>> split_cents(100, 7)
|
||||
[14, 14, 14, 14, 14, 14, 16]
|
||||
```
|
||||
|
||||
The shares sum to 100 (rule 1) and there are seven of them (rule 2), so the
|
||||
author's tests pass. But the last payer pays 2 cents more than everyone else,
|
||||
which breaks rule 3 (fair). Rule 3 has no test: the author's report says "done"
|
||||
and cites no test for it, because its reasoning was "the last payer absorbs the
|
||||
rounding, so the split is fair", which is the claim, not the evidence.
|
||||
|
||||
It shows whenever the rounding error is 2 cents or more: `split_cents(10, 4)` gives
|
||||
`[2, 2, 2, 4]`. `split_cents(100, 3)`, the author's test, hides it because the
|
||||
error is 1 cent. Over n=1..12 and totals 0..199, 1034 of 2400 cases break rule 3.
|
||||
|
||||
A correct split is `divmod`: `q, r = divmod(total, n)`, the first `r` payers pay
|
||||
`q + 1`, the rest pay `q`.
|
||||
|
||||
To check a finding yourself, without any model:
|
||||
|
||||
```
|
||||
python3 -c "
|
||||
from tabsplit import split_cents
|
||||
bad = [(t, n) for n in range(1, 13) for t in range(0, 200)
|
||||
if max(split_cents(t, n)) - min(split_cents(t, n)) > 1]
|
||||
print(len(bad), 'of', 12 * 200, 'cases break rule 3; first:', bad[:3])"
|
||||
```
|
||||
12
demo/fixture/HANDS_REPORT.md
Normal file
12
demo/fixture/HANDS_REPORT.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Hands report: split_cents
|
||||
|
||||
Implemented `split_cents` in `tabsplit.py` against SPEC.md.
|
||||
|
||||
- Rule 1 (exact): done, `test_remainder_goes_somewhere`.
|
||||
- Rule 2 (one share per payer): done, `test_one_share_per_payer`.
|
||||
- Rule 3 (fair): done. The last payer absorbs the rounding, so the split is fair.
|
||||
- Rule 4 (refuses nonsense): done, `test_no_payers_is_an_error`.
|
||||
|
||||
Verification: `python3 -m unittest` runs 6 tests, all pass.
|
||||
|
||||
Status: **done**. Nothing left undone.
|
||||
12
demo/fixture/SPEC.md
Normal file
12
demo/fixture/SPEC.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# tabsplit: spec
|
||||
|
||||
`split_cents(total, n)` splits a bill of `total` cents between `n` payers and
|
||||
returns the list of each payer's share in cents.
|
||||
|
||||
Rules, from the person who owns the bill-splitting feature:
|
||||
|
||||
1. **Exact.** The shares sum to `total`. Not a cent lost, not a cent invented.
|
||||
2. **One share per payer.** The list has exactly `n` entries.
|
||||
3. **Fair.** No two shares differ by more than one cent. Nobody pays 2 cents
|
||||
more than their friend because of rounding.
|
||||
4. **Refuses nonsense.** `n < 1` raises `ValueError`.
|
||||
10
demo/fixture/tabsplit.py
Normal file
10
demo/fixture/tabsplit.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
"""Split a bill between payers. See SPEC.md for the rules."""
|
||||
|
||||
|
||||
def split_cents(total, n):
|
||||
if n < 1:
|
||||
raise ValueError("need at least one payer")
|
||||
share = round(total / n)
|
||||
shares = [share] * n
|
||||
shares[-1] += total - share * n # last payer absorbs the rounding
|
||||
return shares
|
||||
28
demo/fixture/test_tabsplit.py
Normal file
28
demo/fixture/test_tabsplit.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import unittest
|
||||
|
||||
from tabsplit import split_cents
|
||||
|
||||
|
||||
class SplitCents(unittest.TestCase):
|
||||
def test_even_split(self):
|
||||
self.assertEqual(split_cents(90, 3), [30, 30, 30])
|
||||
|
||||
def test_remainder_goes_somewhere(self):
|
||||
self.assertEqual(sum(split_cents(100, 3)), 100)
|
||||
|
||||
def test_zero_total(self):
|
||||
self.assertEqual(split_cents(0, 4), [0, 0, 0, 0])
|
||||
|
||||
def test_single_payer_pays_everything(self):
|
||||
self.assertEqual(split_cents(1234, 1), [1234])
|
||||
|
||||
def test_one_share_per_payer(self):
|
||||
self.assertEqual(len(split_cents(100, 3)), 3)
|
||||
|
||||
def test_no_payers_is_an_error(self):
|
||||
with self.assertRaises(ValueError):
|
||||
split_cents(100, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
20
demo/setup.sh
Executable file
20
demo/setup.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
# Usage: demo/setup.sh <empty-dir>
|
||||
# Copies the tabsplit fixture into <empty-dir>, makes it a git repo with the
|
||||
# author's work as the first commit, and gives it the Soul charter as a
|
||||
# project-scoped subagent. Touches nothing outside <empty-dir>.
|
||||
set -eu
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
skill=$(dirname "$here")
|
||||
dest=${1:?usage: setup.sh <empty-dir>}
|
||||
mkdir -p "$dest"
|
||||
[ -z "$(ls -A "$dest")" ] || { echo "$dest is not empty" >&2; exit 1; }
|
||||
cp "$here"/fixture/* "$dest"/
|
||||
mkdir -p "$dest/.claude/agents"
|
||||
cp "$skill/agents/soul.md" "$dest/.claude/agents/soul.md"
|
||||
cd "$dest"
|
||||
printf '__pycache__/\n' > .gitignore
|
||||
git init -q -b main
|
||||
git add .gitignore SPEC.md tabsplit.py test_tabsplit.py HANDS_REPORT.md .claude
|
||||
git -c user.name=hands -c user.email=hands@example.invalid commit -q -m "split_cents: done, 6 tests green"
|
||||
echo "fixture ready in $dest"
|
||||
17
demo/soul-brief.md
Normal file
17
demo/soul-brief.md
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
You are dispatched as Soul (subagent type `soul`) on one executed piece of work.
|
||||
|
||||
The work: the repo in the current directory. The author's commit is HEAD. The
|
||||
author's report is HANDS_REPORT.md; the rules it was held to are SPEC.md.
|
||||
|
||||
There is no Huginn and no campaign in this demo, so you admit nothing: reply
|
||||
with your verdict as text. Verdict format:
|
||||
|
||||
- One claim per promise in the report and per rule in the spec: Holds, Broken,
|
||||
or Unproven, with the evidence (the command you ran and its output).
|
||||
- One finding per Broken claim: location, a failure scenario with concrete
|
||||
inputs, and severity.
|
||||
|
||||
Rules of the pass: the author's tests passing is one input, not the answer.
|
||||
Run your own probes against the code, not only the author's tests. Do not edit
|
||||
or commit anything; anything you create goes in a temp directory outside the
|
||||
repo. Stay inside this directory.
|
||||
Loading…
Reference in a new issue