Esempio n. 1
0
    def test_fit_for_study(self):
        random_bookmarks = [BookmarkRule(self.user).bookmark for _ in range(0, 2)]
        random_exercise = ExerciseRule().exercise
        random_exercise.outcome = OutcomeRule().wrong

        random_bookmarks[0].starred = True
        random_bookmarks[1].starred = True
        random_bookmarks[1].add_new_exercise(random_exercise)

        for b in random_bookmarks:
            assert b.fit_for_study
Esempio n. 2
0
    def test_is_learned_based_on_exercise_outcomes(self):
        random_bookmarks = [BookmarkRule(self.user).bookmark for _ in range(0, 4)]

        # Empty exercise_log should lead to a False return
        learned = is_learned_based_on_exercise_outcomes(
            SortedExerciseLog(random_bookmarks[0])
        )
        assert not learned

        # An exercise with Outcome equal to TOO EASY results in True, and time of last exercise
        random_exercise = ExerciseRule().exercise
        random_exercise.outcome = OutcomeRule().too_easy
        random_bookmarks[1].add_new_exercise(random_exercise)
        learned = is_learned_based_on_exercise_outcomes(
            SortedExerciseLog(random_bookmarks[1])
        )
        result_time = SortedExerciseLog(random_bookmarks[1]).last_exercise_time()
        assert learned and result_time == random_exercise.time

        # Same test as above, but without a second return value
        learned = is_learned_based_on_exercise_outcomes(
            SortedExerciseLog(random_bookmarks[1])
        )
        assert learned

        # A bookmark with CORRECTS_IN_A_ROW_FOR_LEARNED correct exercises in a row
        # returns true and the time of the last exercise
        correct_bookmark = random_bookmarks[2]
        exercises = 0
        distinct_dates = set()
        while not (
            exercises >= CORRECTS_IN_A_ROW_FOR_LEARNED
            and len(distinct_dates) >= CORRECTS_IN_DISTINCT_DAYS_FOR_LEARNED
        ):
            correct_exercise = ExerciseRule().exercise
            correct_exercise.outcome = OutcomeRule().correct
            correct_bookmark.add_new_exercise(correct_exercise)
            exercises += 1
            distinct_dates.add(correct_exercise.time.date())

        correct_bookmark.update_learned_status(self.db.session)

        log = SortedExerciseLog(correct_bookmark)
        learned = is_learned_based_on_exercise_outcomes(log)
        result_time = log.last_exercise_time()
        assert learned

        log = SortedExerciseLog(correct_bookmark)
        learned_time_from_log = log.last_exercise_time()
        assert result_time == learned_time_from_log

        # A bookmark with no TOO EASY outcome or less than 5 correct exercises in a row returns False, None
        wrong_exercise = ExerciseRule().exercise
        wrong_exercise.outcome = OutcomeRule().wrong
        random_bookmarks[3].add_new_exercise(wrong_exercise)

        log = SortedExerciseLog(random_bookmarks[3])
        learned = is_learned_based_on_exercise_outcomes(log)
        assert not learned
Esempio n. 3
0
    def test_has_been_learned(self):
        random_bookmarks = [
            BookmarkRule(self.user).bookmark for _ in range(0, 2)
        ]

        random_exercise = ExerciseRule().exercise
        random_exercise.outcome = OutcomeRule().too_easy
        random_bookmarks[0].add_new_exercise(random_exercise)
        result_bool, result_time = random_bookmarks[0].has_been_learned(
            also_return_time=True)
        assert result_bool and result_time == random_bookmarks[0].exercise_log[
            -1].time

        result_bool, result_None = random_bookmarks[1].has_been_learned(
            also_return_time=True)
        assert not result_bool and result_None is None
Esempio n. 4
0
    def test_add_new_exercise(self):
        random_bookmark = BookmarkRule(self.user).bookmark
        length_original_exercise_log = len(random_bookmark.exercise_log)

        random_exercise = ExerciseRule().exercise
        random_bookmark.add_new_exercise(random_exercise)
        length_new_exercise_log = len(random_bookmark.exercise_log)

        assert length_original_exercise_log < length_new_exercise_log
Esempio n. 5
0
    def test_latest_exercise_outcome(self):
        random_bookmark = self.user.all_bookmarks()[0]
        assert random_bookmark.latest_exercise_outcome() is None

        random_exercise = ExerciseRule().exercise
        random_bookmark.add_new_exercise(random_exercise)

        assert random_exercise.outcome == random_bookmark.latest_exercise_outcome(
        )
Esempio n. 6
0
    def test_latest_exercise_outcome(self):
        random_bookmark = self.user.all_bookmarks()[0]
        exercise_log = SortedExerciseLog(random_bookmark)
        assert exercise_log.latest_exercise_outcome() is None

        random_exercise = ExerciseRule().exercise
        random_bookmark.add_new_exercise(random_exercise)

        assert random_exercise.outcome == SortedExerciseLog(random_bookmark).latest_exercise_outcome()
Esempio n. 7
0
    def test_check_if_learned_based_on_exercise_outcomes(self):
        random_bookmarks = [
            BookmarkRule(self.user).bookmark for _ in range(0, 4)
        ]

        # Empty exercise_log should lead to a False return
        assert not random_bookmarks[
            0].check_if_learned_based_on_exercise_outcomes()

        # An exercise with Outcome equal to TOO EASY results in True, and time of last exercise
        random_exercise = ExerciseRule().exercise
        random_exercise.outcome = OutcomeRule().too_easy
        random_bookmarks[1].add_new_exercise(random_exercise)
        result_bool, result_time = random_bookmarks[
            1].check_if_learned_based_on_exercise_outcomes(
                add_to_result_time=True)
        assert result_bool and result_time == random_exercise.time

        # Same test as above, but without a second return value
        assert random_bookmarks[1].check_if_learned_based_on_exercise_outcomes(
        )

        # A bookmark with 5 correct exercises in a row returns true and the time of the last exercise
        for i in range(0, 5):
            correct_exercise = ExerciseRule().exercise
            correct_exercise.outcome = OutcomeRule().correct
            random_bookmarks[2].add_new_exercise(correct_exercise)

        result_bool, result_time = random_bookmarks[
            2].check_if_learned_based_on_exercise_outcomes()
        assert result_bool and result_time == random_bookmarks[2].exercise_log[
            -1].time

        random_bookmarks[2].update_learned_status(self.db.session)

        # A bookmark with no TOO EASY outcome or less than 5 correct exercises in a row returns False, None
        wrong_exercise = ExerciseRule().exercise
        wrong_exercise.outcome = OutcomeRule().wrong
        random_bookmarks[3].add_new_exercise(wrong_exercise)
        result_bool, result_None = random_bookmarks[
            3].check_if_learned_based_on_exercise_outcomes(
                add_to_result_time=True)
        assert not result_bool and result_None is None

        # Same as before, but without a second return value
        assert not random_bookmarks[
            3].check_if_learned_based_on_exercise_outcomes()
Esempio n. 8
0
    def test_add_exercise_outcome(self):
        random_bookmark = BookmarkRule(self.user).bookmark
        random_exercise = ExerciseRule().exercise
        random_bookmark.add_new_exercise_result(random_exercise.source,
                                                random_exercise.outcome,
                                                random_exercise.solving_speed)
        latest_exercise = random_bookmark.exercise_log[-1]

        assert latest_exercise.source == random_exercise.source
        assert latest_exercise.outcome == random_exercise.outcome
        assert latest_exercise.solving_speed == random_exercise.solving_speed
Esempio n. 9
0
    def add_bookmarks(self, bookmark_count, exercises_count=0, **kwargs):
        bookmark_rules = []

        for _ in range(bookmark_count):
            bookmark_rule = BookmarkRule(self.user, **kwargs)
            bookmark = bookmark_rule.bookmark

            for i in range(0, exercises_count):
                random_exercise = ExerciseRule().exercise
                bookmark.add_new_exercise(random_exercise)

            bookmark_rules.append(bookmark_rule)
        return bookmark_rules
    def test_just_finished_bookmark_has_not_the_highest_priority(self):
        # GIVEN
        ABTesting._algorithms = [ABTesting._algorithms[random.randint(0, len(ABTesting._algorithms) - 1)]]
        arts.update_bookmark_priority(zeeguu_core.db, self.user)
        first_bookmark_to_study = self.__get_bookmark_with_highest_priority()

        # WHEN
        # Add an exercise
        exercise_rule = ExerciseRule()
        exercise_rule.exercise.time = datetime.now()
        exercise_rule.exercise.solving_speed = 100
        exercise_rule.exercise.outcome = OutcomeRule().correct
        first_bookmark_to_study.add_new_exercise(exercise_rule.exercise)

        arts.update_bookmark_priority(zeeguu_core.db, self.user)

        # THEN
        bookmark = self.__get_bookmark_with_highest_priority()
        assert first_bookmark_to_study != bookmark