Skip to content

Commit

Permalink
added testing
Browse files Browse the repository at this point in the history
  • Loading branch information
BhanuKiranChaluvadi committed Apr 29, 2020
1 parent 6f9ffe6 commit 9741b5e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions no_solid_design/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9741b5e

Please sign in to comment.