예제 #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'
예제 #2
0
def test_select_topic():
    match_maker = MatchMaker(match_request_since_date='does not matter')
    now = datetime.now().astimezone(timezone.utc)
    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)
        },
    }
    met_recently = True

    topics = {'science', 'art', 'history'}
    selected_topic = match_maker._select_topic('A', 'B', met_recently, topics)
    assert selected_topic == 'history', 'choose the topic they have not yet met in'

    topics = {'science', 'art'}
    selected_topic = match_maker._select_topic('A', 'B', met_recently, topics)
    assert selected_topic == 'art', 'if they have already met in all topics, choose the least recent topic'