Exemple #1
0
def test_place_a_ship_horizontally():
    board = Board(board_width, board_height)
    ship = Ship(3, 'horizontal')
    board.place_ship(ship, 2, 2)
    board.print()
    assert board.squares[0] == [False, False, False, False, False, False]
    assert board.squares[1] == [False, ship, ship, ship, False, False]
    assert board.squares[2] == [False, False, False, False, False, False]
Exemple #2
0
def test_sink_square():
    board = Board(board_width, board_height)
    ship = Ship(3, 'horizontal')
    board.place_ship(ship, 2, 2)
    board.sink_square(2, 2)
    assert board.squares[1] == [False, 'Sunk', ship, ship, False, False]
Exemple #3
0
def test_ships_are_constrained_to_the_board():
    board = Board(board_width, board_height)
    horizontal_ship = Ship(3, 'horizontal')
    vertical_ship = Ship(3, 'vertical')
    assert board.place_ship(horizontal_ship, 5, 2) == False
    assert board.place_ship(vertical_ship, 5, 9) == False
Exemple #4
0
def test_reset_board():
    board = Board(board_width, board_height)
    ship = Ship(3, 'horizontal')
    board.place_ship(ship, 2, 2)
    board.reset()
    assert board.is_square_full(2, 2) == False
Exemple #5
0
def test_cannot_place_a_ship_on_another_ship():
    board = Board(board_width, board_height)
    ship = Ship(3, 'horizontal')
    board.place_ship(ship, 2, 2)
    assert board.place_ship(ship, 2, 2) == False