コード例 #1
0
    def test_compare_cards(self):
        self.game.trump_suit = Suit.DIAMONDS
        self.game.current_suit = Suit.HEARTS

        cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FOUR),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
            PlayingCard(suit=Suit.HEARTS, rank=Rank.QUEEN),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.JACK),
        ]

        cardA = PlayingCard(suit=Suit.SPADES, rank=Rank.ACE)

        self.assertTrue(self.game.compare_cards(cards[3], cardA, round_suit=self.game.current_suit) is None)
        for i in range(0, 3):
            card1 = cards[i]
            for j in range(i+1, 4):
                card2 = cards[j]
                result = self.game.compare_cards(card1=card1, card2=card2, round_suit=self.game.current_suit)
                self.assertTrue(result == card1)

        # test for card2
        for i in range(3, 0, -1):
            card1 = cards[i]
            for j in range(0, i):
                card2 = cards[j]
                result = self.game.compare_cards(card1=card1, card2=card2, round_suit=self.game.current_suit)
                self.assertTrue(result == card2)
コード例 #2
0
    def test_get_round_winner(self):
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.HEARTS,
                                                   rank=Rank.FOUR),
                                  round=1)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.DIAMONDS,
                                                   rank=Rank.TWO),
                                  round=1)
        self.game.current_round = 2
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.SPADES,
                                                   rank=Rank.QUEEN),
                                  round=2)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.CLUBS,
                                                   rank=Rank.JACK),
                                  round=2)

        result = self.game.get_round_winner(1)
        #because its trump suit
        expected = 2
        self.assertEqual(result, expected)
        self.assertEqual(len(self.game.get_plays_from_round(1)), 2)
        #player 1 winds because of round suit
        self.assertEqual(self.game.get_round_winner(2), 1)
コード例 #3
0
    def test_end_round(self):
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.HEARTS,
                                                   rank=Rank.FOUR),
                                  round=1)

        self.assertFalse(self.game.end_round())

        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.DIAMONDS,
                                                   rank=Rank.TWO),
                                  round=1)
        #falso pois ha jogadores a jogar
        self.assertFalse(self.game.end_round())
        self.game.players[1].pass_turn()
        self.game.players[2].pass_turn()
        self.assertEqual(self.game.players[1].number_of_cards_left(), 7)
        self.assertEqual(self.game.players[2].number_of_cards_left(), 7)
        self.assertEqual(self.game.card_deck.list_size(), 38)
        self.assertTrue(self.game.end_round())
        self.assertTrue(self.game.current_round == 2)

        for player in self.game.players.values():
            self.assertTrue(player.is_playing())
            self.assertEqual(player.number_of_cards_left(), 8)

        self.assertEqual(self.game.card_deck.list_size(), 36)
        self.assertTrue(self.game.current_suit == Suit.JOKER)
コード例 #4
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
 def test_sort_by_rank(self):
     expected_list = [PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT),
                      PlayingCard(suit=Suit.SPADES, rank=Rank.TEN), PlayingCard(
         suit=Suit.DIAMONDS, rank=Rank.JACK)]
     expected = CardList(expected_list)
     self.cardl.sort_by_rank()
     self.assertEqual(expected, self.cardl)
コード例 #5
0
    def test_get_round_points(self):
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.HEARTS,
                                                   rank=Rank.FOUR),
                                  round=1)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.DIAMONDS,
                                                   rank=Rank.TWO),
                                  round=1)

        #necessary to add extra cards
        self.game.current_round = 2
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.SPADES,
                                                   rank=Rank.QUEEN),
                                  round=2)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.CLUBS,
                                                   rank=Rank.JACK),
                                  round=2)

        result = self.game.get_round_points(1)
        expected = 0
        self.assertEqual(result, expected)

        result = self.game.get_round_points(2)
        expected = 5
        self.assertEqual(result, expected)
コード例 #6
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_contains_card(self):
        card1 = PlayingCard(suit=Suit.SPADES, rank=Rank.TEN)

        self.assertTrue(self.cardl.contains_card(card1))

        card1 = PlayingCard(suit=Suit.SPADES, rank=Rank.THREE)
        self.assertFalse(self.cardl.contains_card(card1))
コード例 #7
0
    def setUp(self):
        self.player = CardPlayer(player_id=1, card_hand=CardHand())

        self.card_list = [
            PlayingCard(suit=Suit.SPADES, rank=Rank.TEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT)
        ]
コード例 #8
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_deal_card(self):
        expected = PlayingCard(suit=Suit.SPADES, rank=Rank.TEN)
        result = self.cardl.deal_card()
        self.assertEqual(result, expected)

        list2 = [PlayingCard(
            suit=Suit.DIAMONDS, rank=Rank.JACK), PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT)]
        self.assertEqual(self.cardl.show_cards(), list2)
コード例 #9
0
ファイル: card_test.py プロジェクト: jreis22/card_games
    def test_eq(self):
        obj = PlayingCard(suit=Suit.SPADES, rank=Rank.SEVEN)
        expected_true = PlayingCard(suit=Suit.SPADES, rank=Rank.SEVEN)
        diff_suit = PlayingCard(suit=Suit.HEARTS, rank=Rank.SEVEN)
        diff_rank = PlayingCard(suit=Suit.SPADES, rank=Rank.KING)

        self.assertEqual(obj, expected_true)
        self.assertFalse(obj == diff_suit)
        self.assertFalse(obj == diff_rank)
コード例 #10
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_card_list_constructor(self):
        cardL = CardList()
        self.assertEqual(len(cardL.show_cards()), 0)

        cardL = CardList([PlayingCard(suit=Suit.SPADES, rank=Rank.FIVE)])
        expected_list = [PlayingCard(suit=Suit.SPADES, rank=Rank.FIVE)]

        self.assertEqual(len(cardL.show_cards()), len(expected_list))
        self.assertEqual(cardL.show_cards()[0], expected_list[0])
コード例 #11
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_sort_by_suit(self):
        expected_list = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT),
            PlayingCard(suit=Suit.SPADES, rank=Rank.TEN)
        ]
        expected = CardList(expected_list)

        self.cardl.add_card(PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO))
        self.cardl.sort_by_suit()
        self.assertTrue(expected == self.cardl)
コード例 #12
0
    def test_rank_comparison(self):
        cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FOUR),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.SEVEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.QUEEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.KING),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.ACE)
        ]

        card42 = PlayingCard(suit=Suit.CLUBS, rank=Rank.FOUR)

        # teste for card1
        self.assertTrue(
            self.game.rank_comparison(card1=cards[1], card2=card42) is None)
        for i in range(1, 7):
            card1 = cards[i]
            for j in range(0, i):
                card2 = cards[j]
                result = self.game.rank_comparison(card1, card2)
                self.assertTrue(result == card1)

        # test for card2
        for i in range(5, -1, -1):
            card1 = cards[i]
            for j in range(6, i, -1):
                card2 = cards[j]
                result = self.game.rank_comparison(card1, card2)
                self.assertTrue(result == card2)
コード例 #13
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_add_cards(self):
        card = PlayingCard(suit=Suit.SPADES, rank=Rank.QUEEN)
        card2 = PlayingCard(suit=Suit.HEARTS, rank=Rank.FOUR)
        card3 = PlayingCard(suit=Suit.CLUBS, rank=Rank.KING)

        cardl = CardList()
        cardl.add_cards([card, card2])
        expected = [card, card2]
        result = cardl.show_cards()
        self.assertEqual(result, expected)

        cardl = CardList([card3])
        cardl.add_cards([card, card2])
        result = cardl.show_cards()
        self.assertNotEqual(result, expected)
        expected = [card3, card, card2]
        self.assertEqual(result, expected)
コード例 #14
0
    def test_play_card(self):
        self.game.current_suit = Suit.JOKER
        card1 = PlayingCard(suit=Suit.DIAMONDS, rank=Rank.ACE)
        self.assertTrue(self.game.players[1].has_card(card1))
        self.assertEqual(len(self.game.played_cards), 0)
        self.assertEqual(self.game.current_suit, Suit.JOKER)
        self.game.play_card(1, card1)
        self.assertEqual(self.game.current_suit, Suit.DIAMONDS)
        self.assertFalse(self.game.players[1].has_card(card1))
        self.assertEqual(len(self.game.played_cards), 1)
        self.assertFalse(self.game.players[1].is_playing())
        try:
            self.game.play_card(2, card1)
        except Exception:
            pass
        else:
            self.fail("game.play_card player2 shouldnt own card")

        card2 = PlayingCard(suit=Suit.CLUBS, rank=Rank.TWO)

        try:
            self.game.play_card(2, card2)
        except Exception:
            pass
        else:
            self.fail(
                "game.play_card player2 shouldnt be able to play card of different suit"
            )

        card3 = PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO)
        self.assertEqual(self.game.player_order[0], 2)

        self.game.play_card(2, card3)

        self.assertEqual(len(self.game.played_cards), 2)
        self.assertEqual(self.game.current_round, 2)
        self.assertEqual(self.game.current_suit, Suit.JOKER)
        self.assertEqual(self.game.player_order[0], 1)
        self.assertEqual(self.game.player_order[1], 2)
        self.assertEqual(self.game.players[1].points, 11)
        self.assertEqual(self.game.players[2].points, 0)
コード例 #15
0
    def test_get_plays_from_round(self):
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.HEARTS,
                                                   rank=Rank.FOUR),
                                  round=1)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.DIAMONDS,
                                                   rank=Rank.TWO),
                                  round=1)
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.SPADES,
                                                   rank=Rank.QUEEN),
                                  round=2)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.CLUBS,
                                                   rank=Rank.JACK),
                                  round=2)

        result = self.game.get_plays_from_round(1)
        expected = [
            PlayedCard(player_key=1,
                       card=PlayingCard(suit=Suit.HEARTS, rank=Rank.FOUR),
                       round=1),
            PlayedCard(player_key=2,
                       card=PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
                       round=1),
        ]
        self.assertEqual(result, expected)
コード例 #16
0
ファイル: card_game_test.py プロジェクト: jreis22/card_games
    def test_get_player_cards(self):
        try:
            self.game.get_player_cards(0)
        except Exception:
            pass
        else:
            self.fail(
                "game.getplayercards out of index did not raise expected error"
            )

        self.assertEqual([], self.game.get_player_cards(1))
        expected = [
            PlayingCard(suit=Suit.CLUBS, rank=Rank.ACE),
            PlayingCard(suit=Suit.SPADES, rank=Rank.FIVE)
        ]
        self.game.players[1].set_card_hand(CardHand(expected))
        unexpected = [
            PlayingCard(suit=Suit.CLUBS, rank=Rank.ACE),
            PlayingCard(suit=Suit.SPADES, rank=Rank.ACE)
        ]
        self.assertEqual(self.game.get_player_cards(1), expected)
        self.assertNotEqual(self.game.get_player_cards(1), unexpected)
コード例 #17
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_eq(self):
        list2 = [PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK), PlayingCard(
            suit=Suit.SPADES, rank=Rank.TEN), PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT)]

        cardl2 = CardList(list2)

        self.assertFalse(self.cardl == cardl2)

        list2 = [PlayingCard(suit=Suit.SPADES, rank=Rank.TEN), PlayingCard(
            suit=Suit.DIAMONDS, rank=Rank.JACK), PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT)]
        cardl2 = CardList(list2)
        self.assertTrue(self.cardl == cardl2)
コード例 #18
0
ファイル: card_game_test.py プロジェクト: jreis22/card_games
    def test_add_played_card(self):
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.HEARTS,
                                                   rank=Rank.FOUR),
                                  round=1)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.DIAMONDS,
                                                   rank=Rank.TWO),
                                  round=1)
        self.game.add_played_card(player_key=1,
                                  card=PlayingCard(suit=Suit.SPADES,
                                                   rank=Rank.QUEEN),
                                  round=2)
        self.game.add_played_card(player_key=2,
                                  card=PlayingCard(suit=Suit.CLUBS,
                                                   rank=Rank.JACK),
                                  round=2)

        self.assertTrue(
            self.game.played_cards.__contains__(
                PlayedCard(player_key=1,
                           card=PlayingCard(suit=Suit.HEARTS, rank=Rank.FOUR),
                           round=1)))
        self.assertTrue(
            self.game.played_cards.__contains__(
                PlayedCard(player_key=1,
                           card=PlayingCard(suit=Suit.SPADES, rank=Rank.QUEEN),
                           round=2)))
        self.assertTrue(
            self.game.played_cards.__contains__(
                PlayedCard(player_key=2,
                           card=PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
                           round=1)))
        self.assertFalse(
            self.game.played_cards.__contains__(
                PlayedCard(player_key=1,
                           card=PlayingCard(suit=Suit.HEARTS, rank=Rank.FOUR),
                           round=2)))
コード例 #19
0
    def test_constructor(self):
        self.assertTrue(len(self.game.players) == 2)
        self.assertTrue(self.game.card_deck.deck_format == DeckFormat.FORTY)
        self.assertTrue(self.game.card_deck.list_size() == 26)

        expected_player_1_cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.ACE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.THREE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FIVE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.SEVEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.QUEEN),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.ACE),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.THREE)
        ]
        expected_player1_hand = CardHand(expected_player_1_cards)
        self.assertTrue(
            self.game.players[1].card_hand == expected_player1_hand)

        expected_player_1_cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FOUR),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.SIX),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.KING),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.TWO),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.FOUR)
        ]
        expected_player1_hand = CardHand(expected_player_1_cards)
        self.assertTrue(
            self.game.players[2].card_hand == expected_player1_hand)
コード例 #20
0
ファイル: card_test.py プロジェクト: jreis22/card_games
 def test_card_constructor(self):
     card = PlayingCard(suit=Suit.SPADES, rank=Rank.SEVEN)
      
     self.assertEqual(card.suit, Suit.SPADES)
コード例 #21
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
 def setUp(self):
     self.list1 = [PlayingCard(suit=Suit.SPADES, rank=Rank.TEN), PlayingCard(
         suit=Suit.DIAMONDS, rank=Rank.JACK), PlayingCard(suit=Suit.CLUBS, rank=Rank.EIGHT)]
     self.cardl = CardList(card_list=self.list1)
コード例 #22
0
    def test_constructor(self):
        self.assertEqual(len(self.game.players), 2)
        self.assertEqual(self.game.card_deck.deck_format, DeckFormat.FIFTY_TWO)
        self.assertEqual(self.game.card_deck.list_size(), 38)

        expected_player_1_cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.ACE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.THREE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FIVE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.SEVEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.NINE),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.JACK),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.KING)
        ]
        expected_player1_hand = CardHand(expected_player_1_cards)
        self.assertEqual(self.game.players[1].card_hand, expected_player1_hand)

        expected_player_1_cards = [
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TWO),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.FOUR),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.SIX),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.EIGHT),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.TEN),
            PlayingCard(suit=Suit.DIAMONDS, rank=Rank.QUEEN),
            PlayingCard(suit=Suit.CLUBS, rank=Rank.ACE)
        ]
        expected_player1_hand = CardHand(expected_player_1_cards)
        self.assertEqual(self.game.players[2].card_hand, expected_player1_hand)
コード例 #23
0
ファイル: card_list_test.py プロジェクト: jreis22/card_games
    def test_add_card(self):
        cardl = CardList()
        card = PlayingCard(suit=Suit.SPADES, rank=Rank.QUEEN)
        cardl.add_card(card)

        self.assertTrue(cardl.list_size() == 1)