Esempio n. 1
0
    def test_is_game_completed(self):
        game = Game()

        game_result = game.is_game_completed()
        game.bot_field = Field()
        self.assertFalse(game_result[0])
        self.assertFalse(game_result[1])
        game.bot_field = Field(Field.get_arrange_ships())
        game.player_field = Field(Field.get_arrange_ships())

        game_result = game.is_game_completed()
        self.assertFalse(game_result[0])
        self.assertTrue(game_result[1])

        for _ in range(100):
            game.bot_field = Field(Field.get_arrange_ships())

        game_result = game.is_game_completed()
        self.assertTrue(game_result[0])
        self.assertTrue(game_result[1])

        game.bot_field = Field(Field.get_arrange_ships())
        for _ in range(100):
            game.player_field = Field(Field.get_arrange_ships())

        game_result = game.is_game_completed()
        self.assertTrue(game_result[0])
        self.assertFalse(game_result[1])
Esempio n. 2
0
    def test_extract_to_render(self):
        game = Game()
        game.bot_field = Field(Field.get_arrange_ships())
        game.player_field = Field(Field.get_arrange_ships())
        buffer = BufferToGameLogic()
        buffer_to_render = BufferToRender()
        game.extract_to_render(BufferToGameLogic(), buffer_to_render)

        self.assertEqual(len(buffer_to_render.player_cells), 100)
        self.assertEqual(len(buffer_to_render.bot_cells), 100)
        self.assertEqual(len(buffer_to_render.pre_show_cell), 0)

        game = Game()
        buffer.pre_show_cell_index = (1, 1)
        buffer_to_render = BufferToRender()
        game.extract_to_render(buffer, buffer_to_render)
        self.assertEqual(len(buffer_to_render.pre_show_cell), 1)
Esempio n. 3
0
 def test_arrange_ships_automatically(self):
     for _ in range(100):
         self.assertEqual(len(Field.get_arrange_ships()), 10)