def test_put_item_on_map(self): x, y = randint(0, 20 - 1), randint(0, 10 - 1) map = Map() map.generate(20, 10, EMPTY) self.assertEqual(EMPTY, map.get(x, y)) map.put(x, y, TREE) self.assertEqual(TREE, map.get(x, y))
def test_clear_position(self): width, height = 20, 20 start_position = [randint(0, width - 1), randint(0, height - 1)] map = Map() map.generate(width, height, EMPTY) map.put(start_position[0], start_position[1], USER) self.assertEqual(map.get(start_position[0], start_position[1]), USER) map.clear(start_position) self.assertEqual(map.get(start_position[0], start_position[1]), map.empty_char)
def test_move_object(self): width, height = 20, 20 start_position = [randint(0, width - 1), randint(0, height - 1)] new_position = [randint(0, width - 1), randint(0, height - 1)] map = Map() map.generate(width, height, EMPTY) map.put(start_position[0], start_position[1], USER) self.assertEqual(map.get(start_position[0], start_position[1]), USER) self.assertEqual(map.get(new_position[0], new_position[1]), EMPTY) map.move(USER, start_position, new_position) self.assertEqual(map.get(start_position[0], start_position[1]), EMPTY) self.assertEqual(map.get(new_position[0], new_position[1]), USER) map.move(USER, new_position, [-1, -1]) self.assertEqual(map.get(new_position[0], new_position[1]), USER)
def test_init_map(self): width = 20 height = 10 map = Map() map.generate(width, height, EMPTY) self.assertEqual(height, len(map.map)) self.assertEqual(width, len(choice(map.map))) self.assertEqual( EMPTY, map.get(randint(0, width - 1), randint(0, height - 1))) self.assertEqual(map.width, width) self.assertEqual(map.height, height) self.assertEqual(map.empty_char, EMPTY) width = 2 height = 5 map.generate(width, height, TREE) self.assertEqual( TREE, map.get(randint(0, width - 1), randint(0, height - 1))) self.assertEqual(map.width, width) self.assertEqual(map.height, height) self.assertEqual(map.empty_char, TREE)
def test_get_item_by_xy(self): map = Map() map.generate(20, 10, EMPTY) self.assertEqual(map.get(-1, -1), STONE) self.assertEqual(map.get(1, 1), EMPTY)