def test_check_if_position_contain_char(self): map = Map() map.generate(20, 10, TREE) map.put(10, 5, EMPTY) self.assertTrue(map.check(10, 5, EMPTY)) self.assertFalse(map.check(10, 6, EMPTY)) self.assertTrue(map.check(10, 6, TREE))
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_calculate_items_on_map(self): map = Map() map.generate(20, 10, EMPTY) count = 0 for x, y in [[0, 0], [3, 4], [5, 6]]: count += 1 map.put(x, y, TREE) self.assertEqual(map.count(TREE), count) self.assertEqual(map.count(EMPTY), 20 * 10 - count)
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)