Ejemplo n.º 1
0
    def test_greedy(self):
        students = [course.Student(i, "Shit" + str(i)) for i in range(5)]
        questions = [survey.NumericQuestion(i, "FUCKNQ" + str(i), 2, 8) for i in range(5)]
        s = survey.Survey(questions)

        answers = [1, 0, 0, 3, 4, 1, 0, 1, 1, 1, 2, 1, 2, 2, 2, 3, 2, 1, 0, 1, 3, 0, 0, 3, 2]
        i = 0
        for q in questions:
            for stu in students:
                stu.set_answer(q, survey.Answer(2 + answers[i]))
                i += 1

        c = course.Course("Asshole101")
        c.enroll_students(students)

        grouping1 = grouper.GreedyGrouper(1).make_grouping(c, s)
        assert len(grouping1) == 5
        assert grouping_to_list_of_list(grouping1) == [[0], [1], [2], [3], [4]]

        grouping2 = grouper.GreedyGrouper(2).make_grouping(c, s)
        assert len(grouping2) == 3
        assert grouping_to_list_of_list(grouping2) == [[0, 3], [1, 2], [4]]

        grouping3 = grouper.GreedyGrouper(3).make_grouping(c, s)
        assert len(grouping3) == 2
        assert grouping_to_list_of_list(grouping3) == [[0, 3, 4], [1, 2]]

        grouping5 = grouper.GreedyGrouper(5).make_grouping(c, s)
        assert len(grouping5) == 1
        assert grouping_to_list_of_list(grouping5) == [[0, 1, 2, 3, 4]]
Ejemplo n.º 2
0
 def test_greedy_grouper(self) -> None:
     self.c.enroll_students(self.answer_questions())
     g = grouper.GreedyGrouper(3)
     gps = g.make_grouping(self.c, self.s).get_groups()
     assert len(gps) == 2
     assert gps[1].get_members()[1].id == 89
     assert len(gps[1].get_members()) == 2
     g = grouper.GreedyGrouper(2)
     gps = g.make_grouping(self.c, self.s).get_groups()
     assert len(gps) == 3
     assert gps[1].get_members()[1].id == 34
     h = []
     for group in gps:
         h.extend(group.get_members())
     for student in self.c.students:
         assert student in h
Ejemplo n.º 3
0
def test_make_window_grouping() -> None:
    grouper_ = grouper.GreedyGrouper(2)
    q = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    s1 = Student(1, "John")
    s2 = Student(2, "Carl")
    s3 = Student(3, "Anne")
    a1 = Answer([1, 2, 3, 4])
    a2 = Answer([1])
    a3 = Answer([1])
    s1.set_answer(q, a1)
    s2.set_answer(q, a2)
    s3.set_answer(q, a3)
    c = LonelyMemberCriterion()
    sur = Survey([q])
    sur.set_weight(1, q)
    sur.set_criterion(c, q)
    q_2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    a4 = Answer([1, 2])
    a5 = Answer([1, 2])
    a6 = Answer([1, 2])
    s1.set_answer(q_2, a4)
    s2.set_answer(q_2, a5)
    s3.set_answer(q_2, a6)
    sur2 = Survey([q, q_2])
    sur2.set_weight(1, q_2)
    sur2.set_criterion(c, q_2)
    cr = Course('dd')
    cr.enroll_students([s1, s2, s3])
    assert grouper_.make_grouping(
        cr, sur).get_groups()[0].get_members()[0].name == "John"
    assert grouper_.make_grouping(
        cr, sur).get_groups()[0].get_members()[1].name == "Carl"
    assert grouper_.make_grouping(
        cr, sur).get_groups()[1].get_members()[0].name == "Anne"
Ejemplo n.º 4
0
 def test_make_grouping_greedy(self):
     new_course = course.Course('CSC148')
     q1 = survey.CheckboxQuestion(1, 'Hobbies?',
                                  ['Movie', 'Sing', 'Dance', 'Game'])
     new_survey = survey.Survey([q1])
     students = [course.Student(1, 'Zoro'),
                 course.Student(2, 'Aaron'),
                 course.Student(3, 'Gertrude'),
                 course.Student(4, 'Yvette'),
                 course.Student(6, 'Steph'),
                 course.Student(7, 'Draymond'),
                 course.Student(8, 'Andrew')]
     new_course.enroll_students(students)
     new_grouper = grouper.GreedyGrouper(2)
     new_grouping = new_grouper.make_grouping(new_course, new_survey)
     groups = new_grouping.get_groups()
     temp_list = []
     for i in range(0, len(groups)):
         people = groups[i].get_members()
         temp_list.extend(people)
         if i == (len(groups) - 1):
             assert len(groups[i]) <= 2
         else:
             assert len(groups[i]) == 2
     course_students = new_course.get_students()
     for student in course_students:
         assert student in temp_list
     assert len(temp_list) == 7
Ejemplo n.º 5
0
 def test_score_grouping(self) -> None:
     self.c.enroll_students(self.answer_questions())
     g = grouper.AlphaGrouper(3)
     gps = g.make_grouping(self.c, self.s)
     assert self.s.score_grouping(gps) == 0.3125
     self.c.enroll_students(self.answer_questions())
     g2 = grouper.GreedyGrouper(3)
     gps2 = g2.make_grouping(self.c, self.s)
     assert self.s.score_grouping(gps2) == 0.5892857142857143
Ejemplo n.º 6
0
def test_grouper_greedygrouper() -> None:
    c1 = course.Course('CSC148')
    s1 = course.Student(1, 'Ali')
    s2 = course.Student(2, 'Kat')
    s3 = course.Student(3, 'Dorsa')
    s4 = course.Student(4, 'Sophia')
    s5 = course.Student(5, 'Momo')
    s6 = course.Student(6, 'Joseph')
    c1.enroll_students([s1, s2, s3, s4, s5, s6])
    a1 = grouper.GreedyGrouper(2)
    q1 = survey.MultipleChoiceQuestion(1, 'What is your choice?',
                                       ['A', 'B', 'C'])
    a = survey.Answer('A')
    b = survey.Answer('B')
    c = survey.Answer('C')
    s1.set_answer(q1, a)
    s2.set_answer(q1, b)
    s3.set_answer(q1, c)
    s4.set_answer(q1, a)
    s5.set_answer(q1, b)
    s6.set_answer(q1, c)
    sur1 = survey.Survey([q1])
    assert a1.make_grouping(c1, sur1).get_groups()[0].get_members()[0] == s1
    assert a1.make_grouping(c1, sur1).get_groups()[2].get_members()[1] == s6
Ejemplo n.º 7
0
 def test_make_grouping(self, course_with_students_with_answers,
                        greedy_grouping, survey_) -> None:
     grouper_ = grouper.GreedyGrouper(2)
     grouping = grouper_.make_grouping(course_with_students_with_answers,
                                       survey_)
     compare_groupings(grouping, greedy_grouping)
Ejemplo n.º 8
0
    def test_combination(self):
        students = [course.Student(i, "Shit" + str(i)) for i in range(8)]
        q1 = survey.YesNoQuestion(0, "To be, or not to be")
        q2 = survey.NumericQuestion(1, "How many times you f**k up", 0, 10000)
        q3 = survey.MultipleChoiceQuestion(2, "What's your favorite thing to do", ['A', 'B', 'C', 'D'])
        q4 = survey.CheckboxQuestion(3, "How many things you have done", ['A', 'B', 'C', 'D', 'E'])
        questions = [q1, q2, q3, q4]
        s = survey.Survey(questions)

        answers = [True, 1111, 'A', ['A', 'C'],
                   False, 44, 'C', ['A', 'B', 'C'],
                   True, 3, 'B', ['A', 'C', 'D'],
                   True, 56, 'C', ['D', 'C'],
                   False, 12, 'C', ['E'],
                   True, 0, 'A', ['A'],
                   False, 888, 'C', ['A', 'B', 'C', 'D'],
                   True, 12, 'B', ['A', 'B', 'C', 'D', 'E']]

        i = 0
        for stu in students:
            for q in questions:
                stu.set_answer(q, survey.Answer(answers[i]))
                i += 1

        c = course.Course("Asshole101")
        c.enroll_students(students)

        grouping = grouper.AlphaGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]

        grouping = grouper.GreedyGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 2, 5], [1, 4, 6], [3, 7]]

        grouping = grouper.WindowGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 4, 5], [1, 2, 3], [6, 7]]

        s.set_criterion(criterion.HeterogeneousCriterion(), q2)
        s.set_weight(2, q1)
        s.set_weight(2, q1)
        s.set_weight(3, q2)
        s.set_weight(55, q4)

        grouping = grouper.AlphaGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]

        grouping = grouper.GreedyGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 2, 6], [1, 3, 7], [4, 5]]

        grouping = grouper.WindowGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4], [5, 6, 7]]

        s.set_weight(2, q1)
        s.set_weight(1, q2)
        s.set_weight(5, q3)
        s.set_weight(2, q4)
        s.set_criterion(criterion.LonelyMemberCriterion(), q1)
        s.set_criterion(criterion.LonelyMemberCriterion(), q2)
        s.set_criterion(criterion.LonelyMemberCriterion(), q3)
        s.set_criterion(criterion.LonelyMemberCriterion(), q4)

        grouping = grouper.AlphaGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]

        grouping = grouper.GreedyGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 2, 5], [1, 4, 6], [3, 7]]

        grouping = grouper.WindowGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]

        # make one of the student's answer invalid
        students[0].set_answer(q1, survey.Answer('F**K'))

        grouping = grouper.AlphaGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]

        grouping = grouper.GreedyGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 6], [5, 7]]

        grouping = grouper.WindowGrouper(3).make_grouping(c, s)
        assert len(grouping) == 3
        assert grouping_to_list_of_list(grouping) == [[0, 1, 2], [3, 4, 5], [6, 7]]
Ejemplo n.º 9
0
def GreedyGrouper1():
    return grouper.GreedyGrouper(2)
Ejemplo n.º 10
0
def GreedyGrouper2():
    return grouper.GreedyGrouper(3)