def test_initialization(self): self.assertEqual(self.invaders.arr_invaders[0][0], Invader(10, 10, 15, 15, 5, 3, 2, 0)) self.assertEqual(self.invaders.arr_invaders[1][1], Invader(30, 30, 15, 15, 5, 2, 1, 1)) self.assertEqual(self.invaders.arr_invaders[2][2], Invader(50, 50, 15, 15, 5, 1, 0, 0)) self.assertEqual(self.invaders.count, 12) self.assertEqual(self.invaders.height, 3) self.assertEqual(self.invaders.width, 5)
def setUp(self): self.invader = Invader(0, 0, 15, 15, 5, 2, 1, 0) self.ship = Ship(50, 100, 10, 10, 5) arr = [[InvaderState(3, 2) for i in range(3)], [InvaderState(2, 1) for j in range(4)], [InvaderState(1, 0) for k in range(5)]] self.invaders = Invaders(10, 10, self.invader, arr)
def test_parse(self): text = \ 'Invaders: pos(0,0)\n' \ '[1,1] [1,2] [1,3]\n' \ 'Bunkers:\n' \ 'pos(70,430) size(13,3)\n' \ 'pos(340,430) size(13,3)\n' level = Level(text) invaders, bunkers = level.invaders, level.bunkers expected = [[ Invader(0, 75, 42, 30, 5, 1, 1, 0), Invader(47, 75, 42, 30, 5, 1, 2, 0), Invader(94, 75, 42, 30, 5, 1, 3, 0) ]] actual = invaders.arr_invaders self.assertEqual(expected, actual)
def test_kill_ship(self): self.bullet.is_invader_bullet = True invader = Invader(0, 0, 10, 10, 5, 1, 1, 1) invaders = Invaders(0, 0, invader, [[InvaderState(1, 1)]]) obj = self.bullets.kill(invaders, Ship(0, 0, 10, 10, 5), MysteryShip(10, 10, 5, 1)) self.assertTrue(isinstance(obj, Ship))
def test_kill_invader(self): self.assertFalse( self.bullet.kill_invader(Invader(20, 30, 10, 10, 5, 1, 1, 1)))
def setUp(self): self.invader = Invader(10, 20, 15, 15, 5, 2, 1, 0) self.ship = Ship(50, 100, 10, 10, 5)
class TestInvader(unittest.TestCase): def setUp(self): self.invader = Invader(10, 20, 15, 15, 5, 2, 1, 0) self.ship = Ship(50, 100, 10, 10, 5) def test_initialization(self): self.assertEqual(self.invader.x_right(), 25) self.assertEqual(self.invader.y_bottom(), 35) def test_can_move_right(self): self.assertFalse(self.invader.can_move_right(1, 30)) self.assertTrue(self.invader.can_move_right(1, 31)) def test_can_move_left(self): self.assertTrue(self.invader.can_move_left(-1)) self.invader.x_left = 4 self.assertFalse(self.invader.can_move_left(-1)) def test_can_move_down_without_bunkers(self): self.assertTrue(self.invader.can_move_down(self.ship, Bunkers())) self.invader.y_top = 65 + self.invader.height self.assertTrue(self.invader.can_move_down(self.ship, Bunkers())) self.invader.y_top = 66 + self.invader.height self.assertFalse(self.invader.can_move_down(self.ship, Bunkers())) def test_can_move_down_with_bunkers(self): bunkers = Bunkers() bunkers.add(Bunker(50, 40, (5, 5), 5)) self.assertTrue(self.invader.can_move_down(self.ship, bunkers)) bunkers.add(Bunker(50, 39, (5, 5), 5)) self.assertFalse(self.invader.can_move_down(self.ship, bunkers)) def test_change_style(self): style_before = self.invader.style self.invader.move(1, 1) self.assertNotEqual(self.invader.style, style_before) def test_move(self): self.invader.move(1, 1) self.assertEqual(self.invader.y_top, 25) self.assertEqual(self.invader.x_left, 15)