Example #1
0
    def test_invalid_set_add(self):
        m = Meld(Card(rank=Rank.TWO, suit=Suit.HEART),
                 Card(rank=Rank.TWO, suit=Suit.DIAMOND))
        self.assertTrue(m.all_same_rank)
        self.assertFalse(m.all_same_suit)
        self.assertFalse(m.is_run)
        self.assertFalse(m.is_set)
        self.assertFalse(m.complete)
        self.assertEqual(m.size(), 2)

        with self.assertRaises(InvalidMeldError):
            m.add(Card(rank=Rank.THREE, suit=Suit.CLUB))

        self.assertEqual(m.size(), 2)
Example #2
0
    def add_to_meld(self, meld: Meld, card: Card) -> None:
        """Add a card to a meld.

        Args:
            meld (Meld): the meld to add to
            card (Card): the card to add

        Side effects:
            Updates _card_to_meld_id map accordingly

        Raises InvalidMeldError.
        """
        meld.add(card)
        if card in self._card_to_meld_id.keys():
            self._card_to_meld_id[card].add(id(meld))
        else:
            self._card_to_meld_id[card] = set([id(meld)])
Example #3
0
    def test_add_sorts(self):
        c2 = Card(rank=Rank.TWO, suit=Suit.CLUB)
        c3 = Card(rank=Rank.THREE, suit=Suit.CLUB)
        c4 = Card(rank=Rank.FOUR, suit=Suit.CLUB)

        m = Meld(c2)
        m.add(c4)
        m.add(c3)
        self.assertFalse(m.all_same_rank)
        self.assertTrue(m.all_same_suit)
        self.assertTrue(m.is_run)
        self.assertFalse(m.is_set)
        self.assertTrue(m.complete)

        # cards were implicitly re-ordered by add()
        self.assertEqual(m.cards[0], c2)
        self.assertEqual(m.cards[1], c3)
        self.assertEqual(m.cards[2], c4)
Example #4
0
    def test_singleton_add(self):
        """Test adding a card to a single-card partial meld.

        This is significant b/c until the 2nd card is added, any
        single-card partial meld is both a potential run and set.
        """
        m = Meld(Card(rank=Rank.KING, suit=Suit.CLUB))
        self.assertTrue(m.all_same_rank)
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.is_run)
        self.assertFalse(m.is_set)
        self.assertFalse(m.complete)

        m.add(Card(rank=Rank.TWO, suit=Suit.CLUB))
        self.assertFalse(m.all_same_rank)
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.is_run)
        self.assertFalse(m.is_set)
        self.assertFalse(m.complete)
Example #5
0
    def test_large_valid_run_grows_to_inside_straight(self):
        """A run becomes incomplete after inside straight conversion."""
        m = Meld(Card(rank=Rank.TWO, suit=Suit.HEART),
                 Card(rank=Rank.THREE, suit=Suit.HEART),
                 Card(rank=Rank.FOUR, suit=Suit.HEART))
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.all_same_rank)
        self.assertTrue(m.is_run)
        self.assertFalse(m.is_set)
        self.assertTrue(m.complete)

        m.add(Card(rank=Rank.SIX, suit=Suit.HEART))

        self.assertEqual(m.size(), 4)
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.all_same_rank)
        self.assertFalse(m.is_run)
        self.assertFalse(m.is_set)
        self.assertFalse(m.complete)
Example #6
0
    def test_invalid_add_does_not_break_complete_run(self):
        """A bad addition to a complete run doesn't break it."""
        m = Meld(Card(rank=Rank.TWO, suit=Suit.HEART),
                 Card(rank=Rank.THREE, suit=Suit.HEART),
                 Card(rank=Rank.FOUR, suit=Suit.HEART))
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.all_same_rank)
        self.assertTrue(m.is_run)
        self.assertFalse(m.is_set)
        self.assertTrue(m.complete)

        with self.assertRaises(InvalidMeldError):
            m.add(Card(rank=Rank.SIX, suit=Suit.CLUB))

        self.assertEqual(m.size(), 3)
        self.assertTrue(m.all_same_suit)
        self.assertFalse(m.all_same_rank)
        self.assertTrue(m.is_run)
        self.assertFalse(m.is_set)
        self.assertTrue(m.complete)