def test_calculate_study_guide_weighting_topic_score_is_nonnegative():
    study_guide_score, study_guide_attempts, topic_score, topic_attempts = 1., 1., -2., 2.
    try:
        algorithm.calculate_study_guide_weighting(study_guide_score,
                                                  study_guide_attempts,
                                                  topic_score, topic_attempts)
        assert False
    except Exception as error:
        assert error.__class__.__name__ == 'ValueError'
        assert str(
            error) == f"{topic_score} < 0 : topic_score should be non-negative"
def test_calculate_study_guide_weighting_study_guide_score_lt_topic_score():
    study_guide_score, study_guide_attempts, topic_score, topic_attempts = 3., 3., 2., 4.
    try:
        algorithm.calculate_study_guide_weighting(study_guide_score,
                                                  study_guide_attempts,
                                                  topic_score, topic_attempts)
        assert False
    except Exception as error:
        assert error.__class__.__name__ == 'ValueError'
        assert str(
            error
        ) == f"{study_guide_score} > {topic_score} : study_guide_score should be less than or equal to topic_score"
def test_calculate_study_guide_weighting_topic_attempts_is_float():
    study_guide_score, study_guide_attempts, topic_score, topic_attempts = 1., 1., 2., 2
    try:
        algorithm.calculate_study_guide_weighting(study_guide_score,
                                                  study_guide_attempts,
                                                  topic_score, topic_attempts)
        assert False
    except Exception as error:
        assert error.__class__.__name__ == 'TypeError'
        assert str(
            error
        ) == f"topic_attempts should be a float, a {topic_attempts.__class__.__name__} was provided"
Exemple #4
0
def test_calculate_study_guide_weighting_1_when_much_worse_at_guide():
    study_guide_score = 0.
    study_guide_attempts = 100.
    topic_score = 100.
    topic_attempts = 100.
    weighting = algorithm.calculate_study_guide_weighting(
        study_guide_score, study_guide_attempts, topic_score, topic_attempts)
    assert weighting == pytest.approx(1, rel=1e-6)
Exemple #5
0
def test_calculate_study_guide_weighting_in_range_0_to_1():
    study_guide_score = 1.
    study_guide_attempts = 2.
    topic_score = 2.
    topic_attempts = 3.
    weighting = algorithm.calculate_study_guide_weighting(
        study_guide_score, study_guide_attempts, topic_score, topic_attempts)
    assert weighting == pytest.approx(0.5, abs=0.5)
Exemple #6
0
def test_calculate_study_guide_weighting_is_float():
    study_guide_score = 1.
    study_guide_attempts = 2.
    topic_score = 2.
    topic_attempts = 3.
    weighting = algorithm.calculate_study_guide_weighting(
        study_guide_score, study_guide_attempts, topic_score, topic_attempts)
    assert isinstance(weighting, float)
def test_calculate_study_guide_weighting_passes_into_calculate_weighted_value():
    study_guide_score = 0.
    study_guide_attempts = 100.
    topic_score = 100.
    topic_attempts = 100.

    study_guide_weighting = algorithm.calculate_study_guide_weighting(
        study_guide_score, study_guide_attempts, topic_score, topic_attempts)

    try:
        algorithm.calculate_weighted_value(
            study_guide_weighting, study_guide_score, topic_score)
        assert True
    except:
        assert False
Exemple #8
0
def _add_weighted_score_and_attempts(
    study_guide_score_and_attempts, topic_score_and_attempts,
        study_guide_id_list, topic_id_for_study_guide_id):

    for study_guide_id in study_guide_id_list:
        topic_id = topic_id_for_study_guide_id[study_guide_id]
        topic_score = topic_score_and_attempts[topic_id]['score']
        topic_attempts = topic_score_and_attempts[topic_id]['attempts']

        study_guide_score = study_guide_score_and_attempts[study_guide_id]['score']
        study_guide_attempts = study_guide_score_and_attempts[study_guide_id]['attempts']

        study_guide_weighting = algorithm.calculate_study_guide_weighting(
            study_guide_score, study_guide_attempts, topic_score, topic_attempts)

        study_guide_score_and_attempts[study_guide_id]['weighted_score'] = \
            algorithm.calculate_weighted_value(
                study_guide_weighting, study_guide_score, topic_score)

        study_guide_score_and_attempts[study_guide_id]['weighted_attempts'] = \
            algorithm.calculate_weighted_value(
                study_guide_weighting, study_guide_attempts, topic_attempts)