Engine: Card a farby/hodnoty su hashovatelne

Vlastne __eq__ rusilo zdedeny __hash__, takze karty ani enumy sa nedali
pouzit ako kluce dictov a v setoch. Hash doplneny konzistentne s __eq__.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tim
2026-07-07 18:49:55 +02:00
co-authored by Claude Fable 5
parent f17f85ebd9
commit 1b14ace2cd
2 changed files with 22 additions and 0 deletions
+10
View File
@@ -121,6 +121,16 @@ class StashCase(unittest.TestCase):
self.assertRaises(BridzikException, s.get_active_player)
class CardCase(unittest.TestCase):
def test_hashable_consistent_with_eq(self):
# vlastne __eq__ nesmie zrusit hashovatelnost (dict/set pouzitie)
heart_7 = Card(Card_colors['HEARTS'], Card_values['C7'])
self.assertEqual(hash(heart_7), hash(Card(Card_colors['HEARTS'], Card_values['C7'])))
self.assertEqual(len(set(cards)), 32)
self.assertEqual({Card_colors['HEARTS']: 1}[Card_colors['HEARTS']], 1)
self.assertEqual({Card_values['ACE']: 1}[Card_values['ACE']], 1)
class RoundCase(unittest.TestCase):
def test_round_constructor(self):
self.assertRaises(BridzikException, Round, round_number=8, first_player=0)