test_task7_10.py 1.78 KB
Newer Older
Adam Blank's avatar
Adam Blank committed
1
import pytest
2
3
from tests.helpers.test_helpers import *
from tests.helpers.output_place_ships import *
Adam Blank's avatar
Adam Blank committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

def gogo_place_ships():
    global ships_placed
    board_ships_p = task6.make_boolean_square_board(7)
    ships_placed = [[], []]
    battleship.place_ships(0, 0, board_ships_p, ships_placed, False)

def gogo_attack():
    global ships_placed
    ships_placed = [[[(0,0),(1,0),(2,0),(3,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)],[(0,3),(1,3)],[(0,4),(1,4)]],[]]
    battleship.attack(0, 1, board_opponent_ships_1, board_hits_1, ships_placed)

@pytest.mark.parametrize('inputs, expected_output, expected_ships_placed', [
    (["1,1", "N", "1,2", "N", "1,3", "N", "1,4", "N", "1,5", "N"], expected_output_1, [[[(0,0),(1,0),(2,0),(3,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)],[(0,3),(1,3)],[(0,4),(1,4)]],[]]),
    (["1,1", "Y", "2,1", "Y", "3,1", "Y", "4,1", "Y", "5,1", "Y"], expected_output_2, [[[(0,0),(0,1),(0,2),(0,3)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],[(3,0),(3,1)],[(4,0),(4,1)]],[]]),
    (["1,1", "Y", "2,1", "N", "5,7", "N", "7,5", "Y", "1,7", "N"], expected_output_3, [[[(0,0),(0,1),(0,2),(0,3)],[(1,0),(2,0),(3,0)],[(4,6),(5,6),(6,6)],[(6,4),(6,5)],[(0,6),(1,6)]],[]])    
])

def test_ships_placed(inputs, expected_output, expected_ships_placed):
Philippe des Boscs's avatar
Philippe des Boscs committed
23
24
25
26
27
28
29
    result = intercept(gogo_place_ships, inputs)
    if result != expected_output:
        pytest.fail(f"Calling place_ships and providing the following inputs:\n{inputs}\nthe resulting outputs are:\n{result}\nwhen we expect:\n{expected_output}.")
    elif ships_placed != expected_ships_placed:
        pytest.fail(f"Calling place_ships and providing the following inputs:\n{inputs}\nthe resulting ships_placed are:\nships_placed = {ships_placed}\nwhen we expect:\nships_placed = {expected_ships_placed}.")
    else:
        assert True, "Test passed!"