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
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)
def test_grouper_group_contains() -> None: """A test for __contains__() in class Group.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g = Group([s1, s2, s3, s4]) assert s1 in g
def test_grouper_group_len() -> None: """A test for __len__() in class Group.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g = Group([s1, s2, s3, s4]) assert len(g) == 4
def test_grouper_group_to_string() -> None: """A test for __str__() in class Group.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g = Group([s1, s2, s3, s4]) assert type(str(g)) is str
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___str__(self) -> None: s1 = Student(1, "John") s2 = Student(2, "Carl") s3 = Student(3, "Anne") students = [s1, s2, s3] group = Group(students) for student in students: assert student.name in str(group)
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)
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
def test___len__(self) -> None: s1 = Student(1, "John") s2 = Student(2, "Carl") s3 = Student(3, "Anne") students = [s1, s2, s3] group = Group(students) g = Grouping() g.add_group(group) assert len(g) == 1
def test_get_groups(self) -> None: s1 = Student(1, "John") s2 = Student(2, "Carl") s3 = Student(3, "Anne") students = [s1, s2, s3] group = Group(students) g = Grouping() g.add_group(group) assert [group] == g.get_groups()
def test_grouper_grouping_add_group_duplicate() -> None: """A test for add_group() in class Grouping.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s4 = Student(4, 'D') g1 = Group([s1, s2]) g2 = Group([s1, s4]) grouping = Grouping() assert grouping.add_group(g1) assert grouping.add_group(g2) is False
def test_get_members(self) -> None: ids = set() s1 = Student(1, "John") s2 = Student(2, "Carl") s3 = Student(3, "Anne") students = [s1, s2, s3] group = Group(students) for member in group.get_members(): ids.add(member.id) assert ids == {1, 2, 3}
def test_grouper_grouping_add_group_valid() -> None: """A test for add_group() in class Grouping.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g1 = Group([s1, s2]) g2 = Group([s3, s4]) grouping = Grouping() assert grouping.add_group(g1) assert grouping.add_group(g2)
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())
def test_grouper_group_get_members() -> None: """A test for get_members() in class Group.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g = Group([s1, s2, s3, s4]) result = g.get_members() assert s1 in result assert s2 in result assert s3 in result assert s4 in result
def test_grouper_grouping_len() -> None: """A test for __len__() in class Grouping.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g1 = Group([s1, s2]) g2 = Group([s3, s4]) grouping = Grouping() grouping.add_group(g1) grouping.add_group(g2) assert len(grouping) == 2
def test_grouper_grouping_get_groups() -> None: """A test for get_groups() in class Grouping.""" s1 = Student(1, 'A') s2 = Student(2, 'B') s3 = Student(3, 'C') s4 = Student(4, 'D') g1 = Group([s1, s2]) g2 = Group([s3, s4]) grouping = Grouping() grouping.add_group(g1) grouping.add_group(g2) result = grouping.get_groups() assert g1 in result assert g2 in result
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]
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_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_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_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()
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: s = Student(1, "John") assert s.id == 1 assert s.name == "John" str(s) == "John"
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 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___len__(self) -> None: s1 = Student(1, "John") s2 = Student(2, "Carl") s3 = Student(3, "Anne") group = Group([s1, s2, s3]) assert len(group) == 3
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"