"""Step 3f: the fort's rooms (rooms.doors, rooms.LAYOUT), pure: which rooms, which plots, what each holds, where.""" import unittest from p02 import campaign as K from p02 import data as D from p02 import rooms as R def kinds(c): return [(d["key"], d["kind"]) for d in R.doors(c)] class TheDoors(unittest.TestCase): def setUp(self): self.c = K.new_campaign(4) self.c.supplies = 2000 def test_a_new_fort(self): self.assertEqual(kinds(self.c), [("command", "room"), ("barracks", "room"), ("armory", "room"), ("engineering", "room"), ("garage", "room"), ("research", "room"), ("rec", "room"), ("plot:0", "plot"), ("plot:1", "plot"), ("plot:2", "plot"), ("plot:3", "rubble")]) self.assertEqual(D.PLOTS, 3) # what the line above assumes self.assertEqual(D.MAX_PLOTS, 4) def test_every_room_but_rubble_goes_in_and_has_a_control_but_command_and_research(self): for d in R.doors(self.c): self.assertEqual(d["enter"], d["kind"] != "rubble", d["key"]) if d["kind"] != "rubble" and d["key"] not in ("command", "research"): self.assertIn(d["control"], R.BUTTON, d["key"]) ctl = {d["key"]: d["control"] for d in R.doors(self.c)} self.assertEqual((ctl["command"], ctl["research"], ctl["rec"]), (None, None, "memorial")) def test_the_barracks_and_armory_hold_the_roster_the_garage_the_convoy(self): ctl = {d["key"]: d["control"] for d in R.doors(self.c)} self.assertEqual((ctl["barracks"], ctl["armory"], ctl["garage"], ctl["engineering"]), ("roster", "roster", "convoy", "facilities")) def test_the_layout_every_room_in_its_own_place(self): cells = set() for d in R.doors(self.c): level, col, span = R.LAYOUT[d["key"]] self.assertTrue(0 <= level < R.LEVELS and 0 <= col and col + span <= R.COLUMNS, d["key"]) here = {(level, c) for c in range(col, col + span)} self.assertFalse(here & cells, d["key"]) # no two rooms in one place self.assertNotIn(R.LIFT, {c for _, c in here}, d["key"]) # nor in the lift shaft cells |= here self.assertEqual(set(R.LAYOUT), {d["key"] for d in R.doors(self.c)}) self.assertEqual(R.LAYOUT["command"][:2], (0, 0)) # the command room on top def test_the_tabs_are_dillons_rooms_and_the_whole_base(self): self.assertEqual([k for k, _ in R.TABS], ["command", "barracks", "armory", "engineering", "garage", "research", "rec", "base"]) fixed = {k for k, *_ in R.FIXED} self.assertEqual({k for k, _ in R.TABS} - {"base"}, fixed) def test_a_build_in_hand_takes_the_next_plot(self): K.build(self.c, "radio room") d = R.doors(self.c)[7] self.assertEqual((d["kind"], d["facility"], d["name"]), ("building", "radio room", "Radio room (building)")) self.assertIn(f"{D.FACILITIES['radio room']['levels'][0]['days']} days left", d["about"]) self.assertEqual([x["kind"] for x in R.doors(self.c)[8:]], ["plot", "plot", "rubble"]) def test_built_facilities_have_their_doors_with_level_and_what_they_do(self): self.c.facilities = {"radio room": 1, "infirmary": 1} ds = R.doors(self.c) self.assertEqual([(d["kind"], d.get("facility"), d["name"]) for d in ds[7:9]], [("facility", "infirmary", "Infirmary 1"), ("facility", "radio room", "Radio room 1")]) self.assertIn("wounds heal in 75% of the time", ds[7]["about"]) self.assertIn("+1 intel a week", ds[8]["about"]) def test_an_upgrade_in_hand_says_so_on_the_door(self): self.c.facilities = {"drill yard": 1} self.c.project = {"what": "drill yard", "level": 2, "done": self.c.day + 4} d = R.doors(self.c)[7] self.assertEqual(d["kind"], "facility") self.assertIn("building level 2: 4 days left", d["about"]) self.assertTrue(d["about"].startswith("Drill yard, level 1: +25% XP from every mission.")) self.assertEqual([x["kind"] for x in R.doors(self.c)[8:]], ["plot", "plot", "rubble"]) def test_rubble_being_cleared_then_cleared(self): K.build(self.c, "clear rubble") self.assertIn("being cleared", R.doors(self.c)[-1]["about"]) K.wait(self.c, D.CLEAR["days"]) self.assertEqual(self.c.plots, 4) self.assertEqual([x["kind"] for x in R.doors(self.c)[7:]], ["plot"] * 4) def test_a_full_fort(self): self.c.plots = 4 self.c.facilities = {f: 1 for f in D.FACILITIES} self.assertEqual([x["kind"] for x in R.doors(self.c)[7:]], ["facility"] * 4) def test_one_day_left_is_singular(self): self.c.project = {"what": "infirmary", "level": 1, "done": self.c.day + 1} self.assertIn("1 day left", R.doors(self.c)[7]["about"]) def test_does(self): F = D.FACILITIES self.assertEqual(R.does("machine shop", F["machine shop"]["levels"][1]), "gear and convoy 30% cheaper") self.assertEqual(R.does("drill yard", F["drill yard"]["levels"][0]), "+25% XP from every mission") self.assertEqual(R.does("radio room", F["radio room"]["levels"][1]), "+2 intel a week, missions wait 2 days longer") self.assertEqual(R.does("radio room", F["radio room"]["levels"][0]), "+1 intel a week, missions wait 1 day longer") def test_walking_the_corridor_is_not_the_campaign(self): day, log = self.c.day, list(self.c.log) R.doors(self.c) self.assertEqual((self.c.day, self.c.log), (day, log)) if __name__ == "__main__": unittest.main()