diff --git a/no_solid_design/card.py b/no_solid_design/card.py index 14f73a4..8049851 100644 --- a/no_solid_design/card.py +++ b/no_solid_design/card.py @@ -25,6 +25,45 @@ def shuffle_burn(self, n=100): def deal(self): return self.shoe.pop() +__test__ = { + 'Card': ''' + >>> random.seed(1) # Deterministic Sequence + >>> deck = Card() + >>> c1 = deck.deal() + >>> c1 + (3, '♠') + >>> hand = [deck.deal() for _ in range(5)] + >>> hand + [(10, '♠'), (13, '♠'), (2, '♠'), (5, '♠'), (2, '♣')] + + >>> hand2 = [(11, '♠'), (1, '♠')] + >>> sum(deck.points(c)[0] for c in hand2) + 11 + >>> sum(deck.points(c)[0] for c in hand2) + 21 + ''', + + 'Shoe': ''' + >>> deck = Shoe(6) + >>> random.seed(1) # Deterministic Sequence + >>> deck.shuffle_burn(100) + >>> hand = [deck.deal() for _ in range(5)] + >>> hand + [(12, '♣'), (10, '♡'), (7, '♢'), (9, '♢'), (4, '♣')] + >>> dealing= True + >>> while dealing: + ... try: + ... hand = [deck.deal() for _ in range(5)] + ... eq = any( hand[c1] == hand[c2] + ... for c1 in range(len(hand)) for c2 in range(len(hand)) if c1 != c2) + ... if eq: print(hand) + ... except IndexError: + ... dealing= False + ... + [(6, '♢'), (5, '♡'), (6, '♢'), (13, '♡'), (9, '♡')] + [(3, '♢'), (9, '♠'), (6, '♡'), (2, '♢'), (9, '♠')] + ''', +} if __name__ == "__main__": import doctest