Record planting day and show harvest dates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
07057e6c3d
commit
83a9cb6dcc
11 changed files with 282 additions and 44 deletions
|
|
@ -46,6 +46,34 @@ class StoreTests(unittest.TestCase):
|
|||
self.assertEqual(len(snapshot["checks"]), 20)
|
||||
self.assertTrue(all(snapshot["checks"].values()))
|
||||
|
||||
def test_planting_round_trip(self):
|
||||
spring_three = {"year": 1, "season": "spring", "day": 3}
|
||||
result = self.store.set_planting("crop-parsnip", spring_three, "fred")
|
||||
self.assertEqual(result["revision"], 1)
|
||||
self.assertEqual(self.store.snapshot()["plantings"], {"crop-parsnip": spring_three})
|
||||
|
||||
self.store.set_planting("crop-parsnip", None, "fred")
|
||||
snapshot = self.store.snapshot()
|
||||
self.assertEqual(snapshot["plantings"], {})
|
||||
self.assertEqual(snapshot["revision"], 2)
|
||||
|
||||
def test_undated_planted_checks_migrate_to_plantings(self):
|
||||
self.store.set_check("planted-crop-parsnip", True, "fred")
|
||||
self.store.set_check("planted-crop-potato", False, "fred")
|
||||
self.store.initialize()
|
||||
snapshot = self.store.snapshot()
|
||||
self.assertEqual(snapshot["checks"], {})
|
||||
self.assertEqual(
|
||||
snapshot["plantings"], {"crop-parsnip": {"year": None, "season": None, "day": None}}
|
||||
)
|
||||
self.assertEqual(snapshot["revision"], 3)
|
||||
|
||||
def test_game_date_validation(self):
|
||||
self.assertTrue(app.valid_game_date({"year": 2, "season": "winter", "day": 28}))
|
||||
self.assertFalse(app.valid_game_date({"year": 1, "season": "spring", "day": 29}))
|
||||
self.assertFalse(app.valid_game_date({"year": True, "season": "spring", "day": 1}))
|
||||
self.assertFalse(app.valid_game_date({"year": 1, "season": "monsoon", "day": 1}))
|
||||
|
||||
|
||||
class StaticInteractionTests(unittest.TestCase):
|
||||
def test_native_checkboxes_cover_each_tickable_row(self):
|
||||
|
|
|
|||
|
|
@ -12,3 +12,13 @@ assert.equal(calendar.birthdayOn(birthdays, "spring", 7, 2), "Lewis");
|
|||
assert.equal(calendar.birthdayOn(birthdays, "spring", 8, 1), null);
|
||||
|
||||
console.log("calendar tests passed");
|
||||
|
||||
// Parsnip (4 days) planted on Spring 1 is ready on Spring 5.
|
||||
assert.deepEqual(calendar.harvestDate({ year: 1, season: "spring", day: 1 }, 4), { year: 1, season: "spring", day: 5 });
|
||||
// Corn planted late in Summer finishes in Fall; Winter rolls over into the next year.
|
||||
assert.deepEqual(calendar.harvestDate({ year: 1, season: "summer", day: 20 }, 14), { year: 1, season: "fall", day: 6 });
|
||||
assert.deepEqual(calendar.harvestDate({ year: 1, season: "winter", day: 28 }, 1), { year: 2, season: "spring", day: 1 });
|
||||
assert.equal(calendar.daysBetween({ year: 1, season: "spring", day: 3 }, { year: 1, season: "spring", day: 5 }), 2);
|
||||
assert.equal(calendar.daysBetween({ year: 1, season: "fall", day: 2 }, { year: 1, season: "summer", day: 28 }), -2);
|
||||
|
||||
console.log("harvest date tests passed");
|
||||
|
|
|
|||
|
|
@ -28,3 +28,18 @@ assert.equal(confirmed.checks["crop-parsnip"], true);
|
|||
assert.equal(confirmed.revision, 7);
|
||||
|
||||
console.log("sync race tests passed");
|
||||
|
||||
// Plantings follow the same rules: an in-flight local planting (or removal) wins.
|
||||
const springFive = { year: 1, season: "spring", day: 5 };
|
||||
const plantMerge = sync.mergeSnapshot({}, new Set(), 7, {
|
||||
revision: 8,
|
||||
checks: {},
|
||||
plantings: { "crop-parsnip": { year: 1, season: "spring", day: 1 }, "crop-potato": springFive }
|
||||
}, { "crop-parsnip": springFive }, new Set(["crop-parsnip", "crop-potato"]));
|
||||
assert.deepEqual(plantMerge.plantings, { "crop-parsnip": springFive });
|
||||
|
||||
const unplanted = sync.confirmPlanting(plantMerge.plantings, 8, { itemId: "crop-parsnip", planted: null, revision: 9 });
|
||||
assert.deepEqual(unplanted.plantings, {});
|
||||
assert.equal(unplanted.revision, 9);
|
||||
|
||||
console.log("planting sync tests passed");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue