예제 #1
0
 def test_can_breathe(self):
     tank = TestTank()
     piranha_fish = simfish.PiranhaFish()
     self.assertTrue(piranha_fish.alive)
     self.assertEqual(simfish.PiranhaFish.ENERGY, piranha_fish.energy)
     piranha_fish.turn(tank)
     self.assertEqual(simfish.PiranhaFish.ENERGY - 1, piranha_fish.energy)
예제 #2
0
 def test_will_not_eat_clockwork_fish(self):
     tank = TestTank()
     others = [simfish.ClockworkFish()]
     tank.add_items_with(*others)
     piranha_fish = simfish.PiranhaFish()
     self.assertEqual(others, tank.items_with(piranha_fish))
     piranha_fish.turn(tank)
     self.assertEqual(others, tank.items_with(piranha_fish))
예제 #3
0
 def test_will_eat_diver_fish(self):
     tank = TestTank()
     others = [simfish.DiverFish()]
     tank.add_items_with(*others)
     piranha_fish = simfish.PiranhaFish()
     self.assertEqual(others, tank.items_with(piranha_fish))
     piranha_fish.turn(tank)
     self.assertEqual(0, len(tank.items_with(piranha_fish)))
예제 #4
0
 def test_can_create(self):
     piranha_fish = simfish.PiranhaFish()
     self.assertTrue(piranha_fish.alive)
     self.assertEqual(simfish.PiranhaFish.ENERGY, piranha_fish.energy)
     self.assertEqual(3, len(piranha_fish.diet))
     self.assertTrue(simfish.FishFood in piranha_fish.diet)
     self.assertTrue(simfish.SunFish in piranha_fish.diet)
     self.assertTrue(simfish.DiverFish in piranha_fish.diet)
예제 #5
0
 def test_will_only_eat_one_item_per_turn(self):
     tank = TestTank()
     others = [simfish.FishFood(), simfish.SunFish(), simfish.DiverFish()]
     tank.add_items_with(*others)
     piranha_fish = simfish.PiranhaFish()
     for count in range(len(others), 0, -1):
         self.assertEqual(count, len(tank.items_with(piranha_fish)))
         piranha_fish.turn(tank)
     self.assertEqual(0, len(tank.items_with(piranha_fish)))
예제 #6
0
 def test_can_die(self):
     tank = TestTank()
     piranha_fish = simfish.PiranhaFish()
     self.assertTrue(piranha_fish.alive)
     self.assertEqual(simfish.PiranhaFish.ENERGY, piranha_fish.energy)
     for i in range(simfish.PiranhaFish.ENERGY):
         piranha_fish.turn(tank)
     self.assertEqual(0, piranha_fish.energy)
     self.assertFalse(piranha_fish.alive)
예제 #7
0
 def test_will_float_when_dead(self):
     tank = TestTank()
     piranha_fish = simfish.PiranhaFish()
     for i in range(simfish.PiranhaFish.ENERGY):
         piranha_fish.turn(tank)
     self.assertFalse(piranha_fish.alive)
     tank.reset_movement_record()
     piranha_fish.turn(tank)
     self.assertEqual(piranha_fish, tank.last_item_moved)
     self.assertEqual(0, tank.total_dx)
     self.assertEqual(-1, tank.total_dy)
예제 #8
0
 def test_will_not_eat_other_creatures(self):
     tank = TestTank()
     others = [
         simfish.Snail(),
         simfish.SunFish(),
         simfish.DiverFish(),
         simfish.PiranhaFish(),
         simfish.ClockworkFish(),
     ]
     tank.add_items_with(*others)
     clockwork_fish = simfish.ClockworkFish()
     self.assertEqual(others, tank.items_with(clockwork_fish))
     clockwork_fish.turn(tank)
     self.assertEqual(others, tank.items_with(clockwork_fish))