示例#1
0
def test_sets_must_be_three_long_to_count():
    hand = Hand()

    hand.add(Card(rank=Rank.JACK, suit=Suit.HEART))    # 0:  JH
    hand.add(Card(rank=Rank.JACK, suit=Suit.DIAMOND))   # 1:  JD

    md = MeldDetector(*hand.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 0)
示例#2
0
def test_runs_must_be_same_suit():
    hand = Hand()

    hand.add(Card(rank=Rank.JACK, suit=Suit.HEART))
    hand.add(Card(rank=Rank.QUEEN, suit=Suit.HEART))
    hand.add(Card(rank=Rank.KING, suit=Suit.CLUB))

    md = MeldDetector(*hand.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 0)
示例#3
0
def test_optimal_melds_chosen_from_hand_with_overlapping_melds(hand_with_overlapping_sets_and_runs):
    expected_melds = [
        Meld(Card.from_text("2C", "2S", "2D", "2H")),
        Meld(Card.from_text("4D", "5D", "6D"))
    ]
    md = MeldDetector(*hand_with_overlapping_sets_and_runs.cards)
    md.detect_optimal_melds()
    assert(len(md.optimal_hand.melds) == 2)
    for meld in expected_melds:
        assert(meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_count == 3)
    assert(md.optimal_hand.deadwood_value == 28)
示例#4
0
def test_optimal_melds_chosen_from_complex_set(hand_with_complex_sets_and_runs):
    expected_melds = [
        Meld(Card.from_text("2D", "2S", "2H")),
        Meld(Card.from_text("3D", "4D", "5D")),
        Meld(Card.from_text("AC", "2C", "3C"))
    ]
    md = MeldDetector(*hand_with_complex_sets_and_runs.cards)
    md.detect_optimal_melds()
    assert(len(md.optimal_hand.melds) == 3)
    for meld in expected_melds:
        assert(meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_value == 3)
示例#5
0
def test_optimal_melds_chosen_from_simple_hand(hand_with_simple_sets_and_runs):
    expected_melds = [
        Meld(Card.from_text("2C", "2S", "2H")),
        Meld(Card.from_text("9S", "10S", "JS")),
        Meld(Card.from_text("4D", "5D", "6D"))
    ]
    md = MeldDetector(*hand_with_simple_sets_and_runs.cards)
    md.detect_optimal_melds()
    assert(len(md.optimal_hand.melds) == 3)
    for meld in expected_melds:
        assert(meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_count == 1)
    assert(md.optimal_hand.deadwood_value == 4)
示例#6
0
def test_set_and_run_detection(hand_with_overlapping_sets_and_runs):
    expected_melds = [
        Meld(Card.from_text("2C", "2S", "2D", "2H")),
        Meld(Card.from_text("2S", "2D", "2H")),
        Meld(Card.from_text("2C", "2D", "2H")),
        Meld(Card.from_text("2C", "2S", "2H")),
        Meld(Card.from_text("2C", "2S", "2D")),
        Meld(Card.from_text("4D", "5D", "6D"))
    ]
    md = MeldDetector(*hand_with_overlapping_sets_and_runs.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 6)
    for meld in expected_melds:
        assert(meld in md._melds)
示例#7
0
def test_small_hand_is_not_complete():
    hand = Hand()

    hand.add(Card(rank=Rank.JACK, suit=Suit.HEART))    # 0:  JH
    hand.add(Card(rank=Rank.QUEEN, suit=Suit.HEART))   # 1:  QH

    md = MeldDetector(*hand.cards)
    assert(md.is_complete_hand == False)
示例#8
0
def test_optimal_meld_scenario_8():
    h = Hand()
    for card in Card.from_text(
        "4C",
        "4S", "3S", "2S",
        "5H", "4H", "3H", "AH",
        "3D", "2D"
    ):
        h.add(card)

    ## in this scenario, there are two equally optimal outcomes
    optimal_expected_option1 = [
        Meld(Card.from_text("4C", "4S", "4H")),
        Meld(Card.from_text("3H", "3S", "3D"))
    ]
    optimal_expected_option2 = [
        Meld(Card.from_text("4S", "3S", "2S")),
        Meld(Card.from_text("5H", "4H", "3H"))
    ]
    md = MeldDetector(*h.cards)
    md.detect_optimal_melds()

    assert(len(md.optimal_hand.melds) == len(optimal_expected_option1)) # works for either

    is_option_1 = True
    is_option_2 = True

    for expected_meld in optimal_expected_option1:
        if expected_meld not in md.optimal_hand.melds:
            is_option_1 = False

    for expected_meld in optimal_expected_option2:
        if expected_meld not in md.optimal_hand.melds:
            is_option_2 = False

    assert(not (is_option_1 and is_option_2)) #highlander principle
    assert(is_option_1 or is_option_2)

    # b/c the two are equiv. this is true regardless of option
    assert(md.optimal_hand.deadwood_value == 10)
    assert(md.optimal_hand.deadwood_count == 4)
示例#9
0
def test_complex_run_detection(hand_with_complex_runs):
        # (3H, 4H, 5H),
        # (4H, 5H, 6H),
        # (5H, 6H, 7H),
        # (3H, 4H, 5H, 6H),
        # (4H, 5H, 6H, 7H),
        # (3H, 4H, 5H, 6H, 7H),
        # (9C, 10C, JC)
    expected_melds = [
        Meld(Card.from_text("3H", "4H", "5H")),
        Meld(Card.from_text("4H", "5H", "6H")),
        Meld(Card.from_text("5H", "6H", "7H")),
        Meld(Card.from_text("3H", "4H", "5H", "6H")),
        Meld(Card.from_text("4H", "5H", "6H", "7H")),
        Meld(Card.from_text("3H", "4H", "5H", "6H", "7H")),
        Meld(Card.from_text("9C", "10C", "JC"))
    ]
    md = MeldDetector(*hand_with_complex_runs.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 7)
    for meld in expected_melds:
        assert(meld in md._melds)
示例#10
0
def test_optimal_meld_scenario_9():
    # this is a relatively simple scenario - only one card is overused
    h = Hand()
    for card in Card.from_text(
        "6D", "6C", "6H",
        "2H", "3H", "4H",
        "2S", "2C"
    ):
        h.add(card)

    optimal_expected = [
        Meld(Card.from_text("6D", "6C", "6H")),
        Meld(Card.from_text("2H", "3H", "4H"))
    ]
    md = MeldDetector(*h.cards)
    md.detect_optimal_melds()

    assert(len(md.optimal_hand.melds) == len(optimal_expected))
    for expected_meld in optimal_expected:
        assert(expected_meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_value == 4)
    assert(md.optimal_hand.deadwood_count == 2)
示例#11
0
def test_optimal_meld_scenario_6():
    h = Hand()
    for card in Card.from_text(
        "4S", "3S", "2S", "AS",
        "3H", "2H", "AH",
        "4D", "3D", "2D"
    ):
        h.add(card)

    optimal_expected = [
        Meld(Card.from_text("4S", "3S", "2S", "AS")),
        Meld(Card.from_text("3H", "2H", "AH")),
        Meld(Card.from_text("4D", "3D", "2D"))
    ]
    md = MeldDetector(*h.cards)
    md.detect_optimal_melds()

    assert(len(md.optimal_hand.melds) == len(optimal_expected))
    for expected_meld in optimal_expected:
        assert(expected_meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_value == 0)
    assert(md.optimal_hand.deadwood_count == 0)
示例#12
0
def test_optimal_meld_scenario_1():
    h = Hand()
    for card in Card.from_text(
        "10S", "9S", "8S",
        "8H",
        "9C", "8C", "7C", "6C", "5C",
        "KD"
    ):
        h.add(card)

    optimal_expected = [
        Meld(Card.from_text("10S", "9S", "8S")),
        Meld(Card.from_text("9C", "8C", "7C", "6C", "5C"))
    ]
    md = MeldDetector(*h.cards)
    md.detect_optimal_melds()

    assert(len(md.optimal_hand.melds) == len(optimal_expected))
    for expected_meld in optimal_expected:
        assert(expected_meld in md.optimal_hand.melds)
    assert(md.optimal_hand.deadwood_value == 18)
    assert(md.optimal_hand.deadwood_count == 2)
示例#13
0
def test_new_meld_detector_with_no_cards():
    md = MeldDetector()
    assert(isinstance(md, MeldDetector))
    assert(md.size() == 0)
示例#14
0
def test_add_clears_detect_flag(hand_with_simple_runs):
    md = MeldDetector(*hand_with_simple_runs.cards)
    md._detect_all_melds()
    md.add(Card(rank=Rank.SIX, suit=Suit.CLUB))
    assert(md._detected == False)
示例#15
0
def test_correctly_sized_hand_is_complete(hand_with_simple_runs):
    md = MeldDetector(*hand_with_simple_runs.cards) # 10 cards
    assert(md.is_complete_hand == True)
    md.add(Card(rank=Rank.SIX, suit=Suit.CLUB)) # 11 is ok, too
    assert(md.is_complete_hand == True)
示例#16
0
def test_simple_run_detection(hand_with_simple_runs):
    """'simple' here means each run sequence is only 3 long, so no overlap"""
    md = MeldDetector(*hand_with_simple_runs.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 2)
示例#17
0
def test_simple_set_detection(hand_with_sets):
    md = MeldDetector(*hand_with_sets.cards)
    md._detect_all_melds()
    assert(len(md._melds) == 6)
示例#18
0
def test_deadwood_value_is_correct_from_overlapping_hand(hand_with_overlapping_sets_and_runs):
    md = MeldDetector(*hand_with_overlapping_sets_and_runs.cards)
    md.detect_optimal_melds()
    assert(md.optimal_hand.deadwood_value == 28)
示例#19
0
def test_deadwood_count_is_correct_from_simple_hand(hand_with_simple_sets_and_runs):
    md = MeldDetector(*hand_with_simple_sets_and_runs.cards)
    md.detect_optimal_melds()
    assert(md.optimal_hand.deadwood_count == 1)
示例#20
0
def test_new_meld_detector_init_from_hand(hand_with_simple_runs):
    md = MeldDetector(*hand_with_simple_runs.cards)
    assert(isinstance(md, MeldDetector))
    assert(md.size() == 10)