Ejemplo n.º 1
0
def test_extrema():
    x = PreorderedSet(range(4))
    x.learn(0, 1, LT)
    x.learn(1, 2, LT)
    assert x.mins() == x.maxes() == set()
    x.learn(2, 3, EQ)
    assert x.mins() == {0}
    assert x.maxes() == {2, 3}
    assert x.maxes(among = {0, 1, 3}) == {3}
    assert x.extreme(n = 2) == {2, 3}
    assert x.extreme(n = 3) == {1, 2, 3}
Ejemplo n.º 2
0
def test_extreme_n():
    x = PreorderedSet(l + str(i)
        for l in "wxyz"
        for i in range(3))
    for a, b in choose2(x.elements):
        x.learn(a, b, Relation.cmp(a[0], b[0]))

    assert (x.maxes() == x.extreme(2) == x.extreme(3) ==
        {"z0", "z1", "z2"})
    assert (x.extreme(4) == x.extreme(5) == x.extreme(6) ==
        {"z0", "z1", "z2", "y0", "y1", "y2"})
    def xb(n):
        return x.extreme(n, bottom = True)
    assert (x.mins() == xb(2) == xb(3) ==
        {"w0", "w1", "w2"})
    assert (xb(4) == xb(5) == xb(6) ==
        {"w0", "w1", "w2", "x0", "x1", "x2"})