def test_setitem_positive_slicing(self):

        """
        Test __setitem__ with positive indices and slicing.

        """

        hc1 = Hand(namelist=["3C", "2H"])
        hc2 = Hand(namelist=["AC", "KS", "9D"])
        hc3 = Hand(namelist=["6H"])

        h = Hand(namelist=["JC", "TC", "JS", "2H", "TD"])
        h1 = Hand(namelist=["JC", "TC", "3C", "2H", "2H", "TD"])
        h2 = Hand(namelist=["JC", "AC", "3C", "KS", "2H", "9D"])
        h3 = Hand(namelist=["6H", "AC", "3C", "KS", "2H", "9D"])

        h[2:3] = hc1
        self.assertEqual(h.index_list(), h1.index_list())
        self.assertTrue(h._cards[2] is hc1._cards[0])

        h[1:6:2] = hc2
        self.assertEqual(h.index_list(), h2.index_list())
        self.assertTrue(h._cards[1] is hc2._cards[0])

        h[:1] = hc3
        self.assertEqual(h.index_list(), h3.index_list())
        self.assertTrue(h._cards[0] is hc3._cards[0])
    def test_mult_copies_made_manual_change(self):

        """Tests copies are properly made. Use manual change to
        make change.

        """

        benchmark3 = Hand(namelist=["AH", "2H"])
        benchmark2 = Hand(namelist=["6D", "2H", "AH", "2H", "AH", "2H"])

        hl = self.hand3 * 3
        hr = 3 * self.hand3

        hl._cards[0]._rank = 6
        hl._cards[0]._suit = 3
        hl._cards[0]._index = 44
        hr._cards[0]._rank = 6
        hr._cards[0]._suit = 3
        hr._cards[0]._index = 44

        # Ensure changed results match benchmark. This also ensures
        # that copies were made during the repetition (i.e. that
        # changing hl._cards[0], for instance, does not also change
        # hl._cards[2] and hl._cards[4]

        self.assertEqual(benchmark2.index_list(), hl.index_list())
        self.assertEqual(benchmark2.index_list(), hr.index_list())

        # Test hand3 was not altered.

        self.assertEqual(benchmark3.index_list(), self.hand3.index_list())
    def test_setitem_negative_slicing(self):

        """
        Test __setitem__ with negative indices and slicing.

        """

        hc1 = Hand(namelist=["3C", "2H"])
        hc2 = Hand(namelist=["AC", "KS", "9D"])
        hc3 = Hand(namelist=["6H"])

        h = Hand(namelist=["JC", "TC", "JS", "2H", "TD"])
        h1 = Hand(namelist=["JC", "TC", "3C", "2H", "2H", "TD"])
        h2 = Hand(namelist=["JC", "9D", "3C", "KS", "2H", "AC"])
        h3 = Hand(namelist=["6H", "9D", "3C", "KS", "2H", "AC"])

        h[-3:-2] = hc1
        self.assertEqual(h.index_list(), h1.index_list())
        self.assertTrue(h._cards[2] is hc1._cards[0])

        h[-1:-6:-2] = hc2
        self.assertEqual(h.index_list(), h2.index_list())
        self.assertFalse(h._cards[1] is hc2._cards[0])

        h[:-5] = hc3
        self.assertEqual(h.index_list(), h3.index_list())
        self.assertTrue(h._cards[0] is hc3._cards[0])
    def test_add_copy_made_right_hand_index(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original right
        side hand changes. The hand index makes the change.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark2 = Hand(namelist=["AD", "5S", "6S"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand2...

        self.hand2[0] = Card(name="AD")

        # ...check first element of hand2 really changed...

        self.assertEqual(benchmark2.index_list(), self.hand2.index_list())

        # ...and check hand3 did *not* change when hand2 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())
    def test_setitem_negative_single(self):

        """
        Test __setitem__ with negative indices and no slicing.

        """

        card1 = Card(name="JC")
        card2 = Card(name="8H")
        card3 = Card(name="QS")

        h = Hand(namelist=["AD", "TC", "JS", "2H", "TD"])
        h1 = Hand(namelist=["JC", "TC", "JS", "2H", "TD"])
        h2 = Hand(namelist=["JC", "TC", "8H", "2H", "TD"])
        h3 = Hand(namelist=["JC", "TC", "8H", "2H", "QS"])

        h[-5] = card1
        self.assertEqual(h.index_list(), h1.index_list())
        self.assertFalse(card1 is h._cards[0])

        h[-3] = card2
        self.assertEqual(h.index_list(), h2.index_list())
        self.assertFalse(card2 is h._cards[2])

        h[-1] = card3
        self.assertEqual(h.index_list(), h3.index_list())
        self.assertFalse(card3 is h._cards[4])
    def test_add_copy_made_left_list_change(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original left
        side hand changes. Manually access the card list to make
        the change.

        The difference between this and the related 'match_index'
        tests is that the latter replaces a list member, and this
        changes it. If the *list* is copied, but the individual
        cards are not, the 'match_index' tests will pass, but the
        'list_change' tests will fail.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark1 = Hand(namelist=["AH", "2C", "3C"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand1...

        self.hand1._cards[0]._rank = 14
        self.hand1._cards[0]._suit = 1
        self.hand1._cards[0]._index = 13

        # ...check first element of hand1 really changed...

        self.assertEqual(benchmark1.index_list(), self.hand1.index_list())

        # ...and check hand3 did *not* change when hand1 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())
    def test_add_basic(self):

        """
        Test basic hand addition.

        """

        benchmark = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        hand3 = self.hand1 + self.hand2
        self.assertEqual(benchmark.index_list(), hand3.index_list())
    def test_pop(self):

        """
        Test pop() method.

        """

        h = Hand(namelist=["AD", "2H", "TC", "TD", "JS"])
        h1 = Hand(namelist=["AD", "2H", "TC", "TD"])
        h2 = Hand(namelist=["AD", "TC", "TD"])
        h3 = Hand(namelist=["AD", "TC"])

        c = h.pop()
        self.assertEqual(c.index(), Card(name="JS").index())
        self.assertEqual(h.index_list(), h1.index_list())

        c = h.pop(1)
        self.assertEqual(c.index(), Card(name="2H").index())
        self.assertEqual(h.index_list(), h2.index_list())

        # Note: using a float as in index seems to raise a
        # DeprecationWarning, so don't include in the fail test,
        # as one day that'll become an exception.

        # Note: Not sure why the two commented-out tests aren't working,
        # investigate in future.

        bad_list = ["spam"]
        #bad_list = ["spam", Hand(namelist=["AS"])]

        for badness in bad_list:
            self.assertRaises(TypeError, h.pop, badness)
    def test_iter(self):

        """
        Test __iter__.

        """

        h = Hand(namelist=["TC", "JS", "2H", "TD", "7H", "6S"])

        idx_list = [card.index() for card in h]
        self.assertEqual(idx_list, h.index_list())
    def test_mult_basic(self):

        """Tests basic Hand repetition."""

        benchmark = Hand(namelist=["AH", "2H", "AH", "2H", "AH", "2H"])

        hl = self.hand3 * 3
        hr = 3 * self.hand3

        self.assertEqual(benchmark.index_list(), hl.index_list())
        self.assertEqual(benchmark.index_list(), hr.index_list())
    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_inplace_mult_basic(self):

        """Test basic inplace multiplication."""

        benchmark4 = Hand(namelist=["3D", "4D", "3D", "4D", "3D", "4D"])
        card = self.hand4._cards[0]

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.assertEqual(self.hand4.index_list(), benchmark4.index_list())

        # Test the operation left hand4's original members intact.

        self.assertTrue(card is self.hand4._cards[0])
    def test_inplace_mult_copies_made_hand_index(self):

        """Test copies are made correctly during in-place
        multiplication. Make change using hand_index change.

        """

        benchmark = Hand(namelist=["AS", "4D", "3D", "4D", "3D", "4D"])

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.hand4[0] = Card(name="AS")

        self.assertEqual(self.hand4.index_list(), benchmark.index_list())
    def test_inplace_add_basic(self):

        """Test basic inplace addition."""

        benchmark1 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        card = self.hand1._cards[0]

        # Add hand2 to hand1 in place, and test hand1 ends up with
        # the right list members.

        self.hand1 += self.hand2
        self.assertEqual(self.hand1.index_list(), benchmark1.index_list())

        # Test the operation left hand1's original members intact.

        self.assertTrue(card is self.hand1._cards[0])
    def test_inplace_mult_copies_made_manual_change(self):

        """Test copies are made correctly during in-place
        multiplication. Make change using manual change.

        """

        benchmark = Hand(namelist=["AS", "4D", "3D", "4D", "3D", "4D"])

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.hand4._cards[0]._rank = 1
        self.hand4._cards[0]._suit = 2
        self.hand4._cards[0]._index = 26

        self.assertEqual(self.hand4.index_list(), benchmark.index_list())
    def test_delitem_negative(self):

        """
        Test __delitem__ with negative indices.

        """

        h = Hand(namelist=["JC", "TC", "JS", "2H", "TD", "7H", "6S"])
        h1 = Hand(namelist=["TC", "JS", "2H", "TD", "7H", "6S"])
        h2 = Hand(namelist=["JS", "TD", "6S"])
        h3 = Hand(namelist=["JS", "TD"])

        del(h[-7])
        self.assertEqual(h.index_list(), h1.index_list())

        del(h[-2:-7:-2])
        self.assertEqual(h.index_list(), h2.index_list())

        del(h[-1])
        self.assertEqual(h.index_list(), h3.index_list())
    def test_reverse(self):

        """
        Test reverse() method.

        """

        h = Hand(namelist=["7D", "3H", "TC", "7H", "QC", "3C"])
        h1 = Hand(namelist=["3C", "QC", "7H", "TC", "3H", "7D"])

        self.assertNotEqual(h.index_list(), h1.index_list())
        h.reverse()
        self.assertEqual(h.index_list(), h1.index_list())
    def test_inplace_add_basic_copied_hand_index(self):

        """Test that changing the new list members following
        in-place addition does not alter the original hand's
        list. Use the hand index to make the change.

        """

        benchmark1 = Hand(namelist=["AC", "2C", "3C", "AD", "5S", "6S"])
        benchmark2 = Hand(namelist=["4S", "5S", "6S"])

        self.hand1 += self.hand2
        self.hand1[3] = Card(name="AD")

        # Check the change was made

        self.assertEqual(self.hand1.index_list(), benchmark1.index_list())

        # Check hand2 remains unchanged

        self.assertEqual(self.hand2.index_list(), benchmark2.index_list())
    def test_count(self):

        """
        Test count() method.

        """

        h = Hand(namelist=["AD", "TC", "JS", "2H", "TD"])
        card = Card(name="TC")
        rank = 10
        rank_str = "jack"
        bad_list = [6.5, Hand(namelist=["AS"])]

        self.assertEqual(h.count(card), 1)
        self.assertEqual(h.count(rank), 2)
        self.assertEqual(h.count(rank_str), 1)
        for badness in bad_list:
            self.assertEqual(h.count(badness), 0)
        self.assertRaises(ValueError, h.count, 0)
        self.assertRaises(ValueError, h.count, 15)
        self.assertRaises(ValueError, h.count, "spam")
    def test_getitem_positive_slicing(self):

        """
        Test __getitem__ with positive indices and slicing.

        """

        namelist = ["AD", "TC", "JS", "2H", "TD"]
        h = Hand(namelist=namelist)

        handc1 = Hand(namelist=["AD", "TC", "JS"])
        handc2 = Hand(namelist=["TC", "JS"])
        handc3 = Hand(namelist=["JS", "2H", "TD"])

        handt1 = h[:3]
        handt2 = h[1:3]
        handt3 = h[2:]

        self.assertEqual(handt1.index_list(), handc1.index_list())
        self.assertTrue(handt1._cards[0] is h._cards[0])

        self.assertEqual(handt2.index_list(), handc2.index_list())
        self.assertFalse(handt2._cards[1] is h._cards[1])

        self.assertEqual(handt3.index_list(), handc3.index_list())
        self.assertFalse(handt3._cards[2] is h._cards[2])
    def test_index(self):

        """
        Test index() method.

        """

        h = Hand(namelist=["AD", "TC", "JS", "2H", "TD"])

        card = Card(name="TD")
        rank = 10
        rank_str = "jack"
        bad_list = [6.5, Hand(namelist=["AS"])]

        self.assertEqual(h.index(card), 4)
        self.assertEqual(h.index(rank), 1)
        self.assertEqual(h.index(rank_str), 2)
        for badness in bad_list:
            self.assertRaises(ValueError, h.index, badness)
        self.assertRaises(ValueError, h.index, 0)
        self.assertRaises(ValueError, h.index, 15)
        self.assertRaises(ValueError, h.index, "spam")
    def test_remove(self):

        """
        Test remove() method.

        """

        h = Hand(namelist=["AD", "2H", "TC", "TD", "TC"])
        h1 = Hand(namelist=["AD", "2H", "TD", "TC"])

        h.remove(Card(name="TC"))
        self.assertEqual(h.index_list(), h1.index_list())

        bad_list = [1, 1.5, "spam", Hand(namelist=["AS"])]
        for badness in bad_list:
            self.assertRaises(TypeError, h.remove, badness)
    def test_extend(self):

        """
        Test extend() method.

        """

        h = Hand(namelist=["AD", "TC", "JS"])
        h1 = Hand(namelist=["QH", "2D"])
        hr = Hand(namelist=["AD", "TC", "JS", "QH", "2D"])

        h.extend(h1)
        self.assertEqual(h.index_list(), hr.index_list())
        self.assertFalse(h._cards[3] is h1._cards[0])

        bad_list = [0, 1.5, "spam", Card(name="AS")]
        for badness in bad_list:
            self.assertRaises(TypeError, h.extend, badness)
    def test_insert(self):

        """
        Test insert() method.

        """

        h = Hand(namelist=["AD", "TC", "JS"])
        h1 = Hand(namelist=["AD", "2H", "TC", "JS"])
        h2 = Hand(namelist=["AD", "2H", "TC", "TD", "JS"])
        c1 = Card(name="2H")
        c2 = Card(name="TD")
        cl = h[-1]

        h.insert(1, c1)
        self.assertEqual(h[1], c1)
        self.assertFalse(h._cards[1] is c1)
        self.assertEqual(h.index_list(), h1.index_list())
        self.assertEqual(h[-1], cl)
        self.assertEqual(len(h), 4)

        h.insert(3, c2)
        self.assertEqual(h[3], c2)
        self.assertFalse(h._cards[3] is c2)
        self.assertEqual(h.index_list(), h2.index_list())
        self.assertEqual(h[-1], cl)
        self.assertEqual(len(h), 5)

        bad_list = [1, 6.5, "spam", Hand(namelist=["AS"])]

        for badness in bad_list:
            self.assertRaises(TypeError, h.insert, badness)
class TestSequenceFunctions(unittest.TestCase):

    """Test sequence class for addition and multiplication
    methods of hand module.

    """

    def setUp(self):
        self.hand1 = Hand(namelist=["AC", "2C", "3C"])
        self.hand2 = Hand(namelist=["4S", "5S", "6S"])
        self.hand3 = Hand(namelist=["AH", "2H"])
        self.hand4 = Hand(namelist=["3D", "4D"])

    def test_add_basic(self):

        """
        Test basic hand addition.

        """

        benchmark = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        hand3 = self.hand1 + self.hand2
        self.assertEqual(benchmark.index_list(), hand3.index_list())

    def test_add_copy_made_left_hand_index(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original left
        side hand changes. Use the hand index to make the change.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark1 = Hand(namelist=["AH", "2C", "3C"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand1...

        self.hand1[0] = Card(name="AH")

        # ...check first element of hand1 really changed...

        self.assertEqual(benchmark1.index_list(), self.hand1.index_list())

        # ...and check hand3 did *not* change when hand1 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())

    def test_add_copy_made_right_hand_index(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original right
        side hand changes. The hand index makes the change.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark2 = Hand(namelist=["AD", "5S", "6S"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand2...

        self.hand2[0] = Card(name="AD")

        # ...check first element of hand2 really changed...

        self.assertEqual(benchmark2.index_list(), self.hand2.index_list())

        # ...and check hand3 did *not* change when hand2 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())

    def test_add_copy_made_left_list_change(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original left
        side hand changes. Manually access the card list to make
        the change.

        The difference between this and the related 'match_index'
        tests is that the latter replaces a list member, and this
        changes it. If the *list* is copied, but the individual
        cards are not, the 'match_index' tests will pass, but the
        'list_change' tests will fail.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark1 = Hand(namelist=["AH", "2C", "3C"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand1...

        self.hand1._cards[0]._rank = 14
        self.hand1._cards[0]._suit = 1
        self.hand1._cards[0]._index = 13

        # ...check first element of hand1 really changed...

        self.assertEqual(benchmark1.index_list(), self.hand1.index_list())

        # ...and check hand3 did *not* change when hand1 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())

    def test_add_copy_made_right_list_change(self):

        """Test copies are appropriately made during addition, so
        that the new hand does not change when the original right
        side hand changes. Manually access the card list to make
        the change.

        The difference between this and the related 'match_index'
        tests is that the latter replaces a list member, and this
        changes it. If the *list* is copied, but the individual
        cards are not, the 'match_index' tests will pass, but the
        'list_change' tests will fail.

        """

        benchmark3 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        benchmark2 = Hand(namelist=["AD", "5S", "6S"])

        # Form hand3 by adding hand2 to hand1...

        hand3 = self.hand1 + self.hand2

        # ...change first element of hand2...

        self.hand2._cards[0]._rank = 1
        self.hand2._cards[0]._suit = 4
        self.hand2._cards[0]._index = 39

        # ...check first element of hand2 really changed...

        self.assertEqual(benchmark2.index_list(), self.hand2.index_list())

        # ...and check hand3 did *not* change when hand2 did.

        self.assertEqual(benchmark3.index_list(), hand3.index_list())

    def test_inplace_add_basic(self):

        """Test basic inplace addition."""

        benchmark1 = Hand(namelist=["AC", "2C", "3C", "4S", "5S", "6S"])
        card = self.hand1._cards[0]

        # Add hand2 to hand1 in place, and test hand1 ends up with
        # the right list members.

        self.hand1 += self.hand2
        self.assertEqual(self.hand1.index_list(), benchmark1.index_list())

        # Test the operation left hand1's original members intact.

        self.assertTrue(card is self.hand1._cards[0])

    def test_inplace_add_basic_copied_hand_index(self):

        """Test that changing the new list members following
        in-place addition does not alter the original hand's
        list. Use the hand index to make the change.

        """

        benchmark1 = Hand(namelist=["AC", "2C", "3C", "AD", "5S", "6S"])
        benchmark2 = Hand(namelist=["4S", "5S", "6S"])

        self.hand1 += self.hand2
        self.hand1[3] = Card(name="AD")

        # Check the change was made

        self.assertEqual(self.hand1.index_list(), benchmark1.index_list())

        # Check hand2 remains unchanged

        self.assertEqual(self.hand2.index_list(), benchmark2.index_list())

    def test_inplace_add_basic_copied_manual_change(self):

        """Test that changing the new list members following
        in-place addition does not alter the original hand's
        list. Use the hand index to make the change.

        """

        benchmark1 = Hand(namelist=["AC", "2C", "3C", "AD", "5S", "6S"])
        benchmark2 = Hand(namelist=["4S", "5S", "6S"])

        self.hand1 += self.hand2
        self.hand1._cards[3]._rank = 14
        self.hand1._cards[3]._suit = 3
        self.hand1._cards[3]._index = 39

        # Check the change was made

        self.assertEqual(self.hand1.index_list(), benchmark1.index_list())

        # Check hand2 remains unchanged.

        self.assertEqual(self.hand2.index_list(), benchmark2.index_list())

    def test_bad_add_assertion(self):

        """Test than a NotImplementedError is raised for invalid
        addition operands.

        """

        bad_opers = [3, 9.5, "spam", Card(name="AS")]

        for oper in bad_opers:
            self.assertRaises(NotImplementedError, self.hand1.__add__, oper)
            self.assertRaises(NotImplementedError, self.hand1.__radd__, oper)
            self.assertRaises(NotImplementedError, self.hand1.__iadd__, oper)

    def test_mult_basic(self):

        """Tests basic Hand repetition."""

        benchmark = Hand(namelist=["AH", "2H", "AH", "2H", "AH", "2H"])

        hl = self.hand3 * 3
        hr = 3 * self.hand3

        self.assertEqual(benchmark.index_list(), hl.index_list())
        self.assertEqual(benchmark.index_list(), hr.index_list())

    def test_mult_copies_made_hand_index(self):

        """Tests copies are properly made. Use hand_index change to
        make change.

        """

        benchmark3 = Hand(namelist=["AH", "2H"])
        benchmark2 = Hand(namelist=["6D", "2H", "AH", "2H", "AH", "2H"])

        hl = self.hand3 * 3
        hr = 3 * self.hand3

        hl[0] = Card(name="6D")
        hr[0] = Card(name="6D")

        # Ensure changed results match benchmark. This also ensures
        # that copies were made during the repetition (i.e. that
        # changing hl._cards[0], for instance, does not also change
        # hl._cards[2] and hl._cards[4]

        self.assertEqual(benchmark2.index_list(), hl.index_list())
        self.assertEqual(benchmark2.index_list(), hr.index_list())

        # Test hand3 was not altered.

        self.assertEqual(benchmark3.index_list(), self.hand3.index_list())

    def test_mult_copies_made_manual_change(self):

        """Tests copies are properly made. Use manual change to
        make change.

        """

        benchmark3 = Hand(namelist=["AH", "2H"])
        benchmark2 = Hand(namelist=["6D", "2H", "AH", "2H", "AH", "2H"])

        hl = self.hand3 * 3
        hr = 3 * self.hand3

        hl._cards[0]._rank = 6
        hl._cards[0]._suit = 3
        hl._cards[0]._index = 44
        hr._cards[0]._rank = 6
        hr._cards[0]._suit = 3
        hr._cards[0]._index = 44

        # Ensure changed results match benchmark. This also ensures
        # that copies were made during the repetition (i.e. that
        # changing hl._cards[0], for instance, does not also change
        # hl._cards[2] and hl._cards[4]

        self.assertEqual(benchmark2.index_list(), hl.index_list())
        self.assertEqual(benchmark2.index_list(), hr.index_list())

        # Test hand3 was not altered.

        self.assertEqual(benchmark3.index_list(), self.hand3.index_list())

    def test_inplace_mult_basic(self):

        """Test basic inplace multiplication."""

        benchmark4 = Hand(namelist=["3D", "4D", "3D", "4D", "3D", "4D"])
        card = self.hand4._cards[0]

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.assertEqual(self.hand4.index_list(), benchmark4.index_list())

        # Test the operation left hand4's original members intact.

        self.assertTrue(card is self.hand4._cards[0])

    def test_inplace_mult_copies_made_hand_index(self):

        """Test copies are made correctly during in-place
        multiplication. Make change using hand_index change.

        """

        benchmark = Hand(namelist=["AS", "4D", "3D", "4D", "3D", "4D"])

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.hand4[0] = Card(name="AS")

        self.assertEqual(self.hand4.index_list(), benchmark.index_list())

    def test_inplace_mult_copies_made_manual_change(self):

        """Test copies are made correctly during in-place
        multiplication. Make change using manual change.

        """

        benchmark = Hand(namelist=["AS", "4D", "3D", "4D", "3D", "4D"])

        # Multiply hand4 by 3 in-place.

        self.hand4 *= 3
        self.hand4._cards[0]._rank = 1
        self.hand4._cards[0]._suit = 2
        self.hand4._cards[0]._index = 26

        self.assertEqual(self.hand4.index_list(), benchmark.index_list())

    def test_bad_mult_assertion(self):

        """Test than a NotImplementedError is raised for invalid
        multiplication operands.

        """

        bad_opers = [9.5, "spam", Card(name="AS"),
                     self.hand3]

        for oper in bad_opers:
            self.assertRaises(NotImplementedError, self.hand4.__mul__, oper)
            self.assertRaises(NotImplementedError, self.hand4.__rmul__, oper)
            self.assertRaises(NotImplementedError, self.hand4.__imul__, oper)
    def test_sort(self):

        """
        Test sort() method.

        """

        h = Hand(namelist=["7D", "3H", "TC", "7H", "QC", "3C"])
        h1 = Hand(namelist=["3C", "3H", "7H", "7D", "TC", "QC"])
        h2 = Hand(namelist=["QC", "TC", "7D", "7H", "3H", "3C"])

        self.assertNotEqual(h.index_list(), h1.index_list())
        h.sort()
        self.assertEqual(h.index_list(), h1.index_list())

        self.assertNotEqual(h.index_list(), h2.index_list())
        h.sort(reverse=True)
        self.assertEqual(h.index_list(), h2.index_list())

        # Test that anything passed as 'key' is ignored.

        self.assertNotEqual(h.index_list(), h1.index_list())
        h.sort(key="Spam Breakfast")
        self.assertEqual(h.index_list(), h1.index_list())
 def setUp(self):
     self.hand1 = Hand(namelist=["AC", "2C", "3C"])
     self.hand2 = Hand(namelist=["4S", "5S", "6S"])
     self.hand3 = Hand(namelist=["AH", "2H"])
     self.hand4 = Hand(namelist=["3D", "4D"])