def testCombinationOfTwoAndJokers(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('2-1 2-2 0-0'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('2-1 2-2 0-0 2-5 0-0'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('2-1 2-2 0-0 2-5 1-0'))
   self.assertFalse(deck.isValidCombination())
 def testSameValueAndDifferentSuits(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 1-2 1-3'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('2-1 2-2 2-3'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('13-2 13-2 13-3'))
   self.assertTrue(deck.isValidCombination())
 def testAllCombinationsOfTwoCards(self):
   stack = cards.strToStackOfCards('3-1 4-1')
   combinations = stack.allCombinationsOfCards()
   self.assertEquals(3, len(combinations))
   self.assertTrue(cards.strToStackOfCards('3-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('4-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('3-1 4-1') in combinations)
 def testInvalidCombinationWithQKAS(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('10-1 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('11-2 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
 def testPopCardsAcceptCardOrStackOrList(self): 
   deck = cards.StackOfCards()
   deck.pushAll(cards.Card(1, 1))
   deck.pushAll(cards.Card(2, 1))
   deck.pushAll(cards.Card(3, 1))
   self.assertEquals(cards.strToStackOfCards('1-1'), deck.popCards(cards.Card(1, 1)))
   self.assertEquals(cards.strToStackOfCards('2-1'), deck.popCards([cards.Card(2, 1)]))
   self.assertEquals(cards.strToStackOfCards('3-1'), deck.popCards(deck))
 def testRealCanastra(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1 2-1'))
   self.assertFalse(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('3-1 4-1 5-2 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1 2-1 3-1'))
   self.assertFalse(deck.isValidCombination())
 def testCombinationWithJoker(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('2-2 10-1 12-1 13-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('0-0 10-1 12-1 13-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('0-0 10-1 12-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('0-0 10-1 11-1'))
   self.assertTrue(deck.isValidCombination())
 def testAllCardsInSequenceWithSameSuitWithJokers(self):
   suitdeck = cards.strToStackOfCards('1-1 2-1 4-1')
   deck = cards.strToStackOfCards('1-2 2-1 4-1')
   self.assertFalse(suitdeck.allCardsInSequenceWithSameSuitWithJokers(0))
   self.assertFalse(deck.allCardsInSequenceWithSameSuitWithJokers(1))
   self.assertFalse(deck.allCardsInSequenceWithSameSuitWithJokers(2))
   self.assertTrue(suitdeck.allCardsInSequenceWithSameSuitWithJokers(1))
   self.assertTrue(suitdeck.allCardsInSequenceWithSameSuitWithJokers(2))
   
   suitdeck = cards.strToStackOfCards('1-1 2-1 5-1')
   deck = cards.strToStackOfCards('1-2 2-1 5-1')
   self.assertFalse(suitdeck.allCardsInSequenceWithSameSuitWithJokers(1))
   self.assertFalse(deck.allCardsInSequenceWithSameSuitWithJokers(2))
   self.assertTrue(suitdeck.allCardsInSequenceWithSameSuitWithJokers(2))
   
   suitdeck = cards.strToStackOfCards('1-1 2-1 4-1 6-1')
   deck = cards.strToStackOfCards('1-2 2-1 4-1 6-1')
   self.assertFalse(suitdeck.allCardsInSequenceWithSameSuitWithJokers(1))
   self.assertFalse(deck.allCardsInSequenceWithSameSuitWithJokers(2))
   self.assertTrue(suitdeck.allCardsInSequenceWithSameSuitWithJokers(2))
   
   suitdeck = cards.strToStackOfCards('1-1 2-1 5-1 7-1')
   deck = cards.strToStackOfCards('1-2 2-1 5-1 7-1')
   self.assertFalse(suitdeck.allCardsInSequenceWithSameSuitWithJokers(1))
   self.assertFalse(suitdeck.allCardsInSequenceWithSameSuitWithJokers(2))
   self.assertFalse(deck.allCardsInSequenceWithSameSuitWithJokers(3))
   self.assertTrue(suitdeck.allCardsInSequenceWithSameSuitWithJokers(3))
 def testConstainsAllCards(self):
   deck = cards.strToStackOfCards('1-1 2-2 3-3')
   deck1 = cards.strToStackOfCards('1-1 2-2 3-3')
   deck2 = cards.strToStackOfCards('1-1 2-2')
   deck3 = cards.strToStackOfCards('1-1 4-4')
   self.assertTrue(deck.containsAllCards(deck))
   self.assertTrue(deck.containsAllCards(deck1))
   self.assertTrue(deck.containsAllCards(deck2))
   self.assertFalse(deck.containsAllCards(deck3))
   
   self.assertTrue(deck.containsAllCards(deck.cards))
   self.assertTrue(deck.containsAllCards(deck1.cards))
   self.assertTrue(deck.containsAllCards(deck2.cards))
   self.assertFalse(deck.containsAllCards(deck3.cards))
 def testStringWithALotOfCardsToStack(self):
   stack = cards.StackOfCards()
   stack.push(cards.Card(1, 2))
   stack.push(cards.Card(5, 5))
   stack.push(cards.Card(50, 7))
   stack.push(cards.Card(123, 2))
   self.assertEquals(stack, cards.strToStackOfCards('1-2 5-5 50-7 123-2'))
 def testPopAll(self):
   deck = cards.StackOfCards()
   deck.push(cards.Card(1, 1))
   deck.push(cards.Card(2, 2))
   self.assertEquals(2, deck.height())
   self.assertEquals(cards.strToStackOfCards('1-1 2-2'), deck.popAll())
   self.assertEquals(0, deck.height())
 def testPopCards(self):
   deck = cards.StackOfCards()
   deck.push(cards.Card(1, 1))
   deck.push(cards.Card(2, 2))
   deck.push(cards.Card(3, 3))
   deck.push(cards.Card(4, 4))
   self.assertEquals(cards.strToStackOfCards('1-1 2-2'), 
                     deck.popCards([cards.Card(1, 1), cards.Card(2, 2)]))
   self.assertEquals(2, deck.height())
   self.assertEquals(cards.strToStackOfCards('3-3'), deck.popCards([cards.Card(3, 3)]))
   self.assertEquals(1, deck.height())
   self.assertEquals(cards.strToStackOfCards('4-4'), deck.popCards([cards.Card(4, 4)]))
   self.assertEquals(0, deck.height())
   deck.push(cards.Card(1, 1))
   deck.push(cards.Card(2, 2))
   self.assertEquals(cards.strToStackOfCards('1-1 2-2'), 
                     deck.popCards(deck.cards))
 def testAllCombinationsOfRepeatedCards(self):
   stack = cards.strToStackOfCards('3-1 3-1 5-1')
   combinations = stack.allCombinationsOfCards()
   self.assertEquals(7, len(combinations))
   self.assertTrue(cards.strToStackOfCards('3-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('3-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('5-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('3-1 3-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('3-1 5-1') in combinations)
   self.assertTrue(cards.strToStackOfCards('3-1 3-1 5-1') in combinations)
 def testPopCardsWithValue(self):
   deck = cards.StackOfCards()
   self.assertEquals(cards.StackOfCards(), deck.popCardsWithValue(1))
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards('1-2'), deck.popCardsWithValue(1))
   self.assertEquals(3, deck.height())
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards('2-1 2-2'), deck.popCardsWithValue(2))
   self.assertEquals(2, deck.height())
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards(''), deck.popCardsWithValue(3))
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards('4-1'), deck.popCardsWithValue(4))
  def testCombinationWithQKASJoker(self):
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 12-1 13-1 1-1'))
    self.assertTrue(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 11-1 13-1 1-1'))
    self.assertTrue(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 11-1 12-1 1-1'))
    self.assertTrue(deck.isValidCombination())

    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 8-1 10-1 12-1'))
    self.assertFalse(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 0-0 8-1 10-1 12-1'))
    self.assertFalse(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 0-0 11-1 13-1 1-1'))
    self.assertFalse(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 0-0 10-1 12-1 1-1'))
    self.assertFalse(deck.isValidCombination())
    
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 11-1 12-2 1-1'))
    self.assertFalse(deck.isValidCombination())
    deck = hole.StackOfCards(cards.strToStackOfCards('0-0 11-1 12-1 1-2'))
    self.assertFalse(deck.isValidCombination())
 def testRealCanastraWithJoker(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-2 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 0-0 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 2-2 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 0-0 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 3-2 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-2 2-2 3-2 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('1-2 2-1 3-2 0-0 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.assertFalse(deck.isValidCombination())
 def testInvalidString(self):
   try:
     cards.strToStackOfCards('1/2')
   except: pass
   else: self.fail()
   try:
     cards.strToStackOfCards('1 2')
   except: pass
   else: self.fail()
   try:
     cards.strToStackOfCards('asdasd')
   except: pass
   else: self.fail()
 def testCompareByHeight(self):
   deck = cards.strToStackOfCards('1-1 2-2 3-3')
   deck2 = cards.strToStackOfCards('1-1 2-2 3-3')
   self.assertEquals(0, deck.compareByHeight(deck2))
   self.assertEquals(0, deck2.compareByHeight(deck))
   
   deck = cards.strToStackOfCards('1-1 2-2 4-4')
   deck2 = cards.strToStackOfCards('1-1 2-2 3-3')
   self.assertEquals(0, deck.compareByHeight(deck2))
   self.assertEquals(0, deck2.compareByHeight(deck))
   
   deck = cards.strToStackOfCards('1-1 2-2')
   deck2 = cards.strToStackOfCards('1-1 2-2 3-3 4-4')
   self.assertEquals(-2, deck.compareByHeight(deck2))
   self.assertEquals(2, deck2.compareByHeight(deck))
   
   deck = cards.strToStackOfCards('')
   deck2 = cards.strToStackOfCards('1-1')
   self.assertEquals(-1, deck.compareByHeight(deck2))
   self.assertEquals(1, deck2.compareByHeight(deck))
 def testPopCardsWithSuit(self):
   deck = cards.StackOfCards()
   self.assertEquals(cards.StackOfCards(), deck.popCardsWithSuit(1))
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards('2-1 4-1'), deck.popCardsWithSuit(1))
   self.assertEquals(2, deck.height())
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards('1-2 2-2'), deck.popCardsWithSuit(2))
   
   deck = cards.strToStackOfCards('1-2 2-1 4-1 2-2')
   self.assertEquals(cards.strToStackOfCards(''), deck.popCardsWithSuit(3))
   self.assertEquals(4, deck.height())
 def testCombinationWithAS2Joker(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 0-0'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 0-0 3-1'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 2-2'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 2-2 3-1'))
   self.assertTrue(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 2-2 3-2'))
   self.assertFalse(deck.isValidCombination())
   
   deck = hole.StackOfCards(cards.strToStackOfCards('1-1 2-2 2-2'))
   self.assertFalse(deck.isValidCombination())
 def testCombinationWithTwoCardsWithSameValueAndJoker(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('0-0 8-1 8-2'))
   self.assertTrue(deck.isValidCombination())
 def testCardsWithDifferentValuesThatIsNotSequenceAndDontHaveJoker(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('10-1 12-1 13-1'))
   self.assertFalse(deck.isValidCombination())
 def testStringNoneToStack(self):
   self.assertEquals(cards.StackOfCards(), cards.strToStackOfCards(None))
 def testStringEmptyToStack(self):
   self.assertEquals(cards.StackOfCards(), cards.strToStackOfCards(''))
 def testCombinationWithQKAS(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('12-1 13-1 1-1'))
   self.assertTrue(deck.isValidCombination())
 def testStringWithOneCardToStack(self):
   stack = cards.StackOfCards()
   stack.push(cards.Card(1, 2))
   self.assertEquals(stack, cards.strToStackOfCards('1-2'))
 def testSequenceWithDifferentSuit(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('3-1 4-1 5-2'))
   self.assertFalse(deck.isValidCombination())
 def testSequenceWithSameSuit(self):
   deck = hole.StackOfCards(cards.strToStackOfCards('3-1 4-1 5-1'))
   self.assertTrue(deck.isValidCombination())
   deck = hole.StackOfCards(cards.strToStackOfCards('12-2 13-2 11-2'))
   self.assertTrue(deck.isValidCombination())
 def setUp(self):
   self.sequence_combination = hole.StackOfCards(cards.strToStackOfCards('3-1 4-1 5-1'))
   self.sequence_withjoker_combination = hole.StackOfCards(cards.strToStackOfCards('3-1 0-0 5-1'))
   self.sequenceas22_combination = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 2-2'))
   self.sequenceas20_combination = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 0-0'))
   self.sequenceas22_invalid_combination = hole.StackOfCards(cards.strToStackOfCards('1-1 2-2 2-2'))
   self.sequenceas22_invalid_combination = hole.StackOfCards(cards.strToStackOfCards('1-3 2-1 2-2'))
   self.sequenceas20_invalid_combination = hole.StackOfCards(cards.strToStackOfCards('1-1 2-2 0-0'))
   self.sequenceQKAS_combination = hole.StackOfCards(cards.strToStackOfCards('12-1 13-1 1-1'))
   self.sequenceQKASwithjoker_combination = hole.StackOfCards(cards.strToStackOfCards('0-0 13-1 1-1'))
   self.samevalue_combination = hole.StackOfCards(cards.strToStackOfCards('3-1 3-1 3-2'))
   self.samevaluewithjoker_combination = hole.StackOfCards(cards.strToStackOfCards('3-1 3-2 0-0'))
   self.jokers_combination = hole.StackOfCards(cards.strToStackOfCards('2-1 0-0 2-2'))
   
   self.sequence_canastra = hole.StackOfCards(cards.strToStackOfCards('3-1 4-1 5-1 6-1 7-1 8-1 9-1'))
   self.sequence_withjoker_canastra = hole.StackOfCards(cards.strToStackOfCards('3-1 0-0 5-1 6-1 7-1 8-1 9-1'))
   self.real_canastra = hole.StackOfCards(cards.strToStackOfCards('1-1 2-1 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.realwithjoker_canastra = hole.StackOfCards(cards.strToStackOfCards('1-1 2-2 3-1 4-1 5-1 6-1 7-1 8-1 9-1 10-1 11-1 12-1 13-1 1-1'))
   self.samevalue_canastra = hole.StackOfCards(cards.strToStackOfCards('3-1 3-1 3-2 3-3 3-4 3-4 3-3'))
   self.samevaluewithjoker_canastra = hole.StackOfCards(cards.strToStackOfCards('3-1 3-2 3-3 3-4 3-1 3-2 0-0'))
   self.jokers_canastra = hole.StackOfCards(cards.strToStackOfCards('2-1 0-0 2-2 0-0 0-0 0-0 2-3'))
 def testStringWithTwoCardsToStack(self):
   stack = cards.StackOfCards()
   stack.push(cards.Card(1, 2))
   stack.push(cards.Card(3, 3))
   self.assertEquals(stack, cards.strToStackOfCards('1-2 3-3'))