def test_student_get_answer() -> None: """A test for get_answer() in class Student.""" s = Student(123, 'Mike') ans = Answer(False) que = Question(2, 'F') s.set_answer(que, ans) test_ans = s.get_answer(que) assert ans == test_ans
def test_student_get_answer() -> None: student = Student(1, "Jane") q1 = Question(1, "How are you") a1 = Answer("good") q2 = Question(2, "hello") a2 = Answer("hi") assert student.get_answer(q1) is None student.set_answer(q1, a1) student.set_answer(q2, a2) assert student.get_answer(q1) == a1 assert student.get_answer(q2) == a2
def test_student_set_answer(): student = Student(1, "Jane") q1 = Question(1, "How are you") a1 = Answer("good") q2 = Question(2, "hello") a2 = Answer("hi") a3 = Answer("test") student.set_answer(q1, a1) student.set_answer(q2, a2) student.set_answer(q2, a3) assert student.get_answer(q1) == a1 assert student.get_answer(q2) == a3
def test_survey_survey_score_grouping() -> None: """A test for score_grouping() in class Survey.""" q1 = YesNoQuestion(1, 'BBC') q2 = MultipleChoiceQuestion(2, 'ABC', ['A', 'B', 'C']) a1 = Answer(True) a2 = Answer('A') a3 = Answer(True) a4 = Answer('C') 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) s = Survey([q1, q2]) c = HomogeneousCriterion() s.set_weight(2.0, q1) s.set_criterion(c, q1) s.set_criterion(c, q2) g1 = Group([stu1, stu2]) g2 = Group([stu3, stu4]) grouping = Grouping() grouping.add_group(g1) grouping.add_group(g2) assert s.score_grouping(grouping) == 0.5
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
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
def test_survey_survey_score_student() -> None: """A test for score_student() in class Survey.""" q1 = YesNoQuestion(1, 'BBC') q2 = MultipleChoiceQuestion(2, 'ABC', ['A', 'B', 'C']) a1 = Answer(True) a2 = Answer('A') a3 = Answer(True) a4 = Answer('C') stu1 = Student(100, 'Jack') stu2 = Student(200, 'Mike') stu1.set_answer(q1, a1) stu1.set_answer(q2, a2) stu2.set_answer(q1, a3) stu2.set_answer(q2, a4) s = Survey([q1, q2]) c = HomogeneousCriterion() s.set_weight(2.0, q1) s.set_criterion(c, q1) s.set_criterion(c, q2) assert s.score_students([stu1, stu2]) == 1.0
def test_student() -> None: student_1 = Student(1, "roney") student_2 = Student(2, "tim") student_3 = Student(3, "allen") assert str(student_1) == "roney" assert str(student_2) == "tim" assert str(student_3) != "roney" assert student_1.id == 1 assert student_2.id != 4 assert student_3.id == 3 mcq_1 = MultipleChoiceQuestion(1, "Cities in Canada", ["Toronto", "Ottawa", "Vancouver"]) mcq_2 = MultipleChoiceQuestion(2, "C", ["A", "O", "V"]) mcq_1_ans = Answer("Toronto") student_1.set_answer(mcq_1, mcq_1_ans) assert student_1.has_answer(mcq_1) assert not student_1.has_answer(mcq_2) assert student_1.get_answer(mcq_1) == mcq_1_ans assert student_1.get_answer(mcq_2) == None assert student_2.get_answer(mcq_1) == None
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]
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"
def return_sur() -> Survey: 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) return sur2
def test_score_students() -> None: 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) assert sur.score_students([s1, s2, s3]) == 0.0 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) sur1 = Survey([q_2]) sur2 = Survey([q, q_2]) sur2.set_weight(1, q_2) sur2.set_criterion(c, q_2) assert sur1.score_students([s1, s2, s3]) == 1 assert sur2.score_students([s1, s2, s3]) == 0.5
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]