Example #1
0
def test_pareto_update_unique():
    """ Test creating Pareto front by updating one by one. """
    list_ = [(1, 2, 3), (3, 2, 1), (0, 5, 0)]
    pf = ParetoFront()

    for i in range(len(list_)):
        pf.update(list_[i])
        assert list(pf) == list_[:i + 1]
Example #2
0
def test_pareto_front_custom_function():
    """ Test construction of Pareto front with custom object and value function. """
    class A:
        def __init__(self, v1, v2):
            self.v1 = v1
            self.v2 = v2

    item1, item2, item3 = A(1, 2), A(2, 1), A(3, 1)
    pf = ParetoFront(get_values_fn=lambda x: (x.v1, x.v2))

    pf.update(item1)
    assert list(pf) == [item1]

    pf.update(item2)
    assert list(pf) == [item1, item2]

    pf.update(item3)
    assert list(pf) == [item1, item3]