Exemplo n.º 1
0
 def test_peek_from_position(self):
     stack = CardStack(['a', 'b', 'c'])
     self.assertEqual(stack.peek_from_position(StackPosition.BOTTOM), ['c'])
     self.assertEqual(stack.peek_from_position(StackPosition.TOP), ['a'])
     self.assertEqual(stack.peek_from_position(StackPosition.TOP, 3),
                      ['a', 'b', 'c'])
     stack.draw(1)
     self.assertEqual(stack.peek_from_position(StackPosition.TOP), ['b'])
Exemplo n.º 2
0
 def test_peek(self):
     stack = CardStack(['a', 'b', 'c'])
     self.assertEqual(stack.peek(0), 'a')
     self.assertEqual(stack.peek(1), 'b')
     self.assertEqual(stack.size(), 3)
     stack.draw(1)
     self.assertEqual(stack.peek(0), 'b')
     self.assertEqual(stack.peek(1), 'c')
Exemplo n.º 3
0
 def test_extract(self):
     card_stack = CardStack(['a', 'b', 'c', 'd', 'b', 'e'])
     extracted = card_stack.extract(['b'])
     self.assertEqual(extracted, ['b'])
     self.assertEqual(card_stack.size(), 5)
     self.assertEqual(card_stack.distribution.count('b'), 1)
     cards = card_stack.draw(card_stack.size())
     self.assertEqual(cards, ['a', 'c', 'd', 'b', 'e'])
     card_stack.add(cards)
     extracted = card_stack.extract(['b'])
     self.assertEqual(card_stack.distribution.count('b'), 0)
Exemplo n.º 4
0
 def test_add(self):
     card_stack = CardStack([])
     card_stack.add('b')
     self.assertTrue(card_stack.has_card('b'))
     self.assertEqual(card_stack.distribution.count('b'), 1)
     cards = card_stack.draw(1)
     self.assertEqual(cards, ['b'])
     card_stack.add(['a', 'b', 'c'])
     cards = card_stack.draw(1)
     self.assertEqual(cards, ['a'])
     card_stack.add('a', StackPosition.BOTTOM)
     cards = card_stack.draw(1)
     self.assertEqual(cards, ['b'])
     cards = card_stack.draw(2)
     self.assertEqual(cards, ['c', 'a'])
Exemplo n.º 5
0
    def test_shuffle(self):
        self.card_stack.add('b')
        self.card_stack.add('c')
        self.card_stack.shuffle()

        self.assertEqual(self.card_stack.size(), 3)
        self.assertTrue(self.card_stack.has_card('a'))
        self.assertTrue(self.card_stack.has_card('b'))
        self.assertTrue(self.card_stack.has_card('c'))

        stack = CardStack(['a', 'b', 'c'])
        unshuffled_stack = stack.deepcopy()
        found_difference = False
        for _ in range(10):
            stack.shuffle()
            if stack._stack != unshuffled_stack._stack:
                found_difference = True
                break

        self.assertTrue(found_difference)
Exemplo n.º 6
0
 def setUp(self):
     self.card_stack = CardStack(['a'])
Exemplo n.º 7
0
 def test_add_to_bottom(self):
     card_stack = CardStack()
     card_stack.add(['a', 'b', 'c'])
     card_stack.add(['d', 'e', 'f'], position=StackPosition.BOTTOM)
     cards = card_stack.draw(5)
     self.assertEqual(cards, ['a', 'b', 'c', 'd', 'e'])