コード例 #1
0
def test_compatibility_measure_error():
    """ Test if wrong measure raises Exception error """
    a = tuple([1.0, 0.8])
    b = tuple([2.0, 0.5])
    with pytest.raises(Exception) as excinfo:
        group_graph.compatibility(a, b, objective_measures=["su", "mu"])
    exception_msg = excinfo.value.args[0]
    assert exception_msg == "Invalid measure"
コード例 #2
0
def test_compatibility_length():
    """ Test if exception message is raised by unequal students' scores """
    a = tuple([1.0])
    b = tuple([2.0, 0.5])
    with pytest.raises(Exception) as excinfo:
        group_graph.compatibility(a, b)
    exception_msg = excinfo.value.args[0]
    assert exception_msg == "Tuples passed to compatibility() must have same size."
コード例 #3
0
def test_compatibility_measure_average():
    """ Test if measure of different student scores return an average """
    a = [1, 1]
    b = [0, 1]
    output = group_graph.compatibility(a, b)
    expected_output = 1.5
    assert output == expected_output
コード例 #4
0
def test_compatibility_objective_weights():
    """ Test if objective_weights returns the objective weights of students """
    a = [1, 1]
    b = [0, 0.5]
    objective_weights = (2.0, 1.0)
    output = group_graph.compatibility(a, b, objective_weights)
    expected_output = 1.75
    assert output == expected_output
コード例 #5
0
def test_compatibility_measure_callable():
    """ Gives a callable measure to compatibility and tests if it is used """
    def score(a, b):
        return a + b

    a = [1, 1]
    b = [0, 0.5]
    output = group_graph.compatibility(a, b, objective_measures=[score, score])
    assert output == sum([1, 1.5])
コード例 #6
0
def test_compatibility_measure_match():
    """ Test if measure of different student scores are both equal """
    a = [1, 0]
    b = [1, 0.5]
    objective_measures = ("match", "match")
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=objective_measures)
    assert output == sum([1, 0])
コード例 #7
0
def test_compatibility_measure_preset():
    """ Test all preset measures """
    a = [1, 1]
    b = [0, 0.5]

    output = group_graph.compatibility(a, b, objective_measures=["avg", "avg"])
    assert output == sum([0.5, 0.75])
    output = group_graph.compatibility(a, b, objective_measures=["max", "max"])
    assert output == sum([1, 1])
    output = group_graph.compatibility(a, b, objective_measures=["min", "min"])
    assert output == sum([0, 0.5])
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=["match", "match"])
    assert output == sum([0, 0])
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=["diff", "diff"])
    assert output == sum([1, 0.5])
コード例 #8
0
def test_compatibility_measure_diff():
    """ Test if measure of different student scores returns an absolute value difference """
    a = [1, 0]
    b = [0, 0.5]
    objective_measures = ("diff", "diff")
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=objective_measures)
    expected_output = 1.5
    assert output == expected_output
コード例 #9
0
def test_compatibility_measure_min():
    """ Test if measure of different student scores return a minimum """
    a = [1, 0]
    b = [0, 0.5]
    objective_measures = ("min", "min")
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=objective_measures)
    expected_output = 0
    assert output == expected_output
コード例 #10
0
def test_compatibility_objective_measures():
    """ Test if objective_measures returns the objective measure of students """
    a = [0, 1]
    b = [0.75, 0.75]
    objective_measures = ("avg", "match")
    output = group_graph.compatibility(a,
                                       b,
                                       objective_measures=objective_measures)
    expected_output = 0.375
    assert output == expected_output