def test_calculate_beta_distribution_passes(): weighted_score, weighted_attempts = algorithm.calculate_weighted_score_and_attempts( 1., 1., 1., 1.) try: algorithm.calculate_beta_distribution_mean(weighted_score, weighted_attempts) assert True except: assert False
def test_calculate_beta_distribution_mean_score_is_nonegative(): score = -1. attempts = 2. try: algorithm.calculate_beta_distribution_mean(score, attempts) assert False except Exception as error: assert error.__class__.__name__ == 'ValueError' assert str(error) == f"{score} < 0 : score should be non-negative"
def test_calculate_beta_distribution_mean_score_lt_attempts(): score = 2. attempts = 1. try: algorithm.calculate_beta_distribution_mean(score, attempts) assert False except Exception as error: assert error.__class__.__name__ == 'ValueError' assert str( error ) == f"{score} > {attempts} : score should be less than or equal to attempts"
def test_calculate_beta_distribution_mean_attempts_is_float(): score = 1. attempts = 2 try: algorithm.calculate_beta_distribution_mean(score, attempts) assert False except Exception as error: assert error.__class__.__name__ == 'TypeError' assert str( error ) == f"attempts should be a float, a {score.__class__.__name__} was provided"
def test_calculate_beta_distribution_mean_is_1_thirds(): score = 0. attempts = 1. mastery = algorithm.calculate_beta_distribution_mean(score, attempts) assert mastery == 1 / 3
def test_calculate_beta_distribution_mean_is_half(): score = 1. attempts = 2. mastery = algorithm.calculate_beta_distribution_mean(score, attempts) assert mastery == 0.5
def test_calculate_beta_distribution_mean_in_range_0_to_1(): score = 1. attempts = 2. mastery = algorithm.calculate_beta_distribution_mean(score, attempts) assert mastery == pytest.approx(0.5, abs=0.5)
def test_calculate_beta_distribution_mean_returns_float(): score = 1. attempts = 2. mastery = algorithm.calculate_beta_distribution_mean(score, attempts) assert isinstance(mastery, float)
def handler(event, context): try: topic_id_list = event['topicIds'] questions = event['questions'] return_results = event['returnResults'] except KeyError: raise Exception('[BAD REQUEST]: Invalid event') study_guide_id_list = helper.get_study_guide_id_list( topic_id_list) topic_id_for_study_guide_id = helper.get_topic_id( study_guide_id_list) response = {'nextQuestion': {}, 'results': []} if not questions: response['nextQuestion'] = algorithm.choose_initial_question( topic_id_for_study_guide_id, study_guide_id_list) return _build_response(200, response) question_id_list = _create_question_id_list(questions) study_guide_score_and_attempts, topic_score_and_attempts = \ _accumulate_score_and_attempts( study_guide_id_list, topic_id_list, questions) _add_weighted_score_and_attempts( study_guide_score_and_attempts, topic_score_and_attempts, study_guide_id_list, topic_id_for_study_guide_id) if return_results: results_list = [] for study_guide_id in study_guide_id_list: topic_id = topic_id_for_study_guide_id[study_guide_id] weighted_score = study_guide_score_and_attempts[ study_guide_id]['weighted_score'] weighted_attempts = study_guide_score_and_attempts[ study_guide_id]['weighted_attempts'] mastery = float(algorithm.calculate_beta_distribution_mean( weighted_score, weighted_attempts)) mastery_band, band_confidence = algorithm.calculate_mastery_band_and_confidence( mastery, weighted_score, weighted_attempts) results_list.append({ 'studyGuideId': study_guide_id, 'topicId': topic_id, 'band': mastery_band, 'masteryScore': mastery * 100, 'confidenceScore': band_confidence * 100 }) response['results'] = results_list else: confidence_intervals_list = algorithm.calculate_confidence_intervals_list( study_guide_id_list, study_guide_score_and_attempts) response['nextQuestion'] = algorithm.choose_next_question( topic_id_for_study_guide_id, study_guide_id_list, confidence_intervals_list, question_id_list) return _build_response(200, response)
def test_calculate_beta_distribution_mean_1_out_of_1(): weighted_score = 1. weighted_attempts = 1. mastery = algorithm.calculate_beta_distribution_mean( weighted_score, weighted_attempts) assert mastery == pytest.approx(0.66, abs=0.01)