Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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