def test_invalid_rank_throws_valueException():
    with assert_raises(ValueError):
        PlayingCard(10, 's')
    with assert_raises(ValueError):
        PlayingCard(1, 's')
    with assert_raises(ValueError):
        PlayingCard('z', 's')
Exemple #2
0
def test_draw_card():
    cards = [PlayingCard('A', 's'), PlayingCard(0, 'h')]

    result = draw_card(cards[0])
    assert_equal('\033[30;47m A s \033[0m', result)

    result = draw_card(cards[1])
    assert_equal('\033[31;47m 0 h \033[0m', result)
Exemple #3
0
def test_get_count_facing_down():
	cards = [PlayingCard('A', 's'), PlayingCard(3, 's'), PlayingCard(2, 'h')]
	cards[2].flip()
	pile = CardPile()

	for card in cards:
		pile.add_card(card)

	assert_equal(2, pile.count_facing_down())
Exemple #4
0
def test_can_take_returns_false_if_card_is_not_next_rank():
	pile = SuitPile()
	first_card = PlayingCard('A', 's')
	pile.add_card(first_card)
	second_card = PlayingCard(3, 's')

	result = pile.can_take(second_card)

	assert_false(result)
Exemple #5
0
def test_can_take_returns_true_if_card_is_same_suit_and_next_rank():
	pile = SuitPile()
	first_card = PlayingCard('A', 's')
	pile.add_card(first_card)
	second_card = PlayingCard(2, 's')

	result = pile.can_take(second_card)

	assert_true(result)
def test_push_and_get_card():
	card = PlayingCard('A', 's')
	card.flip()
	pile = TablePile()
	pile.add_card(card)

	assert_equal(1, len(pile))
	assert_equal(card.rank, pile[0].rank)
	assert_equal(card.suit, pile[0].suit)
Exemple #7
0
def test_draw_non_table_pile_with_no_face_up_cards():
    pile = CardPile()
    cards = [PlayingCard('A', 's'), PlayingCard(2, 's'), PlayingCard(3, 's')]
    for card in cards:
        pile.append(card)

    result = draw_non_table_pile(pile)

    assert_equal('3---', result)
Exemple #8
0
def test_draw_non_table_pile_with_ace_up_card():
    pile = CardPile()
    cards = [PlayingCard('A', 's'), PlayingCard(2, 's'), PlayingCard(3, 's')]
    for card in cards:
        card.flip()
        pile.append(card)

    result = draw_non_table_pile(pile)

    assert_equal('\033[30;47m 3 s \033[0m', result)
Exemple #9
0
def test_draw_on_empty_pile_flips_discard_pile_to_draw_pile():
	game = Game(no_shuffle=True)
	card = PlayingCard('A', 's')
	card.flip()
	game.piles[1].add_card(card)

	game.draw()

	assert_equal(1, len(game.piles[0]))
	assert_equal(0, len(game.piles[1]))
def test_color():
    spade = PlayingCard(2, 's')
    heart = PlayingCard(2, 'h')
    club = PlayingCard(2, 'c')
    diamond = PlayingCard(2, 'd')

    assert_equal('Black', spade.color)
    assert_equal('Black', club.color)
    assert_equal('Red', heart.color)
    assert_equal('Red', diamond.color)
def test_pop_flips_card_if_last_facing_up():
	cards = [PlayingCard('A', 's'), PlayingCard(3, 's'), PlayingCard(2, 'h')]
	cards[2].flip()
	pile = TablePile()

	for card in cards:
		pile.add_card(card)

	pile.pop()

	assert_true(pile[-1].is_face_up())
Exemple #12
0
def test_clear():
	cards = [PlayingCard('A', 's'), PlayingCard(3, 's'), PlayingCard(2, 'h')]
	cards[2].flip()
	piles = [CardPile(), CardPile(), CardPile()]

	for pile in piles:
		for card in cards:
			pile.add_card(card)

	for pile in piles:
		pile.clear()
		assert_equal(0, len(pile))
def test_can_take_returns_true_if_card_is_next_lower_rank_and_opposite_color():
	pile = TablePile()
	pile.add_card(PlayingCard('K', 's'))
	pile[-1].flip()

	queen_hearts = PlayingCard('Q', 'h')
	assert_equal(pile.top().rank_number - 1, queen_hearts.rank_number)
	assert_true(pile.top().rank_number - 1 == queen_hearts.rank_number and 
		pile.top().color != queen_hearts.color)
	assert_false(pile.is_empty() and queen_hearts.rank_number == 12)

	assert_true(pile.can_take(queen_hearts))
	assert_true(pile.can_take(PlayingCard('Q', 'd')))
def test_flip_toggles_card_facing_direction():
    card = PlayingCard(2, 's')

    card.flip()
    assert_true(card.is_face_up())

    card.flip()
    assert_false(card.is_face_up())
def test_draw_table_pile_row():
	card = PlayingCard('A', 's')
	card1 = PlayingCard(2, 's')
	card1.flip()
	pile0 = TablePile()
	pile1 = TablePile()
	pile1.append(card)
	pile2 = TablePile()
	pile2.append(card)
	pile2.append(card1)
	piles = [pile0, pile1, pile2, pile0, pile1, pile2, pile0]

	result = draw_table_pile_row(piles, 0)

	assert_equal('            \033[30;47m 2 s \033[0m             \033[30;47m 2 s \033[0m      ', result)
Exemple #16
0
def test_draw_table_pile_summary_row():
    card = PlayingCard('A', 's')
    card1 = PlayingCard(2, 's')
    card1.flip()
    pile0 = TablePile()
    pile1 = TablePile()
    pile1.append(card)
    pile2 = TablePile()
    pile2.append(card)
    pile2.append(card1)
    piles = [pile0, pile1, pile2, pile0, pile1, pile2, pile0]

    result = draw_table_pile_summary_row(piles)

    assert_equal('0---- 1---- 1---- 0---- 1---- 1---- 0----', result)
def test_draw_table_pile_summary_row():
	card = PlayingCard('A', 's')
	card1 = PlayingCard(2, 's')
	card1.flip()
	pile0 = TablePile()
	pile1 = TablePile()
	pile1.append(card)
	pile2 = TablePile()
	pile2.append(card)
	pile2.append(card1)
	piles = [pile0, pile1, pile2, pile0, pile1, pile2, pile0]

	result = draw_table_pile_summary_row(piles)

	assert_equal('0---- 1---- 1---- 0---- 1---- 1---- 0----', result)
Exemple #18
0
def test_can_take_returns_true_if_pile_is_empty_and_card_is_an_ace():
	pile = SuitPile()
	card = PlayingCard('A', 's')

	result = pile.can_take(card)

	assert_true(result)
def test_valid_ranks():
    valid_ranks = [
        'A', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K'
    ]
    for rank in valid_ranks:
        card = PlayingCard(rank, 's')
        assert_equals(card.rank, rank)
Exemple #20
0
def test_is_empty():
	pile = CardPile()

	assert_true(pile.is_empty())

	pile.add_card(PlayingCard('A', 's'))
	assert_false(pile.is_empty())
Exemple #21
0
def test_can_take_returns_false():
	pile = CardPile()
	card = PlayingCard('A', 's')

	result = pile.can_take(card)

	assert_false(result)
Exemple #22
0
def test_can_take_false_if_pile_is_empty_and_card_is_not_an_ace():
	pile = SuitPile()
	card = PlayingCard(2, 's')

	result = pile.can_take(card)

	assert_false(result)
Exemple #23
0
def test_draw_table_pile_row():
    card = PlayingCard('A', 's')
    card1 = PlayingCard(2, 's')
    card1.flip()
    pile0 = TablePile()
    pile1 = TablePile()
    pile1.append(card)
    pile2 = TablePile()
    pile2.append(card)
    pile2.append(card1)
    piles = [pile0, pile1, pile2, pile0, pile1, pile2, pile0]

    result = draw_table_pile_row(piles, 0)

    assert_equal(
        '            \033[30;47m 2 s \033[0m             \033[30;47m 2 s \033[0m      ',
        result)
def test_get_face_up_card():
	cards = [PlayingCard('A', 's'), PlayingCard(3, 's'), PlayingCard(2, 'h')]
	cards[1].flip()
	cards[2].flip()
	pile = TablePile()

	for card in cards:
		pile.add_card(card)

	for i in range(0, 1):
		result_card = pile.get_face_up_card(i)
		assert_true(result_card != None)
		assert_true(result_card.is_face_up())
		assert_equal(cards[i+1].rank, result_card.rank)
		assert_equal(cards[i+1].suit, result_card.suit)

	result_card = pile.get_face_up_card(2)
	assert_true(result_card == None)
def test_rank_index():
    ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K']
    cards = []
    for rank in ranks:
        cards.append(PlayingCard(rank, 's'))

    for i, rank in enumerate(ranks):
        card = cards[i]
        assert_equal(i, card.rank_number)
def test_add_card():
    pile = DiscardPile()
    card = PlayingCard('A', 's')

    pile.add_card(card)

    assert_equal(1, len(pile))
    assert_equal(card.suit, pile.top().suit)
    assert_equal(card.rank, pile.top().rank)
    assert_true(pile.top().is_face_up())
Exemple #27
0
def test_pop_returns_last_card_and_removes_it():
	card = PlayingCard('A', 's')
	pile = CardPile()
	pile.add_card(card)

	result = pile.pop()

	assert_equal(0, len(pile))
	assert_equal(card.suit, result.suit)
	assert_equal(card.rank, result.rank)
Exemple #28
0
def test_top_returns_last_card_without_removing():
	card = PlayingCard('A', 's')
	pile = CardPile()
	pile.add_card(card)

	result = pile.top()

	assert_equal(1, len(pile))
	assert_equal(card.suit, result.suit)
	assert_equal(card.rank, result.rank)
def test_valid_suits():
    valid_suits = ['s', 'h', 'h', 'h']
    for suit in valid_suits:
        card = PlayingCard(2, suit)
        assert_equals(card.suit, suit)
def test_can_take_card_always_returns_true():
    pile = DiscardPile()

    assert_true(pile.can_take(PlayingCard('A', 's')))
def test_invalid_suit_throws_valueExcepiton():
    with assert_raises(ValueError):
        PlayingCard(2, 'z')
    with assert_raises(ValueError):
        PlayingCard(2, 1)
def test_suit_stored_as_lowercase():
    suit = 'S'
    card = PlayingCard(2, suit)
    assert_equals(card.suit, suit.lower())