def test_getitem(self): map_ = ["#.", "#."] wall = LabyrinthObject(True) empty = LabyrinthObject(False) labyrinth = Labyrinth3d([map_, map_]) self.assertRaises(TypeError, labyrinth.__getitem__, 1) self.assertRaises(IndexError, labyrinth.__getitem__, Location(-1, 1, 0)) for x in range(2): for y in range(2): for z in range(2): location = Location(x, y, z) if y == 0: self.assertEqual(wall, labyrinth[location]) else: self.assertEqual(empty, labyrinth[location])
def test_getitem(self): map_ = [".#.", "##.", ".#."] labyrinth = Labyrinth(map_) wall = LabyrinthObject(True) empty = LabyrinthObject(False) for x in range(3): for y in range(3): current = labyrinth[Location(x, y)] if y == 1 or x == 1 and y == 0: self.assertEqual(current, wall) else: self.assertEqual(current, empty) self.assertRaises(TypeError, labyrinth.__getitem__, 1) self.assertRaises(IndexError, labyrinth.__getitem__, Location(-1, 1))
def test_init(self): map_ = ["#..", "..."] labyrinth = Labyrinth(map_) expected_map = [[LabyrinthObject(True), LabyrinthObject(False), LabyrinthObject(False)], [LabyrinthObject(False), LabyrinthObject(False), LabyrinthObject(False)]] self.assertEqual(labyrinth.width, 2) self.assertEqual(labyrinth.height, 3) self.assertEqual(labyrinth.map, expected_map)
def test_equal(self): wall1 = LabyrinthObject(True) wall2 = LabyrinthObject(True) self.assertEqual(wall1, wall2)
def test_str(self): wall = LabyrinthObject(True) self.assertEqual(str(wall), "Wall") empty = LabyrinthObject(False) self.assertEqual(str(empty), "Empty")
def test_init_empty(self): empty = LabyrinthObject(False) self.assertFalse(empty.is_wall)
def test_init_wall(self): wall = LabyrinthObject(True) self.assertTrue(wall.is_wall)
def test_str_row(self): wall = LabyrinthObject(True) empty = LabyrinthObject(False) map_ = [wall, empty, wall] self.assertEqual(Labyrinth.str_line(map_), "#.#")