예제 #1
0
 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)
예제 #2
0
    def create_ship(self, number_of_decks):
        inc_component, const_component = self.__generate_allowed_position_of_ship(
            number_of_decks)
        names_of_position = self.__generate_names_of_position(
            inc_component, const_component)
        names_of_forbidden_position = self.__generate_names_forbidden_position(
            inc_component, const_component)
        ship = ship_pack.Ship()
        for item in names_of_position:
            cell = self.__board.get_cell_of_board(item)
            deck = ship_pack.Deck(cell)
            ship.add_deck(deck)

        self.__forbid_positions(names_of_position)
        self.__forbid_positions(names_of_forbidden_position)
        return ship
예제 #3
0
 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_ship_ship_bullet(self):
     self.assertFalse(self.ship_bullet.kill_ship(Ship(15, 15, 20, 20, 5)))
예제 #5
0
 def setUp(self):
     self.ship = Ship(10, 20, 30, 40, 5)
예제 #6
0
class TestShip(unittest.TestCase):
    def setUp(self):
        self.ship = Ship(10, 20, 30, 40, 5)

    def test_initialization(self):
        self.assertEqual(self.ship.x_left, 10)
        self.assertEqual(self.ship.y_top, 20)
        self.assertEqual(self.ship.width, 30)
        self.assertEqual(self.ship.height, 40)
        self.assertEqual(self.ship.step, 5)
        self.assertEqual(self.ship.y_bottom(), 60)
        self.assertEqual(self.ship.x_right(), 40)

    def test_normal_rotation(self):
        self.assertEqual(self.ship.angle, 90)
        self.ship.rotate(1, 10)
        self.assertEqual(self.ship.angle, 80)
        for i in range(9):
            self.ship.rotate(-1, 10)
        self.assertEqual(self.ship.angle, 170)

    def test_large_angle_rotation(self):
        angle_before = self.ship.angle
        self.ship.rotate(-1, 170)
        self.assertEqual(angle_before, self.ship.angle)

    def test_normal_move(self):
        self.ship.move(1, 100)
        self.assertEqual(self.ship.x_left, 15)
        self.ship.move(-1, 100)
        self.assertEqual(self.ship.x_left, 10)

    def test_overrun(self):
        for i in range(10):
            self.ship.move(-1, 50)
        self.assertEqual(self.ship.x_left, 0)
        for i in range(10):
            self.ship.move(1, 50)
        self.assertEqual(self.ship.x_left, 20)

    def test_exception(self):
        with self.assertRaises(KeyError):
            self.ship.rotate(-2, 10)
        with self.assertRaises(KeyError):
            self.ship.move(2, 100)
예제 #7
0
 def test_kill_ship(self):
     self.assertTrue(self.bullet.kill_ship(Ship(30, 30, 10, 10, 5)))
     self.assertFalse(self.bullet.kill_ship(Ship(40, 30, 20, 20, 10)))
예제 #8
0
 def setUp(self):
     self.invader = Invader(10, 20, 15, 15, 5, 2, 1, 0)
     self.ship = Ship(50, 100, 10, 10, 5)