from unittest import TestCase
from helpers.board_helper import BoardHelper
from core.board import Board


class TestBoardHelper(TestCase):
    def setUp(self):
        self.board = Board()
        self.board_helper = BoardHelper(self.board.all_ships)

    def test_generate_all_spots_returns_a_list_of_all_spaces(self):
        all_spots_list = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'E10', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'G10', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9', 'I10', 'J1', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'J9', 'J10']

        self.assertEqual(self.board_helper.generate_all_spots(), all_spots_list)

    def test_generate_empty_board_returns_an_empty_board(self):
        empty_board = [
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_empty_board(), empty_board)

    def test_generate_all_occupied_but_one_returns_a_board_with_one_open_spot(self):
        all_occupied_but_one = [
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            [None, 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
            ['Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss', 'Miss'],
        ]

        self.assertEqual(self.board_helper.generate_all_but_one(), all_occupied_but_one)

    def test_generate_full_board_returns_a_board_with_all_spots_filled(self):
        full_board = [
            ['Sunk', "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
            ['Sunk', "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
            ['Sunk', "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
            ['Sunk', "Miss", "Miss", "Miss", 'Sunk', "Miss", "Miss", "Miss", "Miss", "Miss"],
            ['Sunk', 'Sunk', "Miss", "Miss", 'Sunk', "Miss", "Miss", "Miss", "Miss", "Miss"],
            ["Miss", 'Sunk', "Miss", "Miss", 'Sunk', "Miss", "Miss", "Miss", "Miss", "Miss"],
            ["Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
            ["Miss", "Miss", "Miss", "Miss", "Miss", "Miss", 'Sunk', 'Sunk', 'Sunk', 'Sunk'],
            ["Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
            ['Sunk', 'Sunk', 'Sunk', "Miss", "Miss", "Miss", "Miss", "Miss", "Miss", "Miss"],
        ]

        self.assertEqual(self.board_helper.generate_full_board(), full_board)

    def test_generate_board_with_ships_returns_a_board_with_ships(self):
        board_with_ships = [
            [self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1]],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_board_with_ships(), board_with_ships)

    def test_generate_board_with_hit_returns_a_board_with_a_hit(self):
        board_with_a_hit = [
            [self.board.all_ships[0], 'Hit', self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1]],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_board_with_hit(), board_with_a_hit)

    def test_generate_board_with_a_miss_returns_a_board_with_a_miss(self):
        board_with_a_miss = [
            [self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], None, None, None, None, self.board.all_ships[3]],
            ['Miss', None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1]],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_board_with_a_miss(), board_with_a_miss)

    def test_generate_board_with_hit_and_miss_returns_a_board_with_a_hit_and_miss(self):
        board_with_hit_and_miss = [
            ['Hit', self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], self.board.all_ships[0], None, None, None, None, self.board.all_ships[3]],
            ['Miss', None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1]],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_board_with_hit_and_miss(), board_with_hit_and_miss)

    def test_generate_board_with_sunken_ship_returns_a_board_with_a_sunken_ship(self):
        board_with_a_sunken_ship = [
            ['Sunk', 'Sunk', 'Sunk', 'Sunk', 'Sunk', None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, None, None, None, None, None, self.board.all_ships[3]],
            [None, None, None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, self.board.all_ships[4], None, None, self.board.all_ships[2], None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1], self.board.all_ships[1]],
            [None, None, None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None, None, None],
        ]

        self.assertEqual(self.board_helper.generate_board_with_a_sunken_ship(), board_with_a_sunken_ship)
