def test_wall_to_rock(self): """Swap wall into a rock""" grid = sg(".W.\n..W\nWWW") target = sg(".R.\n..R\nRRR") swaps = (wir, ) grid2 = swap(grid, swaps) self.assertEqual(grid2, target)
def test_walking_entities(self): """Walking entities""" for entity in ENTITIES: grid = sg("...\n.{}.\n...".format(entity)) # Make target grid states target_format = lambda x: sg(x.format(entity)) targets = map( target_format, ( ".{}.\n...\n...", "...\n...\n.{}.", "...\n{}..\n...", "...\n..{}\n...", ), ) # 'Entity' is you rule behaviours = {entity.lower(): mb(you=True)} for step, target in zip(STEPS, targets): with self.subTest(grid): grid2, youwin = timestep(grid, behaviours, step) self.assertEqual(grid2, target) self.assertIsNone(youwin)
def test_no_byproducts(self): """Wall is rock does not mess anything else up""" for e in filterfalse(lambda x: x == "W", ENTITIES): with self.subTest(entity=e): grid = sg(f".W{e}\n..W\nW{e}W") target = sg(f".R{e}\n..R\nR{e}R") swaps = (wir, ) grid2 = swap(grid, swaps) self.assertEqual(grid2, target)
def test_all_swaps_but_stationary(self): """A is B, but B is B""" for a, b in permutations(ENTITIES, 2): with self.subTest(entity_a=a, entity_b=b): grid = sg(f".{a}.\n..{a}\n{a}{a}{a}") target = sg(f".{b}.\n..{b}\n{b}{b}{b}") swaps = ((a, b), (a, a)) grid2 = swap(grid, ()) self.assertEqual(grid2, grid)
def test_all_no_swaps(self): """No swaps on all symbols""" for symbol in SYMBOLS: with self.subTest(symbol=symbol): grid = sg(".{0}.\n..{0}\n{0}{0}{0}".format(symbol)) grid2 = swap(grid, ()) self.assertEqual(grid2, grid)
def test_claustrophobic_baba(self): """Baba with nowhere to move""" grid = sg("B") for step in STEPS: with self.subTest(grid): grid2, youwin = timestep(grid, biy, step) self.assertEqual(grid2, grid) self.assertIsNone(youwin)
def test_identity_crisis(self): """Baba is not you""" for entity in ENTITIES: grid = sg("{}.".format(entity)) behaviour = {entity.lower(): mb(you=False)} with self.subTest(entity): grid2, youwin = timestep(grid, behaviour, ">") self.assertEqual(grid2, grid) self.assertIsNone(youwin)
def test_complex_walking(self): """Test more complicates sequences of steps""" paths = ("V>^<<^^<>>", "^<VV>>^^<V", "^^VV<><>") targets = map(sg, ("..B\n...\n...", "...\n.B.\n...", "...\n...\n.B.")) for steps, target in zip(paths, targets): grid = sg("...\n.B.\n...") for step in steps: grid, youwin = timestep(grid, biy, step) self.assertIsNone(youwin) self.assertEqual(grid, target)
def test_but_wall_is_wall(self): """Would swap wall to rock, but wall is wall""" grid = sg(".W.\n..W\nWWW") swaps = (wir, wiw) grid2 = swap(grid, swaps) self.assertEqual(grid2, grid)
def test_no_swaps(self): """Lots of walls but no swap rule""" grid = sg(".W.\n..W\nWWW") grid2 = swap(grid, ()) self.assertEqual(grid2, grid)