Ejemplo n.º 1
0
 def test_adding_objects_out_of_bounds_raise_exceptions(self):
     nest = Nest(create_id(), 10000, 100)
     with self.assertRaises(OutOfBorder):
         self.environment.add_nest(nest)
     nest = Nest(create_id(), 100, 10000)
     with self.assertRaises(OutOfBorder):
         self.environment.add_nest(nest)
Ejemplo n.º 2
0
 def test_moving_an_object_updates_map(self):
     nest, _ = Nest.create(50, 50, create_id())
     self.environment.add_nest(nest)
     ant, _ = Ant.create(nest, create_id())
     self.environment.add_ant(ant)
     self.assertIn(ant, self.environment.map[50, 50])
     self.environment.move(ant, 51, 51)
     self.assertIn(ant, self.environment.map[51, 51])
Ejemplo n.º 3
0
 def test_can_create_an_ant(self):
     nest = Nest(create_id(), 100, 100)
     id = create_id()
     ant, events = Ant.create(nest, id)
     self.assertEqual(nest.posx, ant.posx)
     self.assertEqual(nest.posy, ant.posy)
     self.assertEqual(nest.id, ant.nest_id)
     self.assertEqual(id, ant.id)
     self.assertIn(AntBorn(id, nest.posx, nest.posy, nest.id), events)
Ejemplo n.º 4
0
 def init(self) -> List[Any]:
     self.environment, environment_events = Environment.create(
         200, 200, create_id())
     nest, nest_events = Nest.create(50, 50, create_id())
     self.environment.add_nest(nest)
     ant, ant_events = Ant.create(nest, create_id())
     self.environment.add_ant(ant)
     food, food_events = Food.create(150, 150, create_id())
     self.environment.add_food(food)
     return environment_events + nest_events + ant_events + food_events
Ejemplo n.º 5
0
 def test_can_create_a_nest(self):
     x = 123
     y = 345
     id = create_id()
     nest, events = Nest.create(x, y, id)
     self.assertEqual(x, nest.posx)
     self.assertEqual(y, nest.posy)
     self.assertEqual(id, nest.id)
     self.assertIn(NestCreated(id, x, y), events)
Ejemplo n.º 6
0
 def test_can_create_a_Pheromone(self):
     x = 123
     y = 345
     type = 'long'
     id = create_id()
     pheromone, events = Pheromone.create(x, y, type, id)
     self.assertEqual(x, pheromone.posx)
     self.assertEqual(y, pheromone.posy)
     self.assertEqual(id, pheromone.id)
     self.assertIn(PheromoneDropped(id, x, y, 200, type), events)
Ejemplo n.º 7
0
 def create(size_x, size_y, id=create_id()):
     return Environment(id, size_x,
                        size_y), [EnvironmentCreated(id, size_x, size_y)]
Ejemplo n.º 8
0
 def create(nest: Nest, id=create_id()):
     return Ant(id, nest.posx, nest.posy,
                nest.id), [AntBorn(id, nest.posx, nest.posy, nest.id)]
Ejemplo n.º 9
0
 def setUp(self):
     self.x = 1231
     self.y = 5432
     self.env_id = create_id()
     self.environment, self.events = Environment.create(size_x=self.x, size_y=self.y, id=self.env_id)
Ejemplo n.º 10
0
 def test_can_add_objects(self):
     nest = Nest(create_id(), 100, 100)
     self.environment.add_nest(nest)
     self.assertIn(nest, self.environment.nests)
Ejemplo n.º 11
0
 def create(x, y, id=create_id()):
     return Nest(id, x, y), [NestCreated(id, x, y)]
Ejemplo n.º 12
0
 def create(x, y, food_units, id=create_id()):
     return Food(id, x, y, food_units), [FoodDropped(id, x, y, food_units)]
Ejemplo n.º 13
0
 def create(x, y, type, id=create_id()):
     pheromone = Pheromone(id, x, y, type)
     return pheromone, [PheromoneDropped(id, x, y, pheromone.life, type)]
Ejemplo n.º 14
0
 def test_can_run_the_app(self):
     projection = TKProjection(Queue())
     projection.update([EnvironmentCreated(create_id(), 100, 100)])
     nest_id = create_id()
     projection.update([NestCreated(nest_id, 50, 50)])
     projection.update([AntBorn(create_id(), 10, 10, nest_id)])