示例#1
0
def test_has_card_should_return_false_when_user_has_other_card(person, turtle):
    cards = [Card(1, 'RED', 'MINUS')]
    player = Player(person, turtle, cards)

    actual = player.has_card(Card(0, 'RED', 'PLUS'))

    assert not actual
示例#2
0
def test_has_card_returns_true_when_has_card_in_two_cards(person, turtle):
    cards = [Card(0, 'RED', 'PLUS'), Card(1, 'RED', 'MINUS')]
    player = Player(person, turtle, cards)

    actual = player.has_card(cards[0])

    assert actual
示例#3
0
def test_add_card_should_add_card_for_player_with_one_card(person, turtle):
    player = Player(person, turtle, [Card(0, 'RED', 'PLUS')])
    card = Card(1, 'RED', 'MINUS')

    player.add_card(card)

    assert player.has_card(card)
def test_player_should_keep_getting_hands_until_can_move(people, turtles):
    # Initial state:
    # First player cards: 0,1,2,3,4
    # Second player cards: 5,6,7,8,9
    #
    # First player plays 0 and takes next card (10)
    # Second player can't make any move, so he should take another hand:
    # 11, 12, 13, 14, 15
    # He still can't make any move so he takes another hand:
    # 16, 17, 18, 19, 20

    cards = [Card(i, 'GREEN', 'PLUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE, 3 * HAND_SIZE + 1)
    ]
    cards += [
        Card(i, 'GREEN', 'PLUS')
        for i in range(3 * HAND_SIZE, 4 * HAND_SIZE + 1)
    ]

    game = Game(people, turtles, cards)
    player = game.players[0]

    game.play(player.person, Action(Card(0, 'GREEN', 'PLUS')))

    assert game.players[1].cards == cards[3 * HAND_SIZE + 1:4 * HAND_SIZE + 1]
示例#5
0
def test_new_card_should_be_the_first_of_player_cards(person, turtle):
    player = Player(person, turtle, [Card(0, 'RED', 'PLUS')])
    card = Card(1, 'RED', 'MINUS')

    player.add_card(card)

    assert player.cards[0] == card
def test_get_new_cards_should_return_cards():
    card1 = Card(0, 'RED', 'PLUS')
    card2 = Card(1, 'GREEN', 'MINUS')
    stacks = CardStacks([card1, card2])

    actual = stacks.get_new_cards(2)

    assert actual == [card1, card2]
def test_first_player_should_be_active_after_two_moves(game):
    first_player = game.players[0]
    second_player = game.players[1]

    game.play(first_player.person, Action(Card(0, 'RED', 'PLUS')))
    game.play(second_player.person, Action(Card(5, 'RED', 'PLUS')))

    assert game.active_player == first_player
示例#8
0
def test_new_card_should_add_card_for_player_with_two_cards(person, turtle):
    cards = [Card(0, 'RED', 'PLUS'), Card(1, 'GREEN', 'MINUS')]
    player = Player(person, turtle, cards)
    card = Card(2, 'RAINBOW', 'ARROW')

    player.add_card(card)

    assert player.cards[0] == card
示例#9
0
def test_player_shouldnt_have_card_after_its_removal(person, turtle):
    card = Card(0, 'RED', 'PLUS')
    cards = [card, Card(1, 'RED', 'MINUS')]
    player = Player(person, turtle, cards)

    player.remove_card(card)

    assert not player.has_card(card)
def test_first_player_should_get_another_hand_when_cant_move(people, turtles):
    cards = [Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'GREEN', 'PLUS') for i in range(HAND_SIZE, 3 * HAND_SIZE)
    ]

    game = Game(people, turtles, cards)

    assert game.players[0].cards == cards[2 * HAND_SIZE:3 * HAND_SIZE]
def test_first_player_should_be_active_after_three_moves(cards):
    people = [Person(0, 'Piotr'), Person(1, 'Marta'), Person(2, 'Ewa')]
    turtles = [Turtle('GREEN'), Turtle('RED'), Turtle('BLUE')]
    game = Game(people, turtles, cards)

    game.play(people[0], Action(Card(0, 'RED', 'PLUS')))
    game.play(people[1], Action(Card(5, 'RED', 'PLUS')))

    assert game.active_player == game.players[2]
def test_recent_card_should_not_change_when_all_cards_were_played():
    card1 = Card(0, 'RED', 'PLUS')
    card2 = Card(1, 'GREEN', 'MINUS')
    stacks = CardStacks([card1, card2])

    stacks.put(stacks.get_new())
    stacks.put(stacks.get_new())
    actual = stacks.get_recent()

    assert actual == card2
def test_raises_when_plays_arrow_arrow_incorrect_color(people, cards, turtles):
    player = people[0]
    all_cards = [Card(4 * HAND_SIZE, 'RAINBOW', 'ARROW_ARROW')] + cards
    game = Game(people, turtles, all_cards)

    for _ in range(2):
        active = game.active_player
        game.play(active.person, Action(active.cards[-1]))

    with pytest.raises(ValueError):
        game.play(player,
                  Action(Card(4 * HAND_SIZE, 'RAINBOW', 'ARROW_ARROW'), 'RED'))
    def __init__(self, card: Card, color=None):
        if color and not card.is_rainbow():
            raise ValueError('Action color can be set on actions concerning ' +
                             'rainbow cards only.' +
                             f'Card color: {card.color}')
        if not color and card.is_rainbow():
            raise ValueError(
                'Action color must be set on actions concerning ' +
                'rainbow cards')

        self.card = card
        self.color = color
def test_player_keeps_getting_another_hand_until_can_move(people, turtles):
    cards = [Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'RAINBOW', 'MINUS') for i in range(HAND_SIZE, 2 * HAND_SIZE)
    ]
    cards += [
        Card(i, 'GREEN', 'PLUS') for i in range(2 * HAND_SIZE, 4 * HAND_SIZE)
    ]

    game = Game(people, turtles, cards)

    assert game.players[0].cards == cards[2 * HAND_SIZE:3 * HAND_SIZE]
def test_get_new_should_return_reshuffled_cards_when_all_cards_were_played():
    random.seed(0)

    card1 = Card(0, 'RED', 'PLUS')
    card2 = Card(1, 'GREEN', 'MINUS')
    card3 = Card(2, 'RAINBOW', 'ARROW')
    stacks = CardStacks([card1, card2, card3])

    for _ in range(3):
        stacks.put(stacks.get_new())

    actual = stacks.get_new()

    assert actual == card2
示例#17
0
def test_has_card_should_return_true_when_user_has_given_card(person, turtle):
    card = Card(0, 'RED', 'PLUS')
    player = Player(person, turtle, [card])

    actual = player.has_card(card)

    assert actual
示例#18
0
def test_is_move_possible_returns_false_when_backward_card_turtle_on_start():
    card = Card(0, 'RED', 'MINUS')
    board = Board([Turtle('RED')])

    actual = board.is_move_with_card_possible(card)

    assert not actual
示例#19
0
def test_is_move_possible_returns_true_when_one_turtle_forward_card():
    board = Board([Turtle('RED')])
    card = Card(0, 'RAINBOW', 'PLUS')

    actual = board.is_move_with_card_possible(card)

    assert actual
def test_first_person_should_become_first_player():
    people = [Person(0, 'Piotr'), Person(1, 'Marta')]

    game = Game(people, [Turtle('GREEN'), Turtle('RED')],
                [Card(0, 'RED', 'PLUS') for _ in range(2 * HAND_SIZE)])

    assert game.active_player.person == people[0]
示例#21
0
def test_is_move_possible_should_return_true_when_card_is_forward():
    card = Card(0, 'RED', 'PLUS')
    board = Board([Turtle('RED')])

    actual = board.is_move_with_card_possible(card)

    assert actual
def test_get_new_should_return_first_card():
    card = Card(0, 'RED', 'PLUS')
    stacks = CardStacks([card])

    actual = stacks.get_new()

    assert actual == card
示例#23
0
def test_is_move_possible_returns_false_when_rainbow_card_no_turtles():
    board = Board([])
    card = Card(0, 'RAINBOW', 'MINUS')

    actual = board.is_move_with_card_possible(card)

    assert not actual
def test_card_played_by_player_should_be_recent_on_stack(cards, people, game):
    player = game.players[0]
    card = Card(0, 'RED', 'PLUS')

    game.play(player.person, Action(card))

    assert game.stacks.get_recent() == card
示例#25
0
def test_add_card_should_add_card_for_player_with_no_cards(person, turtle):
    card = Card(0, 'RED', 'PLUS')
    player = Player(person, turtle, [])

    player.add_card(card)

    assert player.has_card(card)
示例#26
0
def test_is_move_possible_should_return_false_when_there_are_no_turtles():
    board = Board([])
    card = Card(0, 'RED', 'PLUS')

    actual = board.is_move_with_card_possible(card)

    assert not actual
def test_player_should_not_have_played_card_after_move(cards, people, game):
    player = game.players[0]
    card = Card(0, 'RED', 'PLUS')

    game.play(player.person, Action(card))

    assert card not in player.cards
示例#28
0
def test_is_move_possible_returns_false_when_no_turtle_with_given_color():
    board = Board([Turtle('RED')])
    card = Card(0, 'GREEN', 'PLUS')

    actual = board.is_move_with_card_possible(card)

    assert not actual
示例#29
0
def test_player_should_have_no_cards_after_removing_only_card(person, turtle):
    card = Card(0, 'RED', 'PLUS')
    player = Player(person, turtle, [card])

    player.remove_card(card)

    assert not player.cards
def test_get_new_should_raise_exception_when_no_more_cards_available():
    card = Card(0, 'RED', 'PLUS')
    stacks = CardStacks([card])
    stacks.get_new()

    with pytest.raises(ValueError):
        stacks.get_new()