Пример #1
0
def test_matchmaker_performance(p, bench, caplog):
    # Disable debug logging for performance
    caplog.set_level(logging.INFO)
    NUM_SEARCHES = 200

    searches = [
        Search([p(1500, 500, ladder_games=1)]) for _ in range(NUM_SEARCHES)
    ]

    with bench:
        algorithm.make_matches(searches)

    assert bench.elapsed() < 0.5
def test_matchmaker(player_factory):
    newbie_that_matches1 = Search([player_factory(1450, 500, ladder_games=1)])
    newbie_that_matches2 = Search([player_factory(1550, 500, ladder_games=1)])
    newbie_force_matched = Search([player_factory(200, 400, ladder_games=9)])

    pro_that_matches1 = Search([player_factory(1800, 60, ladder_games=101)])
    pro_that_matches1.register_failed_matching_attempt()
    pro_that_matches2 = Search([player_factory(1750, 50, ladder_games=100)])
    pro_that_matches2.register_failed_matching_attempt()
    pro_alone = Search([player_factory(1550, 50, ladder_games=100)])
    pro_alone.register_failed_matching_attempt()

    top_player = Search([player_factory(2100, 50, ladder_games=200)])
    top_player.register_failed_matching_attempt()

    searches = [
        newbie_that_matches1, newbie_that_matches2, newbie_force_matched,
        pro_that_matches1, pro_that_matches2, pro_alone, top_player
    ]
    match_pairs = algorithm.make_matches(searches)
    match_sets = [set(pair) for pair in match_pairs]

    assert {newbie_that_matches1, newbie_that_matches2} in match_sets
    assert {pro_that_matches1, pro_that_matches2} in match_sets
    assert {newbie_force_matched, pro_alone} in match_sets
    for match_pair in match_pairs:
        assert top_player not in match_pair
def test_matchmaker_random_only(player_factory):
    newbie1 = Search([player_factory(1550, 500, ladder_games=1)])
    newbie2 = Search([player_factory(200, 400, ladder_games=9)])

    searches = (newbie1, newbie2)
    match_pairs = algorithm.make_matches(searches)
    match_sets = [set(pair) for pair in match_pairs]

    assert {newbie1, newbie2} in match_sets
def test_make_matches_will_not_match_low_quality_games(player_factory):
    s1 = Search([player_factory(100, 64, name="p1")])
    s2 = Search([player_factory(2000, 64, name="p2")])

    searches = [s1, s2]

    matches = algorithm.make_matches(searches)

    assert (s1, s2) not in matches
    assert (s2, s1) not in matches
Пример #5
0
def test_make_matches_will_not_match_low_quality_games(p):
    s1 = Search([p(100, 64, name='p1')])
    s2 = Search([p(2000, 64, name='p2')])

    searches = [s1, s2]

    matches = algorithm.make_matches(searches)

    assert (s1, s2) not in matches
    assert (s2, s1) not in matches
def test_make_matches_communicates_failed_attempts(player_factory):
    s1 = Search([player_factory(100, 64, name="p1")])
    s2 = Search([player_factory(2000, 64, name="p2")])

    searches = [s1, s2]

    assert s1.failed_matching_attempts == 0
    assert s2.failed_matching_attempts == 0

    matches = algorithm.make_matches(searches)

    # These searches should not have been matched
    assert not matches
    assert s1.failed_matching_attempts == 1
    assert s2.failed_matching_attempts == 1