Example #1
0
    def test_record_answer(self):
        q.record_answer(1, 1)
        ans_q = 'SELECT count FROM answers WHERE word_id = 1 AND translation_id = 1'
        self.assertEqual(q.db.sql(ans_q).fetchone()[0], 1)

        q.record_answer(1, 1)
        self.assertEqual(q.db.sql(ans_q).fetchone()[0], 2)
Example #2
0
    def test_hardest_select(self):
        a, b, c = insert_words(*'abc')

        q.record_answer(a, a) # one correct for a
        q.record_answer(c, b) # not correct for c

        self.assertEqual(q.select_most_hard_words_ids(3), [c, b, a])
Example #3
0
    def test_get_translation_variants(self):
        a, b, c, d = insert_words(*'abcd')

        q.record_answer(a, b) 

        res = q.get_translation_variants(a, 3)
        self.assertIn(b, res)
        self.assertIn(a, res)
        self.assertEqual(len(res), 3)
Example #4
0
    def test_hardest_and_random(self):
        a, b, c = insert_words(*'abc')

        q.record_answer(c, b) # not correct for c

        res = q.select_most_hard_words_ids(3)

        self.assertEqual(res[0], c)
        self.assertIn(a, res)
        self.assertIn(b, res)
Example #5
0
def cram(count):
    words_ids = q.select_most_hard_words_ids(count)
    for word_id in words_ids:
        variant_ids = q.get_translation_variants(word_id, 4)
        word, t = q.get_word_and_translation(word_id)
        variants = [q.get_word_and_translation(id)[1] for id in variant_ids]
        answer = choice_question(word, variants)
        answer_id = variant_ids[answer]
        q.record_answer(word_id, variant_ids[answer])
        if answer_id == word_id:
            print(_("Correct!"))
        else:
            print(_('Wrong! "{word}" is correctly translated as "{translation}"').format(word=word, translation=t))
Example #6
0
    def test_remembered(self):
        a, b, c, d = insert_words(*'abcd')

        q.record_answer(c, c)
        self.assertEqual(q.select_remembered(1)[0][0], 'c')