def test_median_error_rate(self): stats = CardStats() for c in Card.generate([1], [Operation.DIV]): stats.add_correct_answer(c, 4.0) stats.add_correct_answer(c, 8.0) stats.add_error(c) stats.add_error(Card(1, Operation.DIV, 1)) median, stddev = stats.median_error_rate( Card.generate([1], [Operation.DIV])) self.assertAlmostEqual(median, 0.3333333333333333) self.assertAlmostEqual(stddev, 0.052704627669472995)
def test_add_error(self): stats = CardStats() stats.add_error(Card(2, Operation.MUL, 2)) c = Card(2, Operation.MUL, 2) self.assertEqual(stats.num_errors(c), 1) stats.add_error(Card(2, Operation.MUL, 2)) c = Card(2, Operation.MUL, 2) self.assertEqual(stats.num_errors(c), 2) self.assertEqual(stats.error_rate(c), 1.0) stats.add_correct_answer(c, 5.0) self.assertAlmostEqual(stats.error_rate(c), 2.0 / 3.0)
def test_median_answer_time_avg(self): stats = CardStats() for c in Card.generate([1], [Operation.DIV]): if c.left % 2 == 0: stats.add_correct_answer(c, 4.0) else: stats.add_correct_answer(c, 8.0) stats.add_correct_answer(Card(10, Operation.DIV, 1), 4.0) median, stddev = stats.median_answer_time_avg( Card.generate([1], [Operation.DIV])) self.assertEqual(median, 6.0) self.assertAlmostEqual(stddev, 2.1081851067789197)
def test_add_timed_result(self): stats = CardStats() card = Card(10, Operation.DIV, 10) stats.add_correct_answer(card, 4.0) stats.add_correct_answer(card, 8.0) self.assertEqual(stats.sum_time(card), 12.0) self.assertEqual(stats.num_correct(card), 2) self.assertEqual(stats.answer_time_avg(card), 6.0)
def start_practice(self): print("starting practice") SelectionsLoader.store(self.get_selections_file(), self.get_selection()) self.state = GameState.PRACTICE self.test_timed_out = False self.enable_controls() self.cards_todo = list(Card.generate(self.get_selection())) shuffle(self.cards_todo) self.show_question_or_feedback() self.feedback.setText("") self.progressBar.setValue(0) self.progressBar.setMaximum(len(self.cards_todo))
def fill_stats(selections): stats = CardStats() cards = list(Card.generate(selections)) for card in cards: num_times = int(uniform(1, 10)) num_err = int(uniform(0, 2)) for i in range(0, num_times): time = abs(random.gauss(3.0, 2.0)) stats.add_correct_answer(card, time) for i in range(0, num_err): stats.add_error(card) return stats
def test_generator(self): table_of_2 = list(Card.generate([2])) self.assertEqual(table_of_2[0], Card(1, Operation.MUL, 2)) self.assertEqual(table_of_2[4], Card(5, Operation.MUL, 2)) self.assertEqual(table_of_2[14], Card(10, Operation.DIV, 2)) self.assertEqual(table_of_2[19], Card(20, Operation.DIV, 2)) all_tables = list(Card.generate(range(1, 11))) self.assertEqual(len(all_tables), 200) self.assertEqual(all_tables[0], Card(1, Operation.MUL, 1)) self.assertEqual(all_tables[42], Card(5, Operation.MUL, 3)) self.assertEqual(all_tables[55], Card(6, Operation.MUL, 6)) self.assertEqual(all_tables[100], Card(1, Operation.DIV, 1)) self.assertEqual(all_tables[132], Card(12, Operation.DIV, 3)) self.assertEqual(all_tables[199], Card(100, Operation.DIV, 10))
def test_value(self): card = Card(2, Operation.MUL, 4) self.assertEqual(card.answer(), 8) card = Card(20, Operation.DIV, 4) self.assertEqual(card.answer(), 5)
def test_to_str(self): card = Card(2, Operation.MUL, 4) self.assertEqual(str(card), "2 x 4")