示例#1
0
def test_win_hzt_false():
    """Given a cell, check if there is not win from it in horizontal line
    """

    array = [[1, 2, 1, 1, 2, 2, 2], [1, 2, 1, 1, 1, 1,
                                     2], [0, 2, 2, 1, 2, 2, 2],
             [0, 1, 0, 1, 2, 0, 2], [0, 0, 0, 2, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]]
    board = Board()
    board.board = array
    test_pos_1 = [[2, 0], [2, 1], [2, 2], [1, 1], [1, 2], [1, 3]]
    test_pos_2 = [[2, 5], [2, 4], [2, 3], [1, 6], [1, 3], [1, 4]]
    test_pos_3 = [[-1, 0], [10, 3], [5, -4], [9, 0]]
    size_line = 3
    sym_p1 = 1
    sym_p2 = 2
    sym_p3 = 3

    # compare cases left to rigth
    assert (board.win_hzt(test_pos_1[0][0], test_pos_1[0][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[1][0], test_pos_1[1][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[2][0], test_pos_1[2][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[3][0], test_pos_1[3][1], True, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_1[4][0], test_pos_1[4][1], True, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_1[5][0], test_pos_1[5][1], True, sym_p2) <
            size_line)
    # compare cases rigth to left
    assert (board.win_hzt(test_pos_2[0][0], test_pos_2[0][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_2[1][0], test_pos_2[1][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_2[2][0], test_pos_2[2][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[3][0], test_pos_2[3][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[4][0], test_pos_2[4][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[5][0], test_pos_2[5][1], False, sym_p2) <
            size_line)
    # compare with symbol not valid
    assert (board.win_hzt(test_pos_1[4][0], test_pos_1[4][1], True, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_1[5][0], test_pos_1[5][1], True, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_2[4][0], test_pos_2[4][1], False, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_2[5][0], test_pos_2[5][1], False, sym_p3) <
            size_line)
    # compare with cell (row, col) not valid
    assert (board.win_hzt(test_pos_3[0][0], test_pos_1[0][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_3[1][0], test_pos_1[1][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_3[2][0], test_pos_2[2][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_3[3][0], test_pos_2[3][1], False, sym_p2) <
            size_line)
示例#2
0
def test_win_hzt_true():
    """Given a cell, check if there is win from it in horizontal line
    """

    array = [[1, 2, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1,
                                     2], [0, 2, 2, 2, 2, 2, 2],
             [0, 1, 0, 1, 2, 0, 2], [0, 0, 0, 2, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]]
    board = Board()
    board.board = array
    test_pos_1 = [[1, 0], [1, 1], [1, 2], [2, 1], [2, 2], [2, 3]]
    test_pos_2 = [[1, 5], [1, 4], [1, 3], [2, 6], [2, 5], [2, 4]]
    size_line = 3
    sym_p1 = 1
    sym_p2 = 2

    # compare cases left to rigth
    assert (board.win_hzt(test_pos_1[0][0], test_pos_1[0][1], True, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_1[1][0], test_pos_1[1][1], True, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_1[2][0], test_pos_1[2][1], True, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_1[3][0], test_pos_1[3][1], True, sym_p2) >=
            size_line)
    assert (board.win_hzt(test_pos_1[4][0], test_pos_1[4][1], True, sym_p2) >=
            size_line)
    assert (board.win_hzt(test_pos_1[5][0], test_pos_1[5][1], True, sym_p2) >=
            size_line)
    # compare cases rigth to lef
    assert (board.win_hzt(test_pos_2[0][0], test_pos_2[0][1], False, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_2[1][0], test_pos_2[1][1], False, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_2[2][0], test_pos_2[2][1], False, sym_p1) >=
            size_line)
    assert (board.win_hzt(test_pos_2[3][0], test_pos_2[3][1], False, sym_p2) >=
            size_line)
    assert (board.win_hzt(test_pos_2[4][0], test_pos_2[4][1], False, sym_p2) >=
            size_line)
    assert (board.win_hzt(test_pos_2[5][0], test_pos_2[5][1], False, sym_p2) >=
            size_line)