Пример #1
0
 def test_can_reverse_direction_west_to_east(self):
     fish = TestFish(direction=simfish.WEST)
     fish.reverse()
     self.assertEqual(simfish.EAST, fish.direction)
     self.assertEqual(0.0, fish.reversal)
     self.assertEqual(0.0, fish.upward)
     self.assertEqual(0.0, fish.downward)
Пример #2
0
 def test_will_swim_forward(self):
     tank = TestTank()
     fish = TestFish(direction=simfish.EAST)
     tank.reset_movement_record()
     for i in range(fish.energy):
         fish.turn(tank)
         self.assertEqual(fish, tank.last_item_moved)
         self.assertEqual(i + 1, tank.total_dx)
         self.assertEqual(0, tank.total_dy)
     self.assertEqual(0, fish.energy)
Пример #3
0
 def test_can_move_items(self):
     tank = simfish.Tank(None)
     fishes = [TestFish(), TestFish(), TestFish()]
     tank.put(fishes[0], x=0, y=0)
     tank.put(fishes[1], x=0, y=0)
     tank.put(fishes[2], x=1, y=1)
     other_fish = tank.items_with(fishes[0])
     self.assertEqual(1, len(other_fish))
     self.assertTrue(fishes[1] in other_fish)
     self.assertFalse(fishes[2] in other_fish)
     tank.move(fishes[0], dx=1, dy=1)
     other_fish = tank.items_with(fishes[0])
     self.assertEqual(1, len(other_fish))
     self.assertFalse(fishes[1] in other_fish)
     self.assertTrue(fishes[2] in other_fish)
Пример #4
0
 def test_can_remove_items_from_tank(self):
     tank = simfish.Tank(None)
     fish = TestFish()
     tank.put(fish, x=0, y=0)
     self.assertEqual(1, len(tank))
     tank.remove(fish)
     self.assertEqual(0, len(tank))
Пример #5
0
 def test_can_take_turns(self):
     tank = simfish.Tank(None)
     fish = TestFish()
     tank.put(fish, x=0, y=0)
     for i in range(10):
         self.assertEqual(i, fish.turns_taken)
         tank.turn()
     self.assertEqual(10, fish.turns_taken)
Пример #6
0
 def test_can_identify_overlapping_items(self):
     tank = simfish.Tank(None)
     fishes = [TestFish(), TestFish(), TestFish()]
     for fish in fishes:
         tank.put(fish, x=0, y=0)
     other_fish = tank.items_with(fishes[0])
     self.assertEqual(2, len(other_fish))
     self.assertFalse(fishes[0] in other_fish)
     self.assertTrue(fishes[1] in other_fish)
     self.assertTrue(fishes[2] in other_fish)
     other_fish = tank.items_with(fishes[1])
     self.assertEqual(2, len(other_fish))
     self.assertTrue(fishes[0] in other_fish)
     self.assertFalse(fishes[1] in other_fish)
     self.assertTrue(fishes[2] in other_fish)
     other_fish = tank.items_with(fishes[2])
     self.assertEqual(2, len(other_fish))
     self.assertTrue(fishes[0] in other_fish)
     self.assertTrue(fishes[1] in other_fish)
     self.assertFalse(fishes[2] in other_fish)
Пример #7
0
 def test_can_put_items_in_tank(self):
     tank = simfish.Tank(None)
     for i in range(1, 100):
         tank.put(TestFish(), x=0, y=0)
         self.assertEqual(i, len(tank))
Пример #8
0
 def test_can_create_mobile_object(self):
     fish = TestFish(direction=simfish.EAST)
     self.assertEqual(simfish.EAST, fish.direction)
     self.assertEqual(0.0, fish.reversal)
     self.assertEqual(0.0, fish.upward)
     self.assertEqual(0.0, fish.downward)