def test_avoid_accidental_reveal(self): rainbow_card = HanabiCard(HanabiColor.RAINBOW, 2) self.assertEqual("??", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R?", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R?", rainbow_card.known())
def test_hand_with_rainbow_cards(self): card1 = HanabiCard(HanabiColor.RED, 2) card2 = HanabiCard(HanabiColor.RAINBOW, 2) hand = HanabiHand() hand.add(card1) hand.add(card2) self.assertEqual(["??", "??"], hand.show_cards(True)) hand.disclose_color(HanabiColor.RED, True) self.assertEqual(["R?", "R?"], hand.show_cards(True)) hand.disclose_color(HanabiColor.GREEN, True) self.assertEqual(["R?", "*?"], hand.show_cards(True))
def __init__(self, seed, variant=HanabiVariant.basic): colors = [HanabiColor.BLUE, HanabiColor.GREEN, HanabiColor.RED, HanabiColor.YELLOW, HanabiColor.WHITE] self.deck = [HanabiCard(color, 1) for _ in range(0, 3) for color in colors] self.deck.extend([HanabiCard(color, rank) for _ in range(0, 2) for rank in range(2, 5) for color in colors]) self.deck.extend([HanabiCard(color, 5) for color in colors]) self.add_rainbow(variant) random.seed(seed) random.shuffle(self.deck)
def test_play_incorrect_rainbow(self): self.table.play_card(0, 2) self.table.play_card(0, 4) self.assertEqual(1, self.table.score()) self.assertEqual(2, self.table.mistakes_left) self.assertTrue( HanabiCard(HanabiColor.RAINBOW, 2) in self.table.discard.discarded())
def add_rainbow(self, variant): if variant != HanabiVariant.basic: num_ones = { HanabiVariant.sixth_suit: 3, HanabiVariant.sixth_suit_hard: 1, HanabiVariant.rainbow_wild: 3 }[variant] num_cards = { HanabiVariant.sixth_suit: 2, HanabiVariant.sixth_suit_hard: 1, HanabiVariant.rainbow_wild: 2 }[variant] self.deck.extend([HanabiCard(HanabiColor.RAINBOW, 1) for _ in range(0, num_ones)]) self.deck.extend([HanabiCard(HanabiColor.RAINBOW, rank) for _ in range(0, num_cards) for rank in range(2, 5)]) self.deck.append(HanabiCard(HanabiColor.RAINBOW, 5))
def setUp(self): self.unknown_card = HanabiCard(HanabiColor.RED, 5) self.known_card = HanabiCard(HanabiColor.BLUE, 1) self.known_card.disclose_color(HanabiColor.BLUE) self.known_card.disclose_rank() self.rank_known_card = HanabiCard(HanabiColor.GREEN, 3) self.rank_known_card.disclose_rank()
def setUp(self): self.discard = HanabiDiscard() self.to_discard = HanabiCard(HanabiColor.RED, 3)
def test_rainbow_card(self): rainbow_card = HanabiCard(HanabiColor.RAINBOW, 2) self.assertEqual("*2", str(rainbow_card)) self.assertEqual("??", rainbow_card.known()) rainbow_card.disclose_rank() self.assertEqual("?2", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R2", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.GREEN, True) self.assertEqual("*2", rainbow_card.known())
def test_eq(self): self.assertEqual(self.rank_known_card, HanabiCard(HanabiColor.GREEN, 3))
class HanabiCardTests(unittest.TestCase): def setUp(self): self.unknown_card = HanabiCard(HanabiColor.RED, 5) self.known_card = HanabiCard(HanabiColor.BLUE, 1) self.known_card.disclose_color(HanabiColor.BLUE) self.known_card.disclose_rank() self.rank_known_card = HanabiCard(HanabiColor.GREEN, 3) self.rank_known_card.disclose_rank() def test_unknown_card_color(self): self.assertEqual(self.unknown_card.color, HanabiColor.RED) def test_known_card_color(self): self.assertEqual(self.known_card.color, HanabiColor.BLUE) def test_rank_known_card_color(self): self.assertEqual(self.rank_known_card.color, HanabiColor.GREEN) def test_unknow_card_rank(self): self.assertEqual(self.unknown_card.rank, 5) def test_known_card_rank(self): self.assertEqual(self.known_card.rank, 1) def test_rank_known_card_rank(self): self.assertEqual(self.rank_known_card.rank, 3) def test_unknown_card_str(self): self.assertEqual(str(self.unknown_card), "R5") def test_known_card_str(self): self.assertEqual(str(self.known_card), "B1") def test_rank_known_card_str(self): self.assertEqual(str(self.rank_known_card), "G3") def test_unknown_card_known(self): self.assertEqual(self.unknown_card.known(), "??") def test_known_card_known(self): self.assertEqual(self.known_card.known(), "B1") def test_rank_known_card_known(self): self.assertEqual(self.rank_known_card.known(), "?3") def test_eq(self): self.assertEqual(self.rank_known_card, HanabiCard(HanabiColor.GREEN, 3)) def test_ne(self): self.assertNotEqual(self.known_card, self.rank_known_card) def test_rainbow_card(self): rainbow_card = HanabiCard(HanabiColor.RAINBOW, 2) self.assertEqual("*2", str(rainbow_card)) self.assertEqual("??", rainbow_card.known()) rainbow_card.disclose_rank() self.assertEqual("?2", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R2", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.GREEN, True) self.assertEqual("*2", rainbow_card.known()) def test_avoid_accidental_reveal(self): rainbow_card = HanabiCard(HanabiColor.RAINBOW, 2) self.assertEqual("??", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R?", rainbow_card.known()) rainbow_card.disclose_color(HanabiColor.RED, True) self.assertEqual("R?", rainbow_card.known())
def setUp(self): self.hand = HanabiHand() self.hand.add(HanabiCard(HanabiColor.BLUE, 2)) self.hand.add(HanabiCard(HanabiColor.GREEN, 5)) self.hand.add(HanabiCard(HanabiColor.BLUE, 1))
def test_hand_add_card(self): self.hand.add(HanabiCard(HanabiColor.WHITE, 1)) self.assertEqual(self.hand.card_at(2), HanabiCard(HanabiColor.BLUE, 1))
def test_hand_remove_card_at(self): card = self.hand.remove_card_at(0) self.assertEqual(card, HanabiCard(HanabiColor.BLUE, 2))
def test_hand_card_at(self): self.assertEqual(self.hand.card_at(0), HanabiCard(HanabiColor.BLUE, 2))