示例#1
0
    def test_count(self):
        hand1 = self.HAND1
        assert hand1.count(hand1[1]) == 1
        assert hand1.count(hand1[1].suit) == 1
        assert hand1.count(hand1[1].value) == 2

        assert hand1.count(hand1[2]) == 1
        assert hand1.count(hand1[2].suit) == 2
        assert hand1.count(hand1[2].value) == 1

        with Hand.default_comparison(deck.HandComparison.Suits):
            assert hand1.count(hand1[2]) == 2
        with Hand.default_comparison(deck.HandComparison.Values):
            assert hand1.count(hand1[2]) == 1
示例#2
0
    def test_contains(self):
        hand1 = self.HAND1
        assert hand1.index(hand1[1]) == 1
        assert hand1.index(hand1[1].suit) == 1
        assert hand1.index(hand1[1].value) == 1

        assert hand1.index(hand1[2]) == 2
        assert hand1.index(hand1[2].suit) == 0
        assert hand1.index(hand1[2].suit, start=1) == 2
        assert hand1.index(hand1[2].value) == 2

        with Hand.default_comparison(deck.HandComparison.Suits):
            assert hand1.index(hand1[2]) == 0
        with Hand.default_comparison(deck.HandComparison.Values):
            assert hand1.index(hand1[2]) == 2
示例#3
0
 def test_union_suit(self):
     hand1, hand2 = self.HAND1, self.HAND2
     hand3 = Hand([Card("♥", 10), Card("♥", 11)])
     expect_hand3 = [*hand1, *hand3]
     hand4 = Hand([Card(joker=True)])
     with Hand.default_comparison(deck.HandComparison.Suits):
         # Self-union should be the complete hand
         assert list(hand1.union(hand1)) == list(hand1)
         assert list(hand2.union(hand2)) == list(hand2)
         # All suits exist between hand1 and hand2 and so we get all of them
         assert list(hand1.union(hand2)) == list(hand1)
         # Nothing is added
         assert list(hand1.union(hand3)) == list(hand1)
         # Nothing is added
         assert list(hand1.union(hand4)) == list(hand1)
         # Check bitwise operator
         assert list(hand1 | hand3) == list(hand1)
         # Check in-place operator
         h1 = Hand(c for c in hand1 if c.suit != deck.Suit.Hearts)
         h1 |= hand1
         assert set(h1) == set(hand1)
示例#4
0
 def test_union_value(self):
     hand1, hand2 = self.HAND1, self.HAND2
     hand3 = Hand([Card("♥", 10), Card("♥", 11)])
     expect_hand3 = [*hand1, hand3[0]]
     hand4 = Hand([Card(joker=True)])
     with Hand.default_comparison(deck.HandComparison.Values):
         # Self-union should be the complete list
         assert list(hand1.union(hand1)) == list(hand1)
         assert list(hand2.union(hand2)) == list(hand2)
         # All values exist between hand1 and hand2 and so we get all of them
         assert list(hand1.union(hand2)) == list(hand1)
         # Only Tens are added
         assert list(hand1.union(hand3)) == expect_hand3
         # Nothing is added
         assert list(hand1.union(hand4)) == list(hand1)
         # Check bitwise operator
         assert list(hand1 | hand3) == expect_hand3
         # Check in-place operator
         h1 = Hand(c for c in hand1 if c.value == 3)
         h1 |= hand1
         assert set(h1) == set(hand1)
示例#5
0
 def test_intersect_suit(self):
     hand1, hand2 = self.HAND1, self.HAND2
     hand3 = Hand([Card("♥", 11)])
     expect_hand3 = {Card("♥", 2), Card("♥", 3)}
     hand4 = Hand([Card(joker=True)])
     with Hand.default_comparison(deck.HandComparison.Suits):
         # Self-intersect should be the complete set
         assert set(hand1.intersect(hand1)) == set(hand1)
         assert set(hand2.intersect(hand2)) == set(hand2)
         # All suits exist between hand1 and hand2 and so we get all of them
         assert set(hand1.intersect(hand2)) == set(hand1)
         # Only Hearts are retained
         assert set(hand1.intersect(hand3)) == expect_hand3
         # Only Jokers are retained
         assert set(hand1.intersect(hand4)) == set(hand4)
         # Check bitwise operator
         assert set(hand1 & hand3) == expect_hand3
         # Check in-place operator
         h1 = Hand(hand1)
         h1 &= hand3
         assert set(h1) == expect_hand3
         assert len(hand1) != len(h1)