def test_add_fail(self): alice = CBUser.from_slackid('UALICE', 'alice') a, t = alice.add_mini_crossword_time(-1, parse_date(None)) self.assertTrue(a) self.assertEqual(t.seconds, -1) self.assertEqual(t.date, parse_date(None)) self.assertTrue(t.is_fail())
def test_add_time(self): alice = CBUser.from_slackid('UALICE', 'alice') a, t = alice.add_mini_crossword_time(10, parse_date(None)) self.assertTrue(a) self.assertEqual(t.user, alice) self.assertEqual(t.seconds, 10) self.assertEqual(t.date, parse_date(None)) self.assertEqual(alice.get_mini_crossword_time(parse_date(None)), t)
def test_crossbucks_add_remove(self): # Checks that removing a time actually removes crossbucks alice = CBUser.from_slackid('UALICE', 'alice') alice.add_mini_crossword_time(10, parse_date(None)) self.assertEqual(alice.crossbucks, CROSSBUCKS_PER_SOLVE) alice.add_mini_crossword_time(10, parse_date(None)) self.assertEqual(alice.crossbucks, CROSSBUCKS_PER_SOLVE) alice.remove_mini_crossword_time(parse_date(None)) self.assertEqual(alice.crossbucks, 0) alice.remove_mini_crossword_time(parse_date(None)) self.assertEqual(alice.crossbucks, 0) alice.add_mini_crossword_time(10, parse_date(None)) self.assertEqual(alice.crossbucks, CROSSBUCKS_PER_SOLVE)
def test_announcement(self): self.run_predictor() announce_data = MiniCrosswordTime.announcement_data( parse_date("2018-01-03")) self.assertIn('overperformers', announce_data) self.assertEqual([u for u, r in announce_data['overperformers']], ['U2']) self.assertIn('difficulty', announce_data) self.assertLess(announce_data['difficulty'], 0)
def test_wins(self): alice = CBUser.from_slackid('UALICE', 'alice') bob = CBUser.from_slackid('UBOB', 'bob') d = {x: parse_date('2018-01-0' + str(x)) for x in range(1, 6)} # make sure winners is empty right now self.assertEqual([], MiniCrosswordTime.winners(d[1])) # alice wins _, a1 = alice.add_mini_crossword_time(10, d[1]) _, b1 = bob.add_mini_crossword_time(11, d[1]) # they tie _, a2 = alice.add_mini_crossword_time(15, d[2]) _, b2 = bob.add_mini_crossword_time(15, d[2]) # bob wins _, a3 = alice.add_mini_crossword_time(21, d[3]) _, b3 = bob.add_mini_crossword_time(20, d[3]) # alice wins _, a4 = alice.add_mini_crossword_time(18, d[4]) _, b4 = bob.add_mini_crossword_time(19, d[4]) # check the winners self.assertEqual([a1], MiniCrosswordTime.winners(d[1])) self.assertEqual([a2, b2], MiniCrosswordTime.winners(d[2])) self.assertEqual([b3], MiniCrosswordTime.winners(d[3])) self.assertEqual([a4], MiniCrosswordTime.winners(d[4])) # check the winning times winning_times = MiniCrosswordTime.winning_times() expected = {d[1]: 10, d[2]: 15, d[3]: 20, d[4]: 18} self.assertEqual(winning_times, expected) # check the actual wins a_wins = MiniCrosswordTime.wins(alice) self.assertEqual(a_wins, [a1, a2, a4]) b_wins = MiniCrosswordTime.wins(bob) self.assertEqual(b_wins, [b2, b3]) # check the streaks a_win_streaks = MiniCrosswordTime.win_streaks(alice) self.assertEqual(a_win_streaks, [[a1, a2], [a4]]) b_win_streaks = MiniCrosswordTime.win_streaks(bob) self.assertEqual(b_win_streaks, [[b2, b3]]) # check the win streaks self.assertEqual({ alice: [a1, a2], bob: [b2] }, MiniCrosswordTime.current_win_streaks(d[2])) self.assertEqual({bob: [b2, b3]}, MiniCrosswordTime.current_win_streaks(d[3])) self.assertEqual({}, MiniCrosswordTime.current_win_streaks(d[5]))
def setUp(self): super().setUp() self.maxDiff = None for u, ts in self.data.items(): user = CBUser(slackid=u) user.save() for i, t in enumerate(ts): if t is not None: user.add_mini_crossword_time( t, parse_date("2018-01-0" + str(i + 1)))
def test_streak(self): alice = CBUser.from_slackid('UALICE', 'alice') # set up a broken 10 streak _, t1 = alice.add_mini_crossword_time(18, parse_date('2018-01-01')) _, t2 = alice.add_mini_crossword_time(12, parse_date('2018-01-02')) _, t3 = alice.add_mini_crossword_time(12, parse_date('2018-01-03')) _, t4 = alice.add_mini_crossword_time(15, parse_date('2018-01-04')) # t5 is missing _, t6 = alice.add_mini_crossword_time(15, parse_date('2018-01-06')) _, t7 = alice.add_mini_crossword_time(15, parse_date('2018-01-07')) _, t8 = alice.add_mini_crossword_time(15, parse_date('2018-01-08')) _, t9 = alice.add_mini_crossword_time(15, parse_date('2018-01-09')) _, t0 = alice.add_mini_crossword_time(18, parse_date('2018-01-10')) # make sure the streak is broken streaks = MiniCrosswordTime.participation_streaks(alice) self.assertListEqual(streaks, [[t1, t2, t3, t4], [t6, t7, t8, t9, t0]]) # fix the broken streak _, t5 = alice.add_mini_crossword_time(15, parse_date('2018-01-05')) streaks = MiniCrosswordTime.participation_streaks(alice) self.assertListEqual(streaks, [[t1, t2, t3, t4, t5, t6, t7, t8, t9, t0]]) # now break it again with a deleted time (t2) alice.remove_mini_crossword_time(parse_date('2018-01-02')) streaks = MiniCrosswordTime.participation_streaks(alice) self.assertListEqual(streaks, [[t1], [t3, t4, t5, t6, t7, t8, t9, t0]])