Ejemplo n.º 1
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.º 2
0
def test_course_get_students() -> None:
    student_1 = Student(2, "Jane")
    student_2 = Student(1, "John")
    course = Course("math")
    lst = [student_1, student_2]
    course.enroll_students(lst)
    assert course.get_students() == (student_2, student_1)
Ejemplo n.º 3
0
def test_course_enroll_student() -> None:
    """A test for enroll_student() in class Course."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    c = Course('CS')
    c.enroll_students([s1, s2])
    assert s1 in c.students and s2 in c.students
Ejemplo n.º 4
0
def test_course_enroll_student_empty() -> None:
    """A test for enroll_student() in class Course."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    s3 = Student(3, '')
    c = Course('CS')
    c.enroll_students([s1, s2])
    c.enroll_students([s3])
    assert s3 not in c.students
Ejemplo n.º 5
0
def test_course_get_students() -> None:
    """A test for get_students() in class Course."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    s3 = Student(3, 'C')
    c = Course('CS')
    c.enroll_students([s3, s1, s2])
    test_tup = c.get_students()
    assert test_tup == (s1, s2, s3)
Ejemplo n.º 6
0
def test_make_rangrouping() -> None:
    grouper_ = grouper.RandomGrouper(3)
    s1 = Student(1, "John")
    s2 = Student(2, "Carl")
    s3 = Student(3, "Anne")
    c = Course('dd')
    c.enroll_students([s1, s2, s3])
    sur = return_sur()
    group = Group([s3, s2, s1])
    assert len(grouper_.make_grouping(
        c, sur).get_groups()[0].get_members()) == len(group.get_members())
Ejemplo n.º 7
0
def test_grouper_alpha_make_grouping() -> None:
    """A test for make_grouping() in class AlphaGrouper."""
    q = MultipleChoiceQuestion(1, 'abc', ['a'])
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    s3 = Student(3, 'C')
    s4 = Student(4, 'D')
    c = Course('CS')
    c.enroll_students([s3, s4, s2, s1])
    a = AlphaGrouper(2)
    s = Survey([q])
    result = a.make_grouping(c, s).get_groups()
    assert s1 in result[0] and s2 in result[0]
    assert s3 in result[1] and s4 in result[1]
Ejemplo n.º 8
0
def test_course_all_answered() -> None:
    """A test for all_answered() in class Course."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    c = Course('CS')
    c.enroll_students([s1, s2])
    q1 = YesNoQuestion(2, 'F')
    q2 = YesNoQuestion(3, 'K')
    a1 = Answer(True)
    a2 = Answer(False)
    survey = Survey([q1, q2])
    s1.set_answer(q1, a1)
    s1.set_answer(q2, a2)
    s2.set_answer(q1, a1)
    s2.set_answer(q2, a2)
    assert c.all_answered(survey) is True
Ejemplo n.º 9
0
def test_course_all_answered() -> None:
    student_1 = Student(2, "Jane")
    student_2 = Student(1, "John")
    course = Course("math")
    course_2 = Course("Eng")
    lst = [student_1, student_2]
    lst_2 = [student_1]
    course.enroll_students(lst)
    course_2.enroll_students(lst_2)
    q = CheckboxQuestion(1, "choose", [1, 2, 3])
    a1 = Answer([1])
    a2 = Answer([5])
    student_1.set_answer(q, a1)
    student_2.set_answer(q, a2)
    s = Survey([q])
    assert course.all_answered(s) is False
    assert course_2.all_answered(s) is True
Ejemplo n.º 10
0
def test_course() -> None:
    course_0 = Course("Snake")
    course_0.enroll_students([Student(0, "Tim")])
    course_0.enroll_students([Student(0, "Tim")])
    course_0.enroll_students([Student(0, "Tim"), Student(0, "Roney")])
    assert len(course_0.get_students()) == 1
    course_0.enroll_students([Student(1, "Tim"), Student(2, "Roney")])
    assert len(course_0.get_students()) == 3
    course_1 = Course("Python")
    students = []
    for x in range(10):
        students.append(Student(x, ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=6))))
    course_1.enroll_students(students)
    assert len(course_1.get_students()) == len(students)
    assert tuple(sort_students(students, "id")) == course_1.get_students()
Ejemplo n.º 11
0
def test_grouper_window_make_grouping() -> None:
    """A test for make_grouping() in class WindowGrouper."""
    q1 = YesNoQuestion(1, 'BBC')
    q2 = MultipleChoiceQuestion(2, 'ABC', ['A', 'B', 'C'])
    a1 = Answer(True)
    a2 = Answer('A')
    a3 = Answer(True)
    a4 = Answer('B')
    a5 = Answer(True)
    a6 = Answer('B')
    a7 = Answer(False)
    a8 = Answer('C')
    stu1 = Student(100, 'Jack')
    stu2 = Student(200, 'Mike')
    stu3 = Student(300, 'Diana')
    stu4 = Student(400, 'Tom')
    stu1.set_answer(q1, a1)
    stu1.set_answer(q2, a2)
    stu2.set_answer(q1, a3)
    stu2.set_answer(q2, a4)
    stu3.set_answer(q1, a5)
    stu3.set_answer(q2, a6)
    stu4.set_answer(q1, a7)
    stu4.set_answer(q2, a8)
    window = WindowGrouper(2)
    survey = Survey([q1, q2])
    course = Course('CS')
    cri = HomogeneousCriterion()
    survey.set_weight(2.0, q1)
    survey.set_criterion(cri, q1)
    survey.set_criterion(cri, q2)
    course.enroll_students([stu1, stu2, stu3, stu4])
    result = window.make_grouping(course, survey).get_groups()
    assert stu1 in result[1]
    assert stu2 in result[0]
    assert stu3 in result[0]
    assert stu4 in result[1]
Ejemplo n.º 12
0
def test_grouper() -> None:
    assert windows([3, 4, 6, 2, 3], 2) == [[3, 4], [4, 6], [6, 2], [2, 3]]
    assert windows(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [1, 6.0, False]]
    assert slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]]
    assert slice_list(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [False]]

    g = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")])
    g_1 = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")])
    g_2 = Group([Student(5, "roney"), Student(6, "tim"), Student(7, "allen")])
    assert len(g) == 3
    assert Student(1, "roney") in g
    assert "roney" in str(g)
    gr = Grouping()
    assert gr.add_group(g)
    assert not gr.add_group(g_1)
    assert gr.add_group(g_2)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = AlphaGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = AlphaGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = RandomGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = RandomGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    ag = GreedyGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    ag = GreedyGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 3, 2]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    s.set_criterion(LonelyMemberCriterion(), q)
    ag = GreedyGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 3]
    assert groups[1]._member_id == [2]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(True))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(LonelyMemberCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HeterogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HomogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(False))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HomogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [2, 3]
    assert groups[1]._member_id == [1, 4]