def test_get_food_level(self): world = World(4, 0) cell = ArableLandCell(world, [0, 0], 0) cell.set_food_level(1) expected_output = 1 world.set_cell(0, 0, cell) submited_output = world.get_food_level(0, 0) self.assertEqual(submited_output, expected_output)
def test_find_best_neighbor_food_metric_1(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=2) test_world = World(6, 0) food_cell = ArableLandCell(test_world, [2, 0], 0) test_world.set_cell(2, 0, food_cell) food_cell.set_food_level(2) submited_output = near_sighted_creature.find_best_neighbor(test_world, METRIC_FOOD) expected_output = [1, 0] self.assertEqual(submited_output, expected_output)
def test_eat_less_hungry_on_food(self): creature = Creature([0, 0], 0.5, 1) test_world = World(4, 0) food_cell = ArableLandCell(test_world, [0, 0], 0) for i in range(200): food_cell.grow() test_world.set_cell(0, 0, food_cell) submited_output = creature.eat(test_world) expected_output = True self.assertEqual(submited_output, expected_output) self.assertEqual(creature.get_hunger_level(), 0)
def test_find_best_neighbor_food_metric_1(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=2) test_world = World(6, 0) food_cell = ArableLandCell(test_world, [2, 0], 0) test_world.set_cell(2, 0, food_cell) food_cell.set_food_level(2) submited_output = near_sighted_creature.find_best_neighbor( test_world, METRIC_FOOD) expected_output = [1, 0] self.assertEqual(submited_output, expected_output)
def test_find_best_neighbor_elevation_metric_2(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=1) test_world = World(6, 0) high_cell1 = LandCell(test_world, [0, 0], 2) test_world.set_cell(0, 0, high_cell1) high_cell2 = LandCell(test_world, [1, 0], 0) test_world.set_cell(1, 0, high_cell2) high_cell3 = LandCell(test_world, [0, 1], 1) test_world.set_cell(0, 1, high_cell3) high_cell4 = LandCell(test_world, [1, 1], 2) test_world.set_cell(1, 1, high_cell4) submited_output = near_sighted_creature.find_best_neighbor( test_world, METRIC_ELEVATION) expected_output = [1, 0] self.assertEqual(submited_output, expected_output)
def test_find_best_neighbor_elevation_metric_2(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=1) test_world = World(6, 0) high_cell1 = LandCell(test_world, [0, 0], 2) test_world.set_cell(0, 0, high_cell1) high_cell2 = LandCell(test_world, [1, 0], 0) test_world.set_cell(1, 0, high_cell2) high_cell3 = LandCell(test_world, [0, 1], 1) test_world.set_cell(0, 1, high_cell3) high_cell4 = LandCell(test_world, [1, 1], 2) test_world.set_cell(1, 1, high_cell4) submited_output = near_sighted_creature.find_best_neighbor(test_world, METRIC_ELEVATION) expected_output = [1, 0] self.assertEqual(submited_output, expected_output)
def test_get_neighbors_corner(self): world = World(world_dim=10, num_foods=10) cell = LandCell(world, [9, 9], 0) neighbors = cell.neighbors() submitted_num_neighbors = len(neighbors) expected_neighbors = [[8, 9], [9, 8]] expected_num_neighbors = len(expected_neighbors) self.assertEqual(submitted_num_neighbors, expected_num_neighbors) for neighbor in neighbors: self.assertIn(neighbor.get_location(), expected_neighbors)
def test_grow_all_food_level(self): world = World(4, 0) cell = ArableLandCell(world, [0, 0], 0) cell.set_food_level(0) expected_output = FOOD_GROWTH world.set_cell(0, 0, cell) world.grow_all_food_level() submited_output = world.get_food_level(0, 0) self.assertEqual(submited_output, expected_output)
def test_get_dim(self): expected_output = 4 world = World(expected_output, 1) submited_output = world.get_dim() self.assertEqual(submited_output, expected_output)
def test_set_cell(self): world = World(4, 0) expected_output = ArableLandCell(world, [0, 0], 0) world.set_cell(0, 0, expected_output) submited_output = world.get_cell(0, 0) self.assertEqual(submited_output, expected_output)
def test_find_best_neighbor_does_not_crash(self): near_sighted_creature = Creature([0, 0], INIT_HUNGER, 2) test_world = World(6, 0) near_sighted_creature.find_best_neighbor(test_world, METRIC_COMBINED)
def test_legal_move_creatures_out_of_bounds_locaiton(self): test_world = World(4, 0) test_creature = Creature([0, 0], INIT_HUNGER, 1) self.assertFalse(test_creature.legal_move([6, 6], test_world))
def test_legal_move_creatures_legal_locaiton(self): test_world = World(4, 0) test_creature = Creature([0, 0], INIT_HUNGER, 1) self.assertTrue(test_creature.legal_move([1, 0], test_world))
def test_move_legal_move(self): creature = Creature([0, 0], INIT_HUNGER, 1) test_world = World(4, 0) submited_output = creature.move("Right", test_world) expected_output = [0, 1] self.assertEqual(submited_output, expected_output)
def test_move_illegal_move_off_world(self): creature = Creature([0, 0], INIT_HUNGER, 1) test_world = World(4, 0) submited_output = creature.move("Left", test_world) expected_output = False self.assertEqual(submited_output, expected_output)
def test_find_best_neighbor_combined_metric_food_beyond_eyesight(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=2) test_world = World(6, 0) high_cell1 = LandCell(test_world, [0, 0], 2) test_world.set_cell(0, 0, high_cell1) high_cell2 = LandCell(test_world, [1, 0], 3) test_world.set_cell(1, 0, high_cell2) high_cell3 = LandCell(test_world, [0, 1], 0) test_world.set_cell(0, 1, high_cell3) high_cell4 = LandCell(test_world, [1, 1], 2) test_world.set_cell(1, 1, high_cell4) food_cell = ArableLandCell(test_world, [3, 0], 0) test_world.set_cell(3, 0, food_cell) food_cell.set_food_level(2) submited_output = near_sighted_creature.find_best_neighbor( test_world, METRIC_COMBINED) expected_output = [0, 1] self.assertEqual(submited_output, expected_output)
def test_get_cell(self): world = World(4, 0) cell = world.get_cell(0, 0) self.assertEqual(type(cell), LandCell)
def test_find_best_neighbor_combined_metric_food_beyond_eyesight(self): near_sighted_creature = Creature([0, 0], starting_hunger=1, eye_sight=2) test_world = World(6, 0) high_cell1 = LandCell(test_world, [0, 0], 2) test_world.set_cell(0, 0, high_cell1) high_cell2 = LandCell(test_world, [1, 0], 3) test_world.set_cell(1, 0, high_cell2) high_cell3 = LandCell(test_world, [0, 1], 0) test_world.set_cell(0, 1, high_cell3) high_cell4 = LandCell(test_world, [1, 1], 2) test_world.set_cell(1, 1, high_cell4) food_cell = ArableLandCell(test_world, [3, 0], 0) test_world.set_cell(3, 0, food_cell) food_cell.set_food_level(2) submited_output = near_sighted_creature.find_best_neighbor(test_world, METRIC_COMBINED) expected_output = [0, 1] self.assertEqual(submited_output, expected_output)