def test_append_valid(self): """ Test append() method with valid type. """ h = Hand(namelist=["AD", "TC", "JS", "2H", "TD"]) card = Card(name="5C") h.append(card) self.assertEqual(h[-1].index(), card.index()) self.assertFalse(h._cards[-1] is card)
def test_index_from_rank_and_value_strings(self): """Test that the card's index is correctly set and returned by the index() method. """ samples = [ (1, 0, 0), (2, 0, 1), (3, 0, 2), (4, 0, 3), (14, 0, 0), (1, 1, 13), (2, 1, 14), (3, 1, 15), (13, 1, 25), (14, 1, 13), (1, 2, 26), (5, 2, 30), (10, 2, 35), (11, 2, 36), (14, 2, 26), (1, 3, 39), (9, 3, 47), (11, 3, 49), (13, 3, 51), (14, 3, 39) ] rank_strings = { 1: "ace", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "jack", 12: "queen", 13: "king", 14: "ace" } suit_strings = {0: "clubs", 1: "hearts", 2: "spades", 3: "diamonds"} for rank, suit, idx in samples: card = Card(rank_strings[rank], suit_strings[suit]) self.assertEqual(card.index(), idx)
def test_getitem_negative_single(self): """ Test __getitem__ with negative indices and no slicing. """ card1 = Card(name="TD") card2 = Card(name="2H") card3 = Card(name="TC") namelist = ["AD", "TC", "JS", "2H", "TD"] h = Hand(namelist=namelist) self.assertEqual(h[-1].index(), card1.index()) self.assertTrue(h[-1] is h._cards[-1]) self.assertEqual(h[-2].index(), card2.index()) self.assertTrue(h[-2] is h._cards[-2]) self.assertEqual(h[-4].index(), card3.index()) self.assertTrue(h[-4] is h._cards[-4])