|
@@ -0,0 +1,129 @@
|
|
|
|
+import unittest
|
|
|
|
+from GameOfLifeLibrary import *
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class FishTestCase(unittest.TestCase):
|
|
|
|
+ def test_fish_removal_1(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 1 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ fish = FishUnit(0, 0)
|
|
|
|
+ self.assertTrue(fish.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_removal_2(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 2 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ fish = FishUnit(0, 0)
|
|
|
|
+ self.assertFalse(fish.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_removal_3(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 3 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ fish = FishUnit(0, 0)
|
|
|
|
+ self.assertFalse(fish.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_removal_4(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 4 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ fish = FishUnit(0, 0)
|
|
|
|
+ self.assertTrue(fish.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_creation_1(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 2 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertFalse(unit.can_spawn_fish(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_creation_2(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 3 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertTrue(unit.can_spawn_fish(nbs))
|
|
|
|
+
|
|
|
|
+ def test_fish_creation_3(self):
|
|
|
|
+ nbs = [FishUnit(0, 0)] * 4 + [NoUnit(0, 0)] * 3 + [ShrimpUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertFalse(unit.can_spawn_fish(nbs))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class ShrimpTestCase(unittest.TestCase):
|
|
|
|
+ def test_shrimp_removal_1(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 1 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ shrimp = ShrimpUnit(0, 0)
|
|
|
|
+ self.assertTrue(shrimp.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_shrimp_removal_2(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 2 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ shrimp = ShrimpUnit(0, 0)
|
|
|
|
+ self.assertFalse(shrimp.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_shrimp_removal_3(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 3 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ shrimp = ShrimpUnit(0, 0)
|
|
|
|
+ self.assertFalse(shrimp.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def test_shrimp_removal_4(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 4 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ shrimp = ShrimpUnit(0, 0)
|
|
|
|
+ self.assertTrue(shrimp.should_be_killed(nbs))
|
|
|
|
+
|
|
|
|
+ def test_shrimp_creation_1(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 2 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertFalse(unit.can_spawn_shrimp(nbs))
|
|
|
|
+
|
|
|
|
+ def test_shrimp_creation_2(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 3 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertTrue(unit.can_spawn_shrimp(nbs))
|
|
|
|
+
|
|
|
|
+ def test_shrimp_creation_3(self):
|
|
|
|
+ nbs = [ShrimpUnit(0, 0)] * 4 + [NoUnit(0, 0)] * 3 + [FishUnit(0, 0)] * 5
|
|
|
|
+ unit = NoUnit(0, 0)
|
|
|
|
+ self.assertFalse(unit.can_spawn_shrimp(nbs))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class GameOfLifeClassTestCase(unittest.TestCase):
|
|
|
|
+ def test_init_1(self):
|
|
|
|
+ game = GameOfLife(3, 3)
|
|
|
|
+ game.parse_field(['nfr', 'fff', 'sfs'])
|
|
|
|
+ result = [[NoUnit(0, 0), FishUnit(0, 1), RockUnit(0, 2)],
|
|
|
|
+ [FishUnit(1, 0), FishUnit(1, 1), FishUnit(1, 2)],
|
|
|
|
+ [ShrimpUnit(2, 0), FishUnit(2, 1), ShrimpUnit(2, 2)]]
|
|
|
|
+ self.assertListEqual(game.cells, result)
|
|
|
|
+
|
|
|
|
+ def test_init_2(self):
|
|
|
|
+ game = GameOfLife(3, 4)
|
|
|
|
+ game.parse_field(['nfrr', 'fffr', 'sfsr'])
|
|
|
|
+ result = [[NoUnit(0, 0), FishUnit(0, 1), RockUnit(0, 2), RockUnit(0, 3)],
|
|
|
|
+ [FishUnit(1, 0), FishUnit(1, 1), FishUnit(1, 2), RockUnit(1, 3)],
|
|
|
|
+ [ShrimpUnit(2, 0), FishUnit(2, 1), ShrimpUnit(2, 2), RockUnit(2, 3)]]
|
|
|
|
+ self.assertListEqual(game.cells, result)
|
|
|
|
+
|
|
|
|
+ def test_init_3(self):
|
|
|
|
+ game = GameOfLife(4, 3)
|
|
|
|
+ game.parse_field(['nfr', 'fff', 'sfs', 'ssf'])
|
|
|
|
+ result = [[NoUnit(0, 0), FishUnit(0, 1), RockUnit(0, 2)],
|
|
|
|
+ [FishUnit(1, 0), FishUnit(1, 1), FishUnit(1, 2)],
|
|
|
|
+ [ShrimpUnit(2, 0), FishUnit(2, 1), ShrimpUnit(2, 2)],
|
|
|
|
+ [ShrimpUnit(3, 0), ShrimpUnit(3, 1), FishUnit(3, 2)]]
|
|
|
|
+ self.assertListEqual(game.cells, result)
|
|
|
|
+
|
|
|
|
+ def test_iterate_1(self):
|
|
|
|
+ game = GameOfLife(3, 3)
|
|
|
|
+ game.parse_field(['nff', 'fff', 'fff'])
|
|
|
|
+ game.iterate()
|
|
|
|
+ result = [[FishUnit(0, 0), NoUnit(0, 1), FishUnit(0, 2)],
|
|
|
|
+ [NoUnit(1, 0), NoUnit(1, 1), NoUnit(1, 2)],
|
|
|
|
+ [FishUnit(2, 0), NoUnit(2, 1), FishUnit(2, 2)]]
|
|
|
|
+ self.assertListEqual(game.cells, result)
|
|
|
|
+
|
|
|
|
+ def test_iterate_2(self):
|
|
|
|
+ game = GameOfLife(5, 5)
|
|
|
|
+ game.parse_field(['nffss', 'ffrrs', 'fffss', 'ssnss', 'frnnf'])
|
|
|
|
+ game.iterate()
|
|
|
|
+ game.iterate()
|
|
|
|
+ result = [[NoUnit(0, 0), FishUnit(0, 1), NoUnit(0, 2), NoUnit(0, 3), NoUnit(0, 4)],
|
|
|
|
+ [FishUnit(1, 0), NoUnit(1, 1), RockUnit(1, 2), RockUnit(1, 3), NoUnit(1, 4)],
|
|
|
|
+ [NoUnit(2, 0), NoUnit(2, 1), NoUnit(2, 2), ShrimpUnit(2, 3), NoUnit(2, 4)],
|
|
|
|
+ [NoUnit(3, 0), NoUnit(3, 1), NoUnit(3, 2), ShrimpUnit(3, 3), NoUnit(3, 4)],
|
|
|
|
+ [NoUnit(4, 0), RockUnit(4, 1), NoUnit(4, 2), ShrimpUnit(4, 3), NoUnit(4, 4)]]
|
|
|
|
+ self.assertListEqual(game.cells, result)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ unittest.main()
|