コード例 #1
0
def test_words_from_board():
    '''Unit test for words from board'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)
    board = copy.deepcopy(board)

    board.add_letter(game_pieces.letter(rules, 'h', owner=1), (4, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=2), (5, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=1), (6, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=2), (7, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (8, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'n', owner=1), (3, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=1), (4, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (3, 8, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=1), (3, 10, 1))

    results = board.words_from_board()

    if results == {
        ((4, 5, 1), (8, 5, 1)): [(4, 5, 1), (5, 5, 1), (6, 5, 1), (7, 5, 1),
                                 (8, 5, 1)],
        ((3, 9, 1), (4, 9, 1)): [(3, 9, 1), (4, 9, 1)],
        ((3, 8, 1), (3, 10, 1)): [(3, 8, 1), (3, 9, 1), (3, 10, 1)]
    }:
        print("Test 1: SUCCESS")
    else:
        print("Test 1: FAILURE")
コード例 #2
0
def test_is_word_location_valid():
    '''Unit test for is word location valid'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)
    board = copy.deepcopy(board)

    board.add_letter(game_pieces.letter(rules, 'h', owner=1), (4, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=2), (5, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=1), (6, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=2), (7, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (8, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'n', owner=1), (3, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=1), (4, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (3, 8, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=1), (3, 10, 1))

    new_letter = game_pieces.letter(rules, 'h', owner=1)
    new_location = (4, 6, 1)

    new_letter_2 = game_pieces.letter(rules, 'j', owner=1)
    new_location_2 = (4, 5, 1)

    word_loc_dict = {new_location: new_letter, new_location_2: new_letter_2}

    board.is_word_location_valid(word_loc_dict)
コード例 #3
0
def test_get_dimensions():
    '''Unit test for getting board dimensions'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)

    if board.get_dimensions() == (10, 10, 1):
        print("Test 1: SUCCESS")
    else:
        print("Test 1: FAILURE")
コード例 #4
0
def test_create_two_letter_word_graph():
    '''Unit test for retrieving the word from the board'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)
    board = copy.deepcopy(board)

    board.add_letter(game_pieces.letter(rules, 'h', owner=1), (4, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=2), (5, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=1), (6, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'l', owner=2), (7, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (8, 5, 1))
    board.add_letter(game_pieces.letter(rules, 'n', owner=1), (3, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=1), (4, 9, 1))
    board.add_letter(game_pieces.letter(rules, 'o', owner=2), (3, 8, 1))
    board.add_letter(game_pieces.letter(rules, 'e', owner=1), (3, 10, 1))

    # board.pretty_print_board()
    test_results = board.create_two_letter_word_graph(delta=(1, 0, 0))

    if test_results == {
        (5, 5, 1): [(4, 5, 1), (6, 5, 1)],
        (4, 5, 1): [(5, 5, 1)],
        (6, 5, 1): [(5, 5, 1), (7, 5, 1)],
        (7, 5, 1): [(6, 5, 1), (8, 5, 1)],
        (8, 5, 1): [(7, 5, 1)],
        (4, 9, 1): [(3, 9, 1)],
        (3, 9, 1): [(4, 9, 1)]
    }:
        print("Test 1: SUCCESS")
    else:
        print("Test 1: FAILURE")

    test_results_y = board.create_two_letter_word_graph(delta=(0, 1, 0))

    if test_results_y == {
        (3, 8, 1): [(3, 9, 1)],
        (3, 10, 1): [(3, 9, 1)],
        (3, 9, 1): [(3, 8, 1), (3, 10, 1)]
    }:
        print("Test 2: SUCCESS")
    else:
        print("Test 2: FAILURE")
コード例 #5
0
def test_add_letter():
    '''Unit test for returning the 3D array, using lists'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)

    board = copy.deepcopy(board)
    # Test 1
    location_one = (1, 1, 1)
    letter_a = game_pieces.letter(rules, 'a')

    print(board.get_letter_positions())
    try:
        board.add_letter(letter_a, location_one)
    except:
        print("Test 1: FAILURE")
    else:
        print("Test 1: SUCCESS")
        print(board.get_letter_positions())

    # Test 2
    location_two = (1, 10, 1)
    letter_a = game_pieces.letter(rules, 'a')
    try:
        board.add_letter(letter_a, location_two)
    except:
        print("Test 2: FAILURE")
    else:
        print("Test 2: SUCCESS")
        print(board.get_letter_positions())

    # Test 2
    location_three = (1, 4, 1)
    letter_a = game_pieces.letter(rules, 'a')
    try:
        board.add_letter(letter_a, location_three)
    except:
        print("Test 3: FAILURE")
    else:
        print("Test 3: SUCCESS")
        print(board.get_letter_positions())
コード例 #6
0
def test_pretty_print_board():
    '''Unit test for pretty printing'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)
    board = copy.deepcopy(board)

    # Test 1
    location_one = (3, 1, 1)
    location_two = (3, 2, 1)
    location_three = (1, 3, 1)
    location_four = (10, 10, 1)

    letter_a = game_pieces.letter(rules, 'a', owner=1)
    letter_b = game_pieces.letter(rules, 'b', owner=2)
    letter_c = game_pieces.letter(rules, 'c', owner=1)
    letter_d = game_pieces.letter(rules, 'd', owner=2)

    board.add_letter(letter_a, location_one)
    board.add_letter(letter_b, location_two)
    board.add_letter(letter_c, location_three)
    board.add_letter(letter_d, location_four)

    board.pretty_print_board()
コード例 #7
0
def test_is_location_empty():
    '''Unit test for checking if a slot in the board is empty'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)

    this_board = copy.deepcopy(board)

    # Test 1
    location_one = (1, 1, 1)
    letter_a = game_pieces.letter(rules, 'a')
    this_board.add_letter(letter_a, location_one)

    if (this_board.is_location_empty(location_one) == False):
        print("Test 1: SUCCESS")
    else:
        print("Test 1: FAILURE")

    # Test 2
    location_one = (1, 2, 1)

    if (board.is_location_empty(location_one) == True):
        print("Test 2: SUCCESS")
    else:
        print("Test 2: FAILURE")
コード例 #8
0
def test_is_valid_location():
    '''Unit test for returning the 3D array, using lists'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)

    # Test 1
    location_one = (1, 1, 1)
    try:
        board.is_valid_location(location_one)
    except:
        print("Test 1: FAILURE")
    else:
        print("Test 1: SUCCESS")

    # Test 2
    location_two = [1, 1, 1]
    try:
        board.is_valid_location(location_two)
        print("Test 2: FAILURE")
    except:
        print("Test 2: SUCCESS")
    else:
        print("Test 2: FAILURE")

    # Test 3
    location_three = ('a', 'a', 'a')
    try:
        board.is_valid_location(location_three)
        print("Test 3: FAILURE")
    except:
        print("Test 3: SUCCESS")
    else:
        print("Test 3: FAILURE")

    # Test 4
    location_four = ('1', 1, 1)
    try:
        board.is_valid_location(location_four)
        print("Test 4: FAILURE")
    except:
        print("Test 4: SUCCESS")
    else:
        print("Test 4: FAILURE")

    location_five = (-1, 1, 1)
    try:
        board.is_valid_location(location_five)
        print("Test 5: FAILURE")
    except:
        print("Test 5: SUCCESS")
    else:
        print("Test 5: FAILURE")

    location_six = (11, 11, 2)
    try:
        board.is_valid_location(location_six)
        print("Test 6: FAILURE")
    except:
        print("Test 6: SUCCESS")
    else:
        print("Test 6: FAILURE")
コード例 #9
0
def test_board():
    '''Unit test for board init'''
    rules = game_pieces.gameRules()
    board = game_pieces.board(rules)
    print("Test 0: SUCCESS")