示例#1
0
def make_test_board():
    card_list = get_cards()
    cards = create_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    indexes = cards_indexes(columns)
    board = make_empty_board(rows, columns)
    make_game_board(board, indexes, cards)
    return board
 def test_click_same_pair(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(count_showed_cards(game), 1)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(count_showed_cards(game), 1)
示例#3
0
def test_click_same_pair():
    """test sprawdza ile kart będzie odkrytych jeżeli gracz spróbuje odsłonić tą samą kartę"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
示例#4
0
def test_click_good_pair():
    """test sprawdza czy będą widoczne dwie poprawnie odsłonięte karty"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert count_showed_cards(game) == 2
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    assert count_showed_cards(game) == 3
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert count_showed_cards(game) == 4
 def test_check_attempts_amount(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     self.assertEqual(game['attempts'], 2)
示例#6
0
def test_check_attempts_amount():
    """test sprawdza czy poprawnie nalicza się ilość prób"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    assert game['attempts'] == 2
 def test_if_game_is_finished(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=0, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=0)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     on_card_clicked(game, board, columns, rows, row=2, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     on_card_clicked(game, board, columns, rows, row=2, col=3)
     self.assertTrue(all_card_showed(game, columns, rows), True)
 def test_which_card_showed(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     self.assertEqual(board[1][3], {'value': 1, 'showed': True})
     self.assertEqual(board[0][3], {'value': 3, 'showed': True})
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     self.assertEqual(board[1][3], {'value': 1, 'showed': False})
     self.assertEqual(board[0][3], {'value': 3, 'showed': False})
     self.assertEqual(board[0][0], {'value': 0, 'showed': True})
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     self.assertEqual(board[0][0], {'value': 0, 'showed': True})
     self.assertEqual(board[1][2], {'value': 0, 'showed': True})
     self.assertEqual(board[2][2], {'value': 4, 'showed': True})
示例#9
0
def test_if_game_is_finished():
    """test sprawdza czy po odklikaniu wszystkich par, wszystkie karty są odsłonięte"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=0, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=0)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    on_card_clicked(game, board, columns, rows, row=2, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert all_card_showed(game, columns, rows) == True
示例#10
0
def test_which_card_showed():
    """test sprawdza czy następuje zakrywanie/odkrywanie wybranych kart"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    assert board[1][3] == {'value': 1, 'showed': True}
    assert board[0][3] == {'value': 3, 'showed': True}
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    assert board[1][3] == {'value': 1, 'showed': False}
    assert board[0][3] == {'value': 3, 'showed': False}
    assert board[0][0] == {'value': 0, 'showed': True}
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    assert board[0][0] == {'value': 0, 'showed': True}
    assert board[1][2] == {'value': 0, 'showed': True}
    assert board[2][2] == {'value': 4, 'showed': True}
示例#11
0
 def test_time_measure(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     time.sleep(2)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=0, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=0)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     on_card_clicked(game, board, columns, rows, row=2, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(game['finish_at'], None)
     on_card_clicked(game, board, columns, rows, row=2, col=3)
     self.assertTrue(game['started_at'] < game['finish_at'], True)
示例#12
0
def test_time_measure():
    """test sprawdza czy dobrze jest liczony czas od startu do zakończenia gry"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    time.sleep(2)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=0, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=0)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    on_card_clicked(game, board, columns, rows, row=2, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert game['finish_at'] == None
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert game['started_at'] < game['finish_at']
示例#13
0
def test_calc_board_rows():
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    assert (calc_board_columns(unique_divisors) * calc_board_rows(unique_divisors) == len(card_list)*2)
示例#14
0
from random import shuffle
from datetime import datetime
import helpers as helper

card_list = helper.get_cards()
all_divisors = helper.calc_all_divisors(card_list)
unique_divisors = helper.calc_pair_divisors(all_divisors)


def build_row(columns):
    list_a = []
    for number in range(columns):
        list_a.append(None)
    return list_a


def build_rows(rows, columns):
    rows_a = []
    for i in range(rows):
        row = build_row(columns)
        rows_a.append(row)
    return rows_a


def make_empty_board(rows, columns):
    """Buduje pustą plansze do gry, pola wypełnione 'None' """
    return build_rows(rows, columns)


def cards_indexes(columns):
    """zwraca listę ze wszystkimi indeksami kart"""
示例#15
0
 def test_calc_board_rows(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     self.assertEqual(calc_board_columns(unique_divisors) * calc_board_rows(unique_divisors), len(card_list) * 2)