Last active
December 16, 2015 07:28
-
-
Save treyhunner/5398647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from unittest import TestCase, main | |
from turn_picker import score | |
class TurnPickerTest(TestCase): | |
def test_score_low_vs_high_attendance(self): | |
self.assertGreater(score(2, 10, 0), score(50, 200, 12)) | |
self.assertLess(score(3, 15, 0), score(50, 200, 12)) | |
def test_score_ab_two_events(self): | |
# A has watched B's movie | |
# B should watch A's movie | |
self.assertTrue(score(1, 2, 0) < score(1, 2, 1)) | |
def test_around_zero(self): | |
self.assertGreater(score(1, 2, 0), 0) | |
self.assertEqual(score(2, 4, 0), 0) | |
self.assertLess(score(3, 6, 0), 0) | |
def test_score_ab_lots_of_events(self): | |
# A has watched B's movie | |
# B has gone to many movie nights, A has only gone to 1 | |
# B should watch A's movie on the third time | |
self.assertGreater(score(1, 2, 0), score(40, 80, 19)) | |
self.assertEqual(score(2, 4, 0), score(40, 80, 19)) | |
def test_average_attendance_difference(self): | |
self.assertLess(score(3, 15, 1), score(3, 115, 1)) | |
def test_large_numbers(self): | |
# Many vs. Few events attended | |
self.assertLess(score(100, 400, 24), score(10000, 40000, 2500)) | |
self.assertGreater(score(100, 400, 25), score(10000, 40000, 2499)) | |
self.assertEqual(score(100, 400, 24), score(10000, 40000, 2499)) | |
# Low vs. High attendance | |
self.assertLess(score(100, 400, 25), score(100, 1000, 10)) | |
self.assertGreater(score(100, 400, 25), score(100, 1000, 9)) | |
self.assertLess(score(100, 400, 24), score(100, 1000, 10)) | |
self.assertEqual(score(100, 400, 24), score(100, 1000, 9)) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from math import log | |
def score(events_attended, people_attended, times_picked): | |
average_attendance = people_attended / events_attended | |
exp_score = average_attendance * (times_picked + 1) / events_attended | |
return log(exp_score, average_attendance) * people_attended |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment