示例#1
0
def test___eq__():
    """Test == operator."""
    VS1, VS2 = ValueSet([]), ValueSet([])
    assert VS1 == VS2
    VS1, VS2 = ValueSet([1]), ValueSet([1])
    assert VS1 == VS2
    # Test out of order
    VS1, VS2 = ValueSet([1, 3, 5]), ValueSet([5, 3, 1])
    assert VS1 == VS2
    VS1 = ValueSet([1, 'b', 3, 'c', 'a', 5])
    VS2 = ValueSet([5, 3, 1, 'a', 'b', 'c'])
    assert VS1 == VS2
    VS1 = ValueSet([1, 'b', 3, 'c', 'a', 5, Interval(1, 10), Point(1.0)])
    VS2 = ValueSet([Interval(1, 10), 5, 3, 1, Point(1.0), 'a', 'b', 'c'])
    assert VS1 == VS2
    VS1 = ValueSet([Point(1.0, 1.0)])
    VS2 = ValueSet([Point(1.0)])
    assert not VS1 == VS2
    # test type mismatch for Interval
    VS1, VS2 = ValueSet([Interval(1, 10)]), ValueSet([Interval(1.0, 10.0)])
    assert VS1 != VS2
    VS1, VS2 = ValueSet([LineSegment(Point(1.0), Point(2.0))]), ValueSet([LineSegment(Point(1.0), Point(2.0))])
    assert VS1 == VS2
    VS1, VS2 = ValueSet([LineSegment(Point(1.0), Point(2.0))]), ValueSet([LineSegment(Point(-1.0), Point(-2.0))])
    assert VS1 != VS2
示例#2
0
def test_unstringify():
    """Test unstringify function for LineSegment."""
    p1, p2 = Point(1.0), Point(2.0)
    p3, p4 = Point(1.0, 1.0, 1.0), Point(2.0, 2.0, 2.0)
    a = LineSegment(p1, p2)
    b = LineSegment(p3, p4)
    assert a == LineSegment.unstringify("L(P(1.0),P(2.0))")
    assert b == LineSegment.unstringify("L(P(1.0,1.0,1.0),P(2.0,2.0,2.0))")
示例#3
0
def test___repr__():
    """Test repr(LineSegment)."""
    p1, p2 = Point(1.0), Point(2.0)
    p3, p4 = Point(1.0, 1.0, 1.0), Point(2.0, 2.0, 2.0)
    a = LineSegment(p1, p2)
    b = LineSegment(p3, p4)
    assert repr(a) == "L(P(1.0),P(2.0))"
    assert repr(b) == "L(P(1.0,1.0,1.0),P(2.0,2.0,2.0))"
示例#4
0
def test___contains__():
    """Test in operator."""
    def test_AttributeError(member, segment):
        """Test constructor for AttributeErrors with given params."""
        with pytest.raises(AttributeError) as excinfo:
            member in segment

    a = LineSegment(Point(1.0), Point(2.0))
    b = LineSegment(Point(0.0), Point(2.0))
    c = LineSegment(Point(1.0), Point(3.0))
    d = LineSegment(Point(0.0), Point(3.0))
    e = LineSegment(Point('x'), Point('x'))
    p = Point(1.5)

    test_AttributeError('', a)
    test_AttributeError(None, a)
    test_AttributeError(object, a)

    assert a in a
    assert a in b
    assert b not in c
    assert a in c
    assert a in d
    assert a in e
    assert p in a
    assert p in b
    assert p in c
    assert p in d
    assert p in e

    a = LineSegment(Point(1.0, 1.0, 1.0), Point(2.0, 2.0, 2.0))
    b = LineSegment(Point(0.0, 0.0, 0.0), Point(2.0, 2.0, 2.0))
    c = LineSegment(Point(1.0, 1.0, 1.0), Point(3.0, 3.0, 3.0))
    d = LineSegment(Point(0.0, 0.0, 0.0), Point(3.0, 3.0, 3.0))
    e = LineSegment(Point('x', 'x', 'x'), Point('x', 'x', 'x'))
    p = Point(1.5, 1.5, 1.5)

    assert a in a
    assert a in b
    assert b not in c
    assert a in c
    assert a in d
    assert a in e
    assert p in a
    assert p in b
    assert p in c
    assert p in d
    assert p in e
示例#5
0
def test_meets():
    """Test meets wrapper for Point function."""
    a = LineSegment(Point(0.0, 0.0), Point(5.0, 5.0))
    b = LineSegment(Point(0.0, 0.0), Point(5.0, 5.0))
    p1 = Point(0.0, 0.0)
    p2 = Point(1.0, 1.0)
    p3 = Point(5.0, 5.0)
    assert LineSegment.meets(p1, a, b)
    assert LineSegment.meets(p2, a, b)
    assert LineSegment.meets(p3, a, b)
    c = LineSegment(Point(5.0, 0.0), Point(0.0, 5.0))
    p4 = Point(2.5, 2.5)
    assert not LineSegment.meets(p1, a, c)
    assert not LineSegment.meets(p2, a, c)
    assert not LineSegment.meets(p3, a, c)
    assert LineSegment.meets(p4, a, c)
示例#6
0
def test___contains__():
    """Test in operator for ValueSet object."""
    v = ValueSet([1, 2, 'a', 'b', False, True,
                  Interval(100, 1000),
                  Point(1.0), LineSegment(Point(0.0), Point(1.0))])
    assert 1 in v
    assert 2 in v
    assert 'a' in v
    assert 'b' in v
    assert False in v
    assert True in v
    assert LineSegment(Point(0.0), Point(1.0)) in v
    assert not LineSegment(Point(10.0), Point(1.0)) in v
    assert Interval(100, 1000) in v
    assert Point(1.0) in v
    assert not Interval(400, 500) in v
    assert not Interval(100.0, 1000.0) in v
    assert not Interval(100L, 1000L) in v
    assert not Point('x') in v
示例#7
0
def test___deepcopy__():
    """Test copy.deepcopy."""
    from copy import deepcopy
    a = LineSegment(Point(1.0), Point(2.0))
    b = deepcopy(a)

    assert a == b
    assert a is not b
    assert a[0] is not b[0]
    assert a[1] is not b[1]
示例#8
0
def test___init__():
    """Test ValueSet Constructor"""
    def test_TypeError(valueset):
        """Test an individual ValueSet construction."""
        with pytest.raises(TypeError) as excinfo:
            ValueSet(valueset)

    # test value_set errors
    test_TypeError(1)
    test_TypeError(1.0)
    test_TypeError("")
    test_TypeError(object)
    test_TypeError(Interval(0, 10))
    test_TypeError(Point(0.0))

    VS1 = ValueSet([Interval(20, 100)])
    VS = ValueSet([LineSegment(Point(1.0), Point(2.0)),
                   LineSegment(Point(1.0), Point(2.0))])

    assert VS == ValueSet([LineSegment(Point(1.0), Point(2.0))])
示例#9
0
def test__parse():
    """Test _parse function for ValueSet."""
    def test_TypeError(values):
        """Test TypeError raising in split_by_types."""
        with pytest.raises(TypeError) as excinfo:
            ValueSet._parse(values)

    # test standard type parsing
    standard_types = ValueSet._parse(
        [-1, -2, -1.0, -1.5, -1L, -2L, 'a', 'b', True, False,
         Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L), Point(1.0)])

    assert standard_types == [-1.5, -1.0, 'a', 'b',
                              False, True, Interval(-2, 10),
                              Interval(0.0, 10.0), Interval(-2L, 10L),
                              Point(1.0)]

    # test single numbers being filtered by intervals
    number_filters = ValueSet._parse(
        [-2, 1, -1.5, 1.0, -2L, 1L,
            Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L)])

    assert number_filters == [-2, -1.5, -2L, Interval(0, 10),
                              Interval(0.0, 10.0), Interval(0L, 10L)]

    interval_collapsing = ValueSet._parse(
        [Interval(0, 10), Interval(5, 15), Interval(7, 11), Interval(15, 25),
         Interval(-10, 500), Interval(0.0, 10.4), Interval(5.56, 15.33),
         Interval(7.765, 11.001), Interval(15.32, 25.77),
         Interval(-10.2, 500.442), Interval(0L, 10L), Interval(5L, 15L),
         Interval(7L, 11L), Interval(15L, 25L), Interval(-10L, 500L)])

    assert interval_collapsing == [
        Interval(-10, 500), Interval(-10.2, 500.442), Interval(-10L, 500L)]

    point_duplicates = ValueSet._parse([Point(1.0), Point(1.0), Point('x')])

    assert point_duplicates == [Point(1.0), Point('x')]

    line_segment_duplicates = ValueSet._parse(
        [LineSegment(Point(1.0), Point(0.0)),
         LineSegment(Point(1.0), Point(0.0)),
         LineSegment(Point('x'), Point('x')),
         LineSegment(Point('x', 'x'), Point('x', 'x')),
         LineSegment(Point('x', 'x'), Point('x', 'x'))])

    assert line_segment_duplicates == [LineSegment(Point(1.0), Point(0.0)),
                                       LineSegment(Point('x'), Point('x')),
                                       LineSegment(Point('x', 'x'), Point('x', 'x'))]
示例#10
0
def test__split_by_types():
    """Test split_by_types used in parsing."""
    def test_AttributeError(values):
        """Test AttributeError raising in split_by_types."""
        with pytest.raises(AttributeError) as excinfo:
            ValueSet._split_by_types(values)

    def test_TypeError(values):
        """Test TypeError raising in split_by_types."""
        with pytest.raises(TypeError) as excinfo:
            ValueSet._split_by_types(values)

    # test error raising
    i = Interval(1, 10)
    i._is_different_object = True
    ValueSet.add_object_type("_is_different_object")
    test_AttributeError([i])
    test_TypeError([object])

    # test output
    types = ValueSet._split_by_types(
        [1, 2, 1.0, 1.5, 1L, 2L, 'a', 'b', True, False,
         Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L),
         Point(1.0), Point(1.0, 1.0), Point('x'),
         LineSegment(Point(0.0), Point(1.0)),
         LineSegment(Point("x", "x", "x"), Point("x", "x", "x"))])

    d = {
        int: [1, 2], float: [1.0, 1.5], long: [1L, 2L],
        str: ['a', 'b'], bool: [True, False],
        "_is_Interval": [Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L)],
        "_is_Point": [Point(1.0), Point(1.0, 1.0), Point('x')],
        "_is_LineSegment": [LineSegment(Point(0.0), Point(1.0)), LineSegment(Point("x", "x", "x"), Point("x", "x", "x"))]}

    empty = ValueSet._split_by_types([])
    assert empty == {}
    assert d == types
示例#11
0
def test___getitem__():
    """Test indexing."""
    def test_TypeError(index, segment):
        """Test constructor for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            segment[index]

    def test_IndexError(index, segment):
        """Test constructor for IndexErrors with given params."""
        with pytest.raises(IndexError) as excinfo:
            segment[index]

    p1, p2 = Point(1.0), Point(2.0)
    a = LineSegment(p1, p2)
    assert a[0] == p1
    assert a[1] == p2

    test_TypeError(a, a)
    test_TypeError('', a)
    test_TypeError(None, a)
    test_TypeError(object, a)
    test_IndexError(-1, a)
    test_IndexError(2, a)
示例#12
0
def test___ne__():
    """Test != operator."""
    assert not LineSegment(Point(1.0), Point(1.0)) != LineSegment(Point(1.0), Point(1.0))
    assert LineSegment(Point(1.0), Point(1.0)) != LineSegment(Point('x'), Point('x'))
    assert LineSegment(Point(1.0), Point(1.0)) != LineSegment(Point(1.0, 1.0), Point(1.0, 1.0))
示例#13
0
def test___sub__():
    """Test - operator for set theoretic difference."""

    VS1 = ValueSet([
        -5,
        32L,
        555.678,
        'b', 'c',
        False,
        Interval(20, 100), Interval(2L, 5L),
        LineSegment(Point(0.0), Point(1.0)),
        LineSegment(Point(0.0, 0.0), Point(1.0, 1.0))])

    VS2 = ValueSet([
        -1, -3,
        15L, 32L,
        167.4,
        'a', 'c',
        False,
        Interval(1, 10),
        Interval(10.0, 75.4), Interval(2L, 5L),
        LineSegment(Point(10.0), Point(1.0)),
        LineSegment(Point(0.0, 0.0), Point(1.0, 1.0))])

    assert VS1 - VS2 == ValueSet([-5, 555.678, 'b', Interval(20, 100),
                                  LineSegment(Point(0.0), Point(1.0))])

    VSA = ValueSet([
        -1, -3, -5,
        15L, 32L,
        167.4, 555.678,
        'a', 'b', 'c',
        True, False,
        Interval(1, 10), Interval(20, 100),
        Interval(10.0, 75.4), Interval(2L, 5L)])

    VSB = ValueSet([
        -1, -3, -5,
        15L, 32L,
        167.4, 555.678,
        'a', 'b', 'c',
        True, False,
        Interval(1, 10), Interval(20, 100),
        Interval(10.0, 75.4), Interval(2L, 5L)])

    VSC = ValueSet([
        -1, -3,
        32L,
        167.4,
        'c',
        False,
        Interval(1, 10), Interval(2L, 5L),
        Point(0.0)])

    VSD = ValueSet([
        -1, -3,
        32L,
        555.678,
        'b', 'c',
        False,
        Interval(1, 10), Interval(10.0, 75.4), Interval(2L, 5L),
        Point(1.0, 1.0)])

    VSE = ValueSet([
        -1, -5,
        15L,
        167.4,
        'a',
        True,
        Interval(1, 10), Interval(20, 100),
        Point(3.4)])

    assert VSA - VSA == ValueSet([])
    assert VSA - VSB == ValueSet([])
    assert VSA - VSC == ValueSet([-5, 15L, 555.678, 'a', 'b', True,
                                  Interval(20, 100), Interval(10.0, 75.4)])
    assert VSC - VSA == ValueSet([Point(0.0)])
    assert VSD - VSE == ValueSet([-3, 32L, 555.678, 'b', 'c', False,
                                  Interval(10.0, 75.4), Interval(2L, 5L),
                                  Point(1.0, 1.0)])
    assert VSE - VSD == ValueSet([-5, 15L, 167.4, 'a', True,
                                  Interval(20, 100),
                                  Point(3.4)])

    VSF = ValueSet([Interval(1, 10)])
    VSG = ValueSet([1, 5, 10])
    assert VSF - VSG == ValueSet([Interval(2, 4), Interval(6, 9)])
    VSH = ValueSet([2, 9])
    assert VSF - VSH == ValueSet([1, 10, Interval(3, 8)])
    VSI = ValueSet([2, 4, 6])
    assert VSF - VSI == ValueSet([1, 3, 5, Interval(7, 10)])

    VSJ = ValueSet([Interval(1L, 10L)])
    VSK = ValueSet([1L, 5L, 10L])
    assert VSJ - VSK == ValueSet([Interval(2L, 4L), Interval(6L, 9L)])
    VSL = ValueSet([2L, 9L])
    assert VSJ - VSL == ValueSet([1L, 10L, Interval(3L, 8L)])
    VSM = ValueSet([2L, 4L, 6L])
    assert VSJ - VSM == ValueSet([1L, 3L, 5L, Interval(7L, 10L)])

    VSN = ValueSet([Interval(1.0, 10.0)])
    VSO = ValueSet([1.0, 5.0, 10.0])
    assert VSN - VSO == ValueSet([Interval(1.00000000001, 4.99999999999),
                                  Interval(5.00000000001, 9.99999999999)])
    VSP = ValueSet([2.0, 9.0])
    assert VSN - VSP == ValueSet([Interval(1.0, 1.99999999999),
                                  Interval(2.00000000001, 8.99999999999),
                                  Interval(9.00000000001, 10.0)])
    VSQ = ValueSet([2.0, 4.0, 6.0])
    assert VSN - VSQ == ValueSet([Interval(1.0, 1.99999999999),
                                  Interval(2.00000000001, 3.99999999999),
                                  Interval(4.00000000001, 5.99999999999),
                                  Interval(6.00000000001, 10.0)])
    VSR = ValueSet([1.00000000001])
    assert VSN - VSR == ValueSet([1.0, Interval(1.00000000002, 10.0)])

    VSS = VSF + VSJ + VSN
    VST = VSG + VSK + VSO
    VSU = VSH + VSL + VSP
    VSV = VSI + VSM + VSQ

    assert VSS - VST == ValueSet([Interval(2, 4),
                                  Interval(6, 9),
                                  Interval(1.00000000001, 4.99999999999),
                                  Interval(5.00000000001, 9.99999999999),
                                  Interval(2L, 4L),
                                  Interval(6L, 9L)])

    assert VSS - VSU == ValueSet([1, 10, Interval(3, 8),
                                  1L, 10L, Interval(3L, 8L),
                                  Interval(1.0, 1.99999999999),
                                  Interval(2.00000000001, 8.99999999999),
                                  Interval(9.00000000001, 10.0)])

    assert VSS - VSV == ValueSet([1, 3, 5, Interval(7, 10),
                                  1L, 3L, 5L, Interval(7L, 10L),
                                  Interval(1.0, 1.99999999999),
                                  Interval(2.00000000001, 3.99999999999),
                                  Interval(4.00000000001, 5.99999999999),
                                  Interval(6.00000000001, 10.0)])

    VS1 = ValueSet([Interval(1, 10)])
    VS2 = ValueSet([Interval(1, 3), Interval(8, 10)])
    assert VS1 - VS2 == ValueSet([Interval(4, 7)])
    VS3 = ValueSet([Interval(-5, 3), Interval(8, 12)])
    assert VS1 - VS3 == ValueSet([Interval(4, 7)])
    VS4 = ValueSet([Interval(-5, 1), Interval(10, 12)])
    assert VS1 - VS4 == ValueSet([Interval(2, 9)])
    VS5 = ValueSet([Interval(4, 7)])
    assert VS1 - VS5 == ValueSet([Interval(1, 3), Interval(8, 10)])

    VS6 = ValueSet([Interval(1L, 10L)])
    VS7 = ValueSet([Interval(1L, 3L), Interval(8L, 10L)])
    assert VS6 - VS7 == ValueSet([Interval(4L, 7L)])
    VS8 = ValueSet([Interval(-5L, 3L), Interval(8L, 12L)])
    assert VS6 - VS8 == ValueSet([Interval(4L, 7L)])
    VS9 = ValueSet([Interval(-5L, 1L), Interval(10L, 12L)])
    assert VS6 - VS9 == ValueSet([Interval(2L, 9L)])
    VS10 = ValueSet([Interval(4L, 7L)])
    assert VS6 - VS10 == ValueSet([Interval(1L, 3L), Interval(8L, 10L)])

    VS11 = ValueSet([Interval(1.0, 10.0)])
    VS12 = ValueSet([Interval(1.0, 3.0), Interval(8.0, 10.0)])
    assert VS11 - VS12 == ValueSet([Interval(3.00000000001, 7.99999999999)])
    VS13 = ValueSet([Interval(-5.0, 3.0), Interval(8.0, 12.0)])
    assert VS11 - VS13 == ValueSet([Interval(3.00000000001, 7.99999999999)])
    VS14 = ValueSet([Interval(-5.0, 1.0), Interval(10.0, 12.0)])
    assert VS11 - VS14 == ValueSet([Interval(1.00000000001, 9.99999999999)])
    VS15 = ValueSet([Interval(4.0, 7.0)])
    assert VS11 - VS15 == ValueSet([Interval(1.0, 3.99999999999),
                                    Interval(7.00000000001, 10.0)])

    VS01 = ValueSet([Interval(1, 10)])
    VS02 = ValueSet([Interval(1, 3), 5, Interval(8, 10)])
    assert VS01 - VS02 == ValueSet([4, Interval(6, 7)])
    VS06 = ValueSet([Interval(1L, 10L)])
    VS07 = ValueSet([Interval(1L, 3L), 5L, Interval(8L, 10L)])
    assert VS06 - VS07 == ValueSet([4L, Interval(6L, 7L)])
    VS011 = ValueSet([Interval(1.0, 10.0)])
    VS012 = ValueSet([Interval(1.0, 3.0), 5.0, Interval(8.0, 10.0)])
    assert VS011 - VS012 == ValueSet([Interval(3.00000000001, 4.99999999999),
                                      Interval(5.00000000001, 7.99999999999)])

    assert ValueSet([0]) == \
        ValueSet([Interval(0, 9)]) - ValueSet([Interval(1, 9)])
    assert ValueSet([0, 10]) == \
        ValueSet([Interval(0, 10)]) - ValueSet([Interval(1, 9)])

    assert ValueSet([10]) == \
        ValueSet([Interval(0, 10)]) - ValueSet([Interval(0, 9)])

    assert ValueSet([Interval(0, 1), Interval(9, 10)]) == \
        ValueSet([Interval(0, 10)]) - ValueSet([Interval(2, 8)])
示例#14
0
def test___eq__():
    """Test == operator."""
    assert LineSegment(Point(1.0), Point(1.0)) == LineSegment(Point(1.0), Point(1.0))
    assert not LineSegment(Point(1.0), Point(1.0)) == LineSegment(Point('x'), Point('x'))
    assert not LineSegment(Point(1.0), Point(1.0)) == LineSegment(Point(1.0, 1.0), Point(1.0, 1.0))
示例#15
0
def test__key():
    """Test key used in hashing."""
    a = LineSegment(Point(1.0), Point(2.0))
    assert a._key() == (Point(1.0), Point(2.0))
示例#16
0
def test___hash__():
    """Test hash(LineSegment)."""
    p1, p2 = Point(1.0), Point(2.0)
    a = LineSegment(p1, p2)
    assert hash(a) == 2847735836036288514
示例#17
0
def test___iadd__():
    """Test + operator for ValueSet."""
    VSA = ValueSet([
        -5,
        15L,
        167.4,
        'c',
        True,
        Interval(1, 10),
        Interval(10.0, 75.4)])

    VSB = ValueSet([
        -2,
        33L,
        555.679,
        'e',
        False,
        Point(1.0, 1.0),
        Interval(2L, 5L)])

    VSA += VSB
    assert VSA == ValueSet([-5, -2, 15L, 33L, 167.4, 555.679, 'c', 'e',
                           True, False, Interval(1, 10), Interval(10.0, 75.4),
                           Interval(2L, 5L), Point(1.0, 1.0)])
    VSA += VSA
    assert VSA == VSA

    VSD = ValueSet([
        -2, -100,
        33L,
        555.679,
        'e',
        False,
        Point(1.0, 1.0),
        Interval(2L, 5L)])

    VSE = ValueSet([
        -2, -5, -100,
        33L,
        555.679,
        'e',
        False,
        Point(1.0, 1.0),
        Interval(2L, 5L)])

    VSF = ValueSet([
        -2, -5, -100,
        33L,
        555.679,
        'e',
        False,
        Point(1.0, 1.0),
        Interval(2L, 5L),
        LineSegment(Point(0.0), Point(1.0))])

    VSB += -100
    assert VSD == VSB
    VSB += [-5, -100]
    assert VSE == VSB
    VSB += LineSegment(Point(0.0), Point(1.0))
    assert VSF == VSB
示例#18
0
def test_total_ordering():
    """Test ."""
    a = LineSegment(Point(1.0), Point(2.0))
    b = LineSegment(Point(0.0), Point(2.0))
    c = LineSegment(Point(1.0), Point(3.0))
    d = LineSegment(Point(0.0), Point(3.0))
    e = LineSegment(Point('x'), Point('x'))

    assert a <= a
    assert not a < a
    assert a >= a
    assert not a > a
    assert a <= b
    assert a < b
    assert a <= c
    assert a < c
    assert a <= d
    assert a < d
    assert a <= e
    assert a < e
    assert b >= a
    assert b > a
    assert c >= a
    assert c > a
    assert d >= a
    assert d > a
    assert e >= a
    assert e > a
    assert a < b < d < e

    a = LineSegment(Point(1.0, 1.0, 1.0, 1.0), Point(2.0, 2.0, 2.0, 2.0))
    b = LineSegment(Point(0.0, 0.0, 0.0, 0.0), Point(2.0, 2.0, 2.0, 2.0))
    c = LineSegment(Point(1.0, 1.0, 1.0, 1.0), Point(3.0, 3.0, 3.0, 3.0))
    d = LineSegment(Point(0.0, 0.0, 0.0, 0.0), Point(3.0, 3.0, 3.0, 3.0))
    e = LineSegment(Point('x', 'x', 'x', 'x'), Point('x', 'x', 'x', 'x'))

    assert a <= a
    assert not a < a
    assert a >= a
    assert not a > a
    assert a <= b
    assert a < b
    assert a <= c
    assert a < c
    assert a <= d
    assert a < d
    assert a <= e
    assert a < e
    assert b >= a
    assert b > a
    assert c >= a
    assert c > a
    assert d >= a
    assert d > a
    assert e >= a
    assert e > a
    assert a < b < d < e

    a = LineSegment(Point(1.0, 1.0), Point(2.0, 2.0))
    b = LineSegment(Point(0.0, 1.0), Point(2.0, 2.0))

    assert not a < b
    assert not a > b
    assert not a <= b
    assert not a >= b
示例#19
0
def test___le__():
    """
    Test <, <=, >, >= total ordering operators for subset-superset relations.
    """
    VS0 = ValueSet([])
    VS1 = ValueSet([Interval(20, 100),
                    True, 1, 'b', 3, 'c', 'a', 5,
                    Interval(1, 10),
                    Point(0.0)])
    VS2 = ValueSet([Interval(1, 10),
                    5, 3, 1, 'a',
                    Interval(20, 100),
                    'b', True, 'c',
                    Point(0.0)])
    VS3 = ValueSet([Interval(1, 10),
                    5, 3, 1, 'a',
                    Interval(20, 100),
                    'b', True, 'c', False,
                    Point(0.0),
                    Point(0.0, 0.0)])
    VS4 = ValueSet([5, 3, 1, 17L, 2.67854, 'b', True, Point(0.0, 0.0)])
    VS5 = ValueSet([Interval(1, 10),
                    Interval(1.0, 10.0),
                    Interval(10L, 100L),
                    'b', True,
                    Point(0.0, 0.0)])

    assert not VS0 < VS0
    assert not VS1 < VS2
    assert VS0 < VS1
    assert VS1 < VS3
    assert VS0 <= VS0
    assert VS0 <= VS1
    assert VS1 <= VS2
    assert VS1 <= VS3
    assert not VS2 > VS3
    assert not VS3 > VS3
    assert not VS0 > VS0
    assert VS3 > VS2
    assert VS3 > VS1
    assert VS3 > VS0
    assert VS3 >= VS3
    assert VS3 >= VS1
    assert not VS2 >= VS3
    assert VS0 >= VS0

    # Test ints, floats, and longs being subsumed by Intervals during comp
    assert VS4 < VS5
    assert VS4 <= VS5
    assert VS5 > VS4
    assert VS5 >= VS4

    VS6 = ValueSet([LineSegment(Point(1.0, 1.0), Point(2.0, 2.0))])
    VS7 = ValueSet([LineSegment(Point(0.0, 0.0), Point(2.0, 2.0))])
    VS8 = ValueSet([LineSegment(Point(1.0, 1.0), Point(3.0, 3.0))])
    VS9 = ValueSet([LineSegment(Point(0.0, 0.0), Point(3.0, 3.0))])
    VS10 = ValueSet([LineSegment(Point("x", "x"), Point("x", "x"))])

    assert not VS6 < VS6
    assert VS6 <= VS6
    assert VS6 < VS7
    assert VS6 <= VS7
    assert VS6 < VS8
    assert VS6 <= VS8
    assert VS6 < VS9
    assert VS6 <= VS9
    assert VS6 < VS10
    assert VS6 <= VS10
    assert not VS6 > VS6
    assert VS6 >= VS6
    assert VS7 > VS6
    assert VS7 >= VS6
    assert VS8 > VS6
    assert VS8 >= VS6
    assert VS9 > VS6
    assert VS9 >= VS6
    assert VS10 > VS6
    assert VS10 >= VS6
示例#20
0
 def test_ValueError(start_point, end_point):
     """Test constructor for ValueErrors with given params."""
     with pytest.raises(ValueError) as excinfo:
         LineSegment(start_point, end_point)
示例#21
0
def test___add__():
    """Test + operator for ValueSet."""
    def test_TypeError(valueset, object_type):
        """Test TypeError raising in add_object_type."""
        with pytest.raises(TypeError) as excinfo:
            valueset + object_type

    VSA = ValueSet([
        -5,
        15L,
        167.4,
        'c',
        True,
        Interval(1, 10),
        Interval(10.0, 75.4)])

    VSB = ValueSet([
        -2,
        33L,
        555.679,
        'e',
        False,
        Point(1.0, 1.0),
        Interval(2L, 5L)])

    VSC = VSA + VSB
    assert VSC == ValueSet([-5, -2, 15L, 33L, 167.4, 555.679, 'c', 'e',
                           True, False, Interval(1, 10), Interval(10.0, 75.4),
                           Interval(2L, 5L), Point(1.0, 1.0)])
    assert VSA == VSA + VSA

    VSD = ValueSet([
        -5, -100,
        15L,
        167.4,
        'c',
        True,
        Interval(1, 10),
        Interval(10.0, 75.4)])

    VSE = ValueSet([
        -5, -100,
        15L,
        167.4,
        'c',
        True,
        Interval(1, 10),
        Interval(10.0, 75.4),
        LineSegment(Point(1.0), Point(2.0))])

    VSF = ValueSet([
        -5, -100,
        15L,
        167.4,
        'c',
        True,
        Interval(1, 10),
        Interval(10.0, 75.4),
        LineSegment(Point(1.0), Point(2.0)),
        LineSegment(Point(2.0), Point(3.0))])

    assert VSD == VSA + -100
    assert VSD == VSA + [-5, -100]
    assert VSF == VSE + [LineSegment(Point(2.0), Point(3.0))]

    from vivid.classes.attribute import Attribute
    test_TypeError(VSA, Attribute("l", ['s']))