コード例 #1
0
ファイル: tests-roney.py プロジェクト: RoneyThomas/csc148
def test_criterion() -> None:
    ho_crit = HomogeneousCriterion()
    he_crit = HeterogeneousCriterion()
    lo_crit = LonelyMemberCriterion()

    ynq = YesNoQuestion(1, "Is earth round")
    ynq_1_answers = [Answer(True), Answer(True), Answer(True), Answer(True)]
    ynq_2_answers = [Answer(True), Answer(False), Answer(True), Answer(False)]
    ynq_3_answers = [Answer(True)]
    ynq_4_answers = [Answer(True), Answer(False)]

    assert ho_crit.score_answers(ynq, ynq_1_answers) == 1
    assert ho_crit.score_answers(ynq, ynq_2_answers) == 1 / 3
    assert ho_crit.score_answers(ynq, ynq_3_answers) == 1
    assert ho_crit.score_answers(ynq, ynq_4_answers) == 0

    assert he_crit.score_answers(ynq, ynq_1_answers) == 0.0
    assert he_crit.score_answers(ynq, ynq_2_answers) == pytest.approx(2 / 3,
                                                                      rel=1e-3)
    assert he_crit.score_answers(ynq, ynq_3_answers) == 0.0
    assert he_crit.score_answers(ynq, ynq_4_answers) == 1

    assert lo_crit.score_answers(ynq, ynq_1_answers) == 1
    assert lo_crit.score_answers(ynq, ynq_2_answers) == 0.0
    assert lo_crit.score_answers(ynq, ynq_3_answers) == 1
    assert lo_crit.score_answers(ynq, ynq_4_answers) == 0
コード例 #2
0
ファイル: tests.py プロジェクト: jiheechoi6/CSC148-A1
def test_homogeneous_criterion() -> None:
    q = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    a1 = Answer([1, 2, 3, 4])
    a2 = Answer([1, 2])
    a3 = Answer(["hello"])
    c = HomogeneousCriterion()
    assert c.score_answers(q, [a1, a2]) == 0.5
    # assert c.score_answers(q, [a3]) is InvalidAnswerError
    assert c.score_answers(q, [a1]) == 1.0
コード例 #3
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
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
コード例 #4
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
def test_survey_survey_set_criterion_invalid() -> None:
    """A test for set_criterion() in class Survey."""
    q1 = CheckboxQuestion(1, 'ABC', ['a', '1', ','])
    q2 = YesNoQuestion(2, 'BBC')
    s = Survey([q1])
    c = HomogeneousCriterion()
    assert s.set_criterion(c, q2) is False
コード例 #5
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
def test_criterion_homo_score_answer_valid() -> None:
    """A test for score_answer() in class HomogeneousCriterion."""
    q1 = YesNoQuestion(1, 'ABC')
    a1 = Answer(True)
    a2 = Answer(True)
    a3 = Answer(True)
    a4 = Answer(True)
    a5 = Answer(False)
    a6 = Answer(False)
    c = HomogeneousCriterion()
    #    a1 a2 a3 a4 a5 a6
    # a1 NA 1  1  1  0  0
    # a2 1  NA 1  1  0  0
    # a3 1  1  NA 1  0  0
    # a4 1  1  1  NA 0  0
    # a5 0  0  0  0  NA 1
    # a6 0  0  0  0  1  NA
    # score = 0.466666...
    assert 0.46 < c.score_answers(q1, [a1, a2, a3, a4, a5, a6]) < 0.47
コード例 #6
0
 def __init__(self, questions: List[Question]) -> None:
     """
     Initialize a new survey that contains every question in <questions>.
     This new survey should use a HomogeneousCriterion as a default criterion
     and should use 1 as a default weight.
     """
     self._questions = questions
     self._default_criterion = HomogeneousCriterion()
     self._default_weight = 1
     self._criteria = dict()
     self._weights = dict()
コード例 #7
0
ファイル: survey.py プロジェクト: RoneyThomas/csc148
 def __init__(self, questions: List[Question]) -> None:
     """
     Initialize a new survey that contains every question in <questions>.
     This new survey should use a HomogeneousCriterion as a default criterion
     and should use 1 as a default weight.
     """
     # TODO: complete the body of this method
     self._questions = {q.id: q for q in questions}
     self._criteria, self._weights = {}, {}
     self._default_weight = 1
     self._default_criterion = HomogeneousCriterion()  # Am i doing it right?
コード例 #8
0
 def __init__(self, questions: List[Question]) -> None:  # done
     """
     Initialize a new survey that contains every question in <questions>.
     This new survey should use a HomogeneousCriterion as a default criterion
     and should use 1 as a default weight.
     """
     self._ques = questions
     self._questions = {}  # dict of question id to question
     for quest in self._ques:
         self._questions[quest.id] = quest
     self._criteria = {}  # dict question id to criterion
     self._default_criterion = HomogeneousCriterion()
     self._default_weight = 1
     self._weights = {}  # question id to weight of question
コード例 #9
0
 def __init__(self, questions: List[Question]) -> None:
     """
     Initialize a new survey that contains every question in <questions>.
     This new survey should use a HomogeneousCriterion as a default criterion
     and should use 1 as a default weight.
     """
     self._questions = {}
     for q in questions:
         if q.id not in self._questions:
             self._questions[q.id] = q
     self._criteria = {}
     self._weights = {}
     self._default_criterion = HomogeneousCriterion()
     self._default_weight = 1
コード例 #10
0
 def __init__(self, questions: List[Question]) -> None:
     """
     Initialize a new survey that contains every question in <questions>.
     This new survey should use a HomogeneousCriterion as a default criterion
     and should use 1 as a default weight.
     """
     # TODO: complete the body of this method
     questions_dict = {}
     for question in questions:
         questions_dict[question.id] = question
     self._questions = questions_dict
     self._criteria = {}
     self._weights = {}
     self._default_criterion = HomogeneousCriterion()
     self._default_weight = 1
コード例 #11
0
    def __init__(self, questions: List[Question]) -> None:
        """
        Initialize a new survey that contains every question in <questions>.
        This new survey should use a HomogeneousCriterion as a default criterion
        and should use 1 as a default weight.
        """
        # create empty dictionary
        self._questions = {}
        self._criteria = {}
        self._weights = {}
        default_c = HomogeneousCriterion()

        for question in questions:
            self._questions[question.id] = question
            self._criteria[question.id] = default_c
            self._weights[question.id] = 1

        self._default_criterion = default_c
        self._default_weight = 1
コード例 #12
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
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
コード例 #13
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
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]
コード例 #14
0
ファイル: tests.py プロジェクト: xhd131142117/148-a1
def test_criterion_homo_score_answer_valid_one() -> None:
    """A test for score_answer() in class HomogeneousCriterion."""
    q1 = YesNoQuestion(1, 'ABC')
    a1 = Answer(True)
    c = HomogeneousCriterion()
    assert c.score_answers(q1, [a1]) == 1.0
コード例 #15
0
ファイル: tests-roney.py プロジェクト: RoneyThomas/csc148
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]