Example #1
0
def test_not_memoized_pair_score_and_topic():
    match_maker = MatchMaker(match_request_since_date='does not matter')
    now = datetime.now().astimezone(timezone.utc)
    match_maker._recent_match_by_profile_pair = {
        key('A', 'B'): {
            'date': now - timedelta(weeks=20)
        },
    }
    match_maker._most_recent_match_by_profile = {
        key('A'): {
            'date': now - timedelta(weeks=20)
        },
        key('B'): {
            'date': now - timedelta(weeks=20)
        },
    }
    match_maker._recent_match_by_profile_pair_and_topic = {
        key('A', 'B', 'science'): {
            'date': now - timedelta(weeks=10)
        },
        key('A', 'B', 'art'): {
            'date': now - timedelta(weeks=20)
        },
    }
    match_maker._match_requests_profile_to_topic = {
        'A': {'science', 'art', 'history'},
        'B': {'science', 'art', 'religion'},
    }
    score, topic = match_maker._not_memoized_pair_score_and_topic('A', 'B')
    assert score > 0
    assert score != int(
        score
    ), "score is a whole number, that's unlikely if we're really exercising the functionality"
    assert topic == 'art'
Example #2
0
def test_penalty_based_on_recent_pairing():
    match_maker = MatchMaker(match_request_since_date='does not matter')
    now = datetime.now().astimezone(timezone.utc)
    match_maker._recent_match_by_profile_pair = {
        key('A', 'B'): {
            'date': now - timedelta(days=1)
        },
        key('A', 'C'): {
            'date': now - timedelta(weeks=10)
        },
        key('A', 'D'): {
            'date': now - timedelta(weeks=20)
        },
        # key('A', 'E'): {'date': now - infinity},  <- no entry is treated as never having met
    }
    scoreAB = match_maker._penalty_based_on_recent_pairing('A', 'B')
    scoreAC = match_maker._penalty_based_on_recent_pairing('A', 'C')
    scoreAD = match_maker._penalty_based_on_recent_pairing('A', 'D')
    scoreAE = match_maker._penalty_based_on_recent_pairing('A', 'E')
    assert scoreAB > scoreAC > scoreAD > scoreAE, 'the penalty is greater if they have met more recently'
    assert scoreAB == float(
        'infinity'), 'having just met implies "infinite" penalty'