def test_calculate_weighted_value_topic_value_nonnegative(): weighting = 0.5 study_guide_value = 1. topic_value = -1. try: algorithm.calculate_weighted_value(weighting, study_guide_value, topic_value) assert False except Exception as error: assert error.__class__.__name__ == 'ValueError' assert str( error) == f"{topic_value} < 0 : topic_value should be non-negative"
def test_calculate_weighted_value_weighting_is_float(): weighting = 1 study_guide_value = 1. topic_value = 1. try: algorithm.calculate_weighted_value(weighting, study_guide_value, topic_value) assert False except Exception as error: assert error.__class__.__name__ == 'TypeError' assert str( error ) == f"weighting should be a float, a {weighting.__class__.__name__} was provided"
def test_calculate_weighted_value_weighting_in_range_0_to_1(): weighting = 5. study_guide_value = 1. topic_value = 1. try: algorithm.calculate_weighted_value(weighting, study_guide_value, topic_value) assert False except Exception as error: assert error.__class__.__name__ == 'ValueError' assert str( error ) == f"unexpected value encountered - weighted_score should be in the interval [0, 1]"
def test_calculate_weighted_value_study_guide_value_lt_topic_value(): weighting = 0.5 study_guide_value = 2. topic_value = 1. try: algorithm.calculate_weighted_value(weighting, study_guide_value, topic_value) assert False except Exception as error: assert error.__class__.__name__ == 'ValueError' assert str( error ) == f"{study_guide_value} > {topic_value} : study_guide_value should be less than or equal to topic_value"
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
def test_calculate_weighted_value_is_study_guidewhen_weighting_is_1(): weighting = 1. study_guide_value = 1. topic_value = 2. weighted_value = \ algorithm.calculate_weighted_value( weighting, study_guide_value, topic_value) assert weighted_value == study_guide_value
def test_calculate_weighted_value_between_study_guide_and_topic_value(): weighting = 0.5 study_guide_value = 1. topic_value = 2. weighted_value = \ algorithm.calculate_weighted_value( weighting, study_guide_value, topic_value) assert weighted_value >= study_guide_value assert weighted_value <= topic_value
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)
def test_calculate_weighted_value_returns_float(): weighted_value = \ algorithm.calculate_weighted_value(0.5, 1., 2.) assert isinstance(weighted_value, float)