Personal ledger on the character sheet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-28 13:20:26 +00:00
parent ece0f101aa
commit 4b0724e6e5
4 changed files with 159 additions and 11 deletions

View file

@ -3378,3 +3378,32 @@ class TownsfolkTest(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
class LedgerTest(unittest.TestCase):
def test_a_stretch_of_work_is_one_line(self):
world = world_with(("fred", "commoner"))
p = world["players"]["fred"]
game.start_action(world, p, "mine_stone", T0)
game.process_player(world, p, T0 + 100, random.Random(1))
game.process_player(world, p, T0 + 200, random.Random(1))
[line] = p["ledger"]
self.assertEqual((line["act"], line["n"], line["items"], line["xp"]), ("mine_stone", 10, {"stone": 10}, 50))
self.assertEqual(line["at"] - line["start"], 200)
# Stopped and started again later: a new stretch.
game.start_action(world, p, "mine_stone", T0 + 1000)
game.process_player(world, p, T0 + 1020, random.Random(1))
self.assertEqual([l["n"] for l in p["ledger"]], [10, 1])
def test_gifts_and_sales_add_up_within_the_hour(self):
world = world_with(("fred", "commoner"), ("ann", "commoner"))
fred, ann = world["players"]["fred"], world["players"]["ann"]
fred["bank"] = {"stone": 30}
game.give(world, fred, ann, "stone", 5, T0)
game.give(world, fred, ann, "stone", 5, T0 + 60)
game.sell(world, fred, "stone", 10, T0 + 120)
self.assertEqual([(l["verb"], l["qty"]) for l in fred["ledger"]], [("Gave", 10), ("Sold", 10)])
self.assertEqual(fred["ledger"][1]["gold"], 10 * game.ITEMS["stone"]["value"])
self.assertEqual((ann["ledger"][0]["verb"], ann["ledger"][0]["who"]), ("Received", "fred"))
game.sell(world, fred, "stone", 1, T0 + 2 * game.HOUR)
self.assertEqual([l["verb"] for l in fred["ledger"]], ["Gave", "Sold", "Sold"])