示例#1
0
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)
示例#2
0
def test_deck_constructor_tuples():
    a = Card("Riemann")
    b = Card("Kolmogorov")

    d = Deck(a, (4, b))

    assert (len(d) == 5)
    assert (d.count(a) == 1)
    assert (d.count(b) == 4)
示例#3
0
def test_deck_constructor_not_empty():
    a = Card("Riemann")
    b = Card("Euler")

    d = Deck(a, b)
    assert (len(d) == 2)
    assert (d[0] is a)
    assert (d[1] is b)
示例#4
0
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)
示例#5
0
def test_deck_contains():
    a = Card("Riemann")
    b = Card("Euler")
    c = Card("Martin-Löf")

    deck = Deck(a, b)

    assert (a in deck)
    assert (b in deck)
    assert (c not in deck)
示例#6
0
def test_tally():
    cards = [
        Card(n) for n in ["Riemann", "Euler", "Euler", "Riemann", "Gauss"]
    ]
    d = Deck(*cards)

    t = deck.tally(d)

    t = list(t)

    assert (len(t) == 3)

    assert ((Card("Riemann"), 2) in t)
    assert ((Card("Euler"), 2) in t)
    assert ((Card("Gauss"), 1) in t)
示例#7
0
def test_deck_constructor_bad_inputs():
    with pytest.raises(ValueError):
        Deck(1)

    with pytest.raises(ValueError):
        Deck(Card("Riemann"), Card("Euler"), True)

    with pytest.raises(ValueError):
        Deck((Card("Riemann"), ))

    with pytest.raises(TypeError):
        Deck((None, Card("Riemann")))

    with pytest.raises(ValueError):
        Deck((-1, Card("Riemann")))

    with pytest.raises(ValueError):
        Deck((2, "Kolmogorov"))

    with pytest.raises(ValueError):
        Deck((2, Card("Riemann"), "Anything"))
示例#8
0
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)
示例#9
0
def test_tally_empty_deck():
    assert (list(deck.tally(Deck())) == [])
示例#10
0
def test_deck_empty_equals_empty():
    assert (Deck() == Deck())
示例#11
0
def test_deck_constructor_empty():
    d = Deck()

    assert d.empty
示例#12
0
def test_opening_hand_zero_count():
    t = deck.opening_hand(Deck(Card("Euler")), count=0)
    assert (t == ())
示例#13
0
    (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))