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_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_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_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_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_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_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_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)