Ejemplo n.º 1
0
def test_answer_is_valid() -> None:
    a_multiple = Answer("a")
    a_checkbox = Answer(["a", "b"])
    a_yesno = Answer(True)
    a_yesno_2 = Answer(1)
    a_numeric = Answer(15)

    assert a_multiple.is_valid(MultipleChoiceQuestion(1, "choose", ["a", "b"]))\
           is True
    assert a_multiple.is_valid(MultipleChoiceQuestion(1, "choose", ["c", "b"])) \
           is False
    assert a_checkbox.is_valid(CheckboxQuestion(2, "choose", ["a", "b"])) is \
           True
    assert a_checkbox.is_valid(CheckboxQuestion(2, "choose", ["a", "a"])) is \
           False
    assert a_yesno.is_valid(YesNoQuestion(1, "choose")) is True
    assert a_yesno_2.is_valid(YesNoQuestion(1, "choose")) is False
    assert a_numeric.is_valid(NumericQuestion(1, "5+10", 1, 20)) is True
    assert a_numeric.is_valid(NumericQuestion(1, "5+10", 18, 20)) is False
Ejemplo n.º 2
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
Ejemplo n.º 3
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.º 4
0
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
Ejemplo n.º 5
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.º 6
0
def test_multiple_choice_question_string() -> None:
    q = MultipleChoiceQuestion(1, "how old are you", ['10', '11'])
    assert str(q) == 'how old are you\n10\n11'
Ejemplo n.º 7
0
def test_survey_multi_similarity_different() -> None:
    """A test for get_similarity() in class MultipleChoiceQuestion."""
    q = MultipleChoiceQuestion(1, 'ABC', ['A', 'B'])
    a = Answer('A')
    b = Answer('B')
    assert q.get_similarity(a, b) == 0.0
Ejemplo n.º 8
0
def test_survey_multi_invalid_answer() -> None:
    """A test for validate_answer() in class MultipleChoiceQuestion."""
    q = MultipleChoiceQuestion(1, 'ABC', ['A', 'B'])
    a = Answer('C')
    assert q.validate_answer(a) is False
Ejemplo n.º 9
0
def test_survey_multi_to_string() -> None:
    """A test for _str__() in class MultipleChoiceQuestion."""
    q = MultipleChoiceQuestion(1, 'ABC', ['A', 'B'])
    assert type(str(q)) is str
Ejemplo n.º 10
0
def test_questions() -> None:
    mcq_1 = MultipleChoiceQuestion(1, "Cities in Canada",
                                   ["Toronto", "Ottawa", "Vancouver"])
    assert mcq_1.id == 1
    assert mcq_1.text == "Cities in Canada"
    assert "Cities in Canada" in str(mcq_1)
    assert "Toronto" in str(mcq_1)
    assert "Ottawa" in str(mcq_1)
    assert "Montreal" not in str(mcq_1)
    mcq_1_ans = Answer("Toronto")
    mcq_1_c_ans = Answer("Toronto")
    mcq_2_ans = Answer("Montreal")
    mcq_3_ans = Answer("")
    assert mcq_1_ans.is_valid(mcq_1)
    assert not mcq_2_ans.is_valid(mcq_1)
    assert mcq_1.validate_answer(mcq_1_ans)
    assert not mcq_1.validate_answer(mcq_2_ans)
    assert not mcq_1.validate_answer(mcq_3_ans)
    assert mcq_1.get_similarity(mcq_1_ans, mcq_1_c_ans) == 1.0
    assert mcq_1.get_similarity(mcq_1_ans, mcq_2_ans) == 0.0

    nq_1 = NumericQuestion(1, "A n.o between 1 and 5", 1, 5)
    nq_1_ans = Answer(1)
    nq_2_ans = Answer(2)
    nq_3_ans = Answer(3)
    nq_4_ans = Answer(5)
    nq_5_ans = Answer(10)
    nq_6_ans = Answer(1)
    assert nq_1.validate_answer(nq_1_ans)
    assert nq_1.validate_answer(nq_2_ans)
    assert nq_1.validate_answer(nq_3_ans)
    assert nq_1.validate_answer(nq_4_ans)
    assert not nq_1.validate_answer(nq_5_ans)
    assert nq_1_ans.is_valid(nq_1)
    assert nq_2_ans.is_valid(nq_1)
    assert nq_3_ans.is_valid(nq_1)
    assert nq_4_ans.is_valid(nq_1)
    assert not nq_5_ans.is_valid(nq_1)
    assert nq_1.get_similarity(nq_1_ans, nq_6_ans) == 1.0
    assert nq_1.get_similarity(nq_1_ans, nq_4_ans) == 0.0
    assert nq_1.get_similarity(nq_2_ans, nq_3_ans) == 0.75

    ynq = YesNoQuestion(1, "Is earth round")
    ynq_1 = Answer(True)
    ynq_2 = Answer(False)
    ynq_3 = Answer(False)
    assert ynq_1.is_valid(ynq)
    assert ynq_2.is_valid(ynq)
    assert not ynq.get_similarity(ynq_1, ynq_2)
    assert ynq.get_similarity(ynq_2, ynq_3)

    cbq = CheckboxQuestion(1, "Cities in Canada",
                           ["Toronto", "Ottawa", "Vancouver"])
    cbq_1 = Answer(["Toronto", "Ottawa"])
    cbq_2 = Answer(["Seoul", "Busan"])
    cbq_3 = Answer(["Toronto", "Ottawa"])
    cbq_4 = Answer(["Toronto", "Vancouver"])
    assert cbq.validate_answer(cbq_1)
    assert not cbq.validate_answer(cbq_2)
    assert cbq_1.is_valid(cbq)
    assert not cbq_2.is_valid(cbq)
    assert cbq.get_similarity(cbq_1, cbq_3) == 1
    assert cbq.get_similarity(cbq_1, cbq_4) == 1 / 3
    assert cbq.get_similarity(cbq_1, cbq_2) == 0.0