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'
def test_boost_based_upon_recency_of_match(): match_maker = MatchMaker(match_request_since_date='does not matter') now = datetime.now().astimezone(timezone.utc) match_maker._most_recent_match_by_profile = { key('A'): { 'date': now }, key('B'): { 'date': now - timedelta(weeks=1) }, key('C'): { 'date': now - timedelta(weeks=2) }, # key('D'): {'date': now - infinity}, <- no entry is treated as never having met # key('E'): {'date': now - infinity}, <- no entry is treated as never having met } scoreAB = match_maker._boost_based_upon_recency_of_match('A', 'B') scoreAC = match_maker._boost_based_upon_recency_of_match('A', 'C') scoreAD = match_maker._boost_based_upon_recency_of_match('A', 'D') scoreDE = match_maker._boost_based_upon_recency_of_match('D', 'E') assert scoreAB < scoreAC < scoreAD < scoreDE, 'there is a larger boost for those who have not met in a while' assert scoreDE == 2, \ 'boosts of the individual profiles are additive, and if a player has never been in a match their boost is 1'