def test_opening_hand(): a = Card("A") b = Card("B") c = Card("C") d = Deck(a, b, c) t = deck.opening_hand(d, count=1) assert (a in t or b in t or c in t) assert (len(t) == 1) t = deck.opening_hand(d, count=3) assert (a in t or b in t or c in t) assert (len(t) == 3) t = deck.opening_hand(Deck(a, *((b, ) * 6))) assert (len([c for c in t if c == a]) == 1) assert (len([c for c in t if c == b]) == 6)
def test_opening_hand_bad_arguments(): with pytest.raises(ValueError): deck.opening_hand(None) with pytest.raises(ValueError): deck.opening_hand(Deck(), count="Riemann") with pytest.raises(ValueError): deck.opening_hand(Deck(), count=2)
def test_opening_hand_probabilities(): a = Card("A") b = Card("B") c = Card("C") d = Deck(a, b, *((c, ) * 7)) theoretical_a_occurrence = calc.binomial(8, 6) theoretical_b_occurrence = calc.binomial(8, 6) theoretical_c_occurrence = 2 * calc.binomial(7, 6) + calc.binomial( 7, 5) + calc.binomial(7, 7) total = calc.binomial(9, 7) theoretical_a_occurrence = theoretical_a_occurrence / float(total) theoretical_b_occurrence = theoretical_b_occurrence / float(total) theoretical_c_occurrence = theoretical_c_occurrence / float(total) samples = 10000 a_hands = 0 b_hands = 0 c_hands = 0 for i in range(0, samples): t = deck.opening_hand(d, count=7) if a in t: a_hands += 1 if b in t: b_hands += 1 if c in t: c_hands += 1 tolerance = 0.05 assert (abs((a_hands / float(samples)) - theoretical_a_occurrence) <= tolerance) assert (abs((b_hands / float(samples)) - theoretical_b_occurrence) <= tolerance) assert (abs((c_hands / float(samples)) - theoretical_c_occurrence) <= tolerance)
def test_opening_hand_zero_count(): t = deck.opening_hand(Deck(Card("Euler")), count=0) assert (t == ())
(2, "Cavalier of Gales"), (2, "Dream Trawler"), (3, "Kenrith, the Returned King"), (4, "Sphinx of Foresight"), (2, "Aether Gust"), (3, "Deafening Clarion"), (1, "Shimmer of Possibility"), (4, "Fires of Invention"), (4, "Teferi, Time Raveler"), (2, "Castle Vantress"), (3, "Fabled Passage"), (4, "Hallowed Fountain"), (2, "Island"), (2, "Mountain"), (1, "Plains"), (3, "Sacred Foundry"), (4, "Steam Vents"), (3, "Temple of Epiphany"), (3, "Temple of Triumph"), ] def cardify(values): for count, title in values: yield count, Card(title) deck = Deck(*cardify(decklist)) print(opening_hand(deck))