def test_size_distribution(self):
        """
        This test may fail 1 out of 10,000 times because it tests a sample
        mean against a population mean
        """

        pop_avg = 100
        pop_std_dev = 10
        z_for_99_point_99_confidence = 3.8906
        n = 20

        classrooms = [
            graph_generation.new_classroom(
                # add 1 for the teacher
                avg_num_students=pop_avg + 1,
                variation_coeff=pop_std_dev * 1.0 / pop_avg
            )
            for c in range(n)
            ]

        mean_users = mean([len(c) for c in classrooms])

        # We generate the 99.99% confidence interval for this sample mean
        max_distance = z_for_99_point_99_confidence * pop_std_dev / sqrt(n)

        self.assertTrue(
            abs(mean_users - pop_avg) < max_distance,
            msg='classroom size exceeded expected bounds (may happen 1 out of 10,000 times)'
        )
def reset_graph():
    """Resets THE graph based on parameters"""
    global graph

    num_schools = dict_int(request.form, 'num_schools', 5)
    num_classes = dict_int(request.form, 'num_classes', 10)

    class_gen = lambda: new_classroom(10, variation_coeff=1)
    schools = [new_school(num_classes, 0.5, class_gen, extra_coaching_rate=0.1) for i in range(num_schools)]

    # flatten schools list
    graph = [user for school in schools for user in school]

    return users_to_graph_json(graph)
    def test_list_is_flat(self):
        classroom_gen = lambda: graph_generation.new_classroom(
            avg_num_students=10,
            variation_coeff=0.1
        )

        school = graph_generation.new_school(
            avg_num_classes=3,
            variation_coeff=0.3,
            class_gen=classroom_gen
        )

        for u in school:
            self.assertIsInstance(u, models.User, msg='School list not flattened')
    def test_teacher_exists(self):
        n = 10

        classrooms = [
            graph_generation.new_classroom(avg_num_students=25, variation_coeff=0.1)
            for c in range(n)
            ]

        for c in classrooms:
            # Make sure there's at least one user with n-1 learners
            self.assertGreaterEqual(
                max(len(u.learner_set) for u in c),
                len(c) - 1,
                msg="no teacher found"
            )