コード例 #1
0
 def test_find_single_nearby_food_(self):
     for test_num in range(0, 100):
         world = [[CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
                  [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
                  [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
                  [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
                  [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
                  [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY], ]
         food_level = [['', '', '', '', '', ''],
                       ['', '', '', '', '', ''],
                       ['', '', '', '', '', ''],
                       ['', '', '', '', '', ''],
                       ['', '', '', '', '', ''],
                       ['', '', '', '', '', '']]
         test_world = World(WORLD_DIM, NUM_FOODS)
         test_world.grid = world
         test_world.food_level = food_level
         creature_row = randrange(0, WORLD_DIM - 1)
         creature_col = randrange(0, WORLD_DIM - 1)
         test_creature = Creature((creature_row, creature_col), 0)
         food_location = [-1, -1]
         while not test_creature.legal_move(test_world, food_location):
             food_direction = choice([[1, 0], [-1, 0], [0, 1], [0, -1]])
             food_location = [creature_row - food_direction[0], creature_col - food_direction[1]]
             test_world.set_cell(food_location[0], food_location[1], CELL_FOOD)
             test_world.reset_food_level(food_location[0], food_location[1])
         test_world.grow_all_food_level()
         submission_output = test_creature.find_nearby_food(test_world)
         proper_output = food_location
         self.assertEqual(proper_output, submission_output, "The test randomly places a food on one of the cells adjacent to the creature. Then test find_nearby_food method.")
コード例 #2
0
 def test_find_single_nearby_food_(self):
     for test_num in range(0, 100):
         world = [
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
             [
                 CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
                 CELL_EMPTY
             ],
         ]
         food_level = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                       [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                       [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
         test_world = World(WORLD_DIM, NUM_FOODS)
         test_world.grid = world
         test_world.food_level = food_level
         creature_row = randrange(0, WORLD_DIM - 1)
         creature_col = randrange(0, WORLD_DIM - 1)
         test_creature = Creature((creature_row, creature_col), 0)
         food_location = [-1, -1]
         while not test_creature.legal_move(test_world, food_location):
             food_direction = choice([[1, 0], [-1, 0], [0, 1], [0, -1]])
             food_location = [
                 creature_row - food_direction[0],
                 creature_col - food_direction[1]
             ]
             test_world.set_cell(food_location[0], food_location[1],
                                 CELL_FOOD)
             test_world.reset_food_level(food_location[0], food_location[1])
         test_world.grow_all_food_level()
         submission_output = test_creature.find_nearby_food(test_world)
         proper_output = food_location
         self.assertEqual(
             proper_output, submission_output,
             "The test randomly places a food on one of the cells adjacent to the creature. Then test find_nearby_food method."
         )
コード例 #3
0
 def test_cant_find_far_food_(self):
     world = [[CELL_FOOD, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY], ]
     food_level = [[1, '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', '']]
     test_world = World(6, 1)
     test_world.grid = world
     test_world.food_level = food_level
     test_creature = Creature([4, 4], 0)
     proper_output = None
     submission_output = test_creature.find_nearby_food(test_world)
     self.assertEqual(proper_output, submission_output, "When the food is far away from the creature, find_nearby_food should return None.")
コード例 #4
0
 def test_find_single_nearby_food_(self):
     world = [[CELL_FOOD, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY],
              [CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY], ]
     food_level = [[1, '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''],
                   ['', '', '', '', '', '']]
     test_world = World(WORLD_DIM, NUM_FOODS)
     test_world.grid = world
     test_world.food_level = food_level
     test_creature = Creature((0, 1), 0)
     proper_output = [0, 0]
     submission_output = test_creature.find_nearby_food(test_world)
     self.assertEqual(proper_output, submission_output, "When creature is at (0,1) and food is on (0,0), find_nearby_food should return [0,0].")
コード例 #5
0
 def test_cant_find_far_food_(self):
     world = [
         [
             CELL_FOOD, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
     ]
     food_level = [[1, '', '', '', '', ''], ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''], ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''], ['', '', '', '', '', '']]
     test_world = World(6, 1)
     test_world.grid = world
     test_world.food_level = food_level
     test_creature = Creature([4, 4], 0)
     proper_output = None
     submission_output = test_creature.find_nearby_food(test_world)
     self.assertEqual(
         proper_output, submission_output,
         "When the food is far away from the creature, find_nearby_food should return None."
     )
コード例 #6
0
 def test_find_single_nearby_food_(self):
     world = [
         [
             CELL_FOOD, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
         [
             CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
             CELL_EMPTY
         ],
     ]
     food_level = [[1, '', '', '', '', ''], ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''], ['', '', '', '', '', ''],
                   ['', '', '', '', '', ''], ['', '', '', '', '', '']]
     test_world = World(WORLD_DIM, NUM_FOODS)
     test_world.grid = world
     test_world.food_level = food_level
     test_creature = Creature((0, 1), 0)
     proper_output = [0, 0]
     submission_output = test_creature.find_nearby_food(test_world)
     self.assertEqual(
         proper_output, submission_output,
         "When creature is at (0,1) and food is on (0,0), find_nearby_food should return [0,0]."
     )