コード例 #1
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___iter__():
    """Test iterator for ValueSet object."""
    v = ValueSet([Interval(100, 105),
                  5, 3, 1, 'a',
                  Interval(2.0, 10.0),
                  'b', True, 'c', False,
                  Point(1.0)])
    assert [i for i in v.__iter__()] == v._values
コード例 #2
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___len__():
    """Test len() function for ValueSet object."""
    v = ValueSet([Interval(100, 105), 5, 3, 1, 'a',
                  Interval(2.0, 10.0),
                  'b', True, 'c', False,
                  Point(1.0)])
    v2 = ValueSet([])
    assert len(v) == 11
    assert len(v2) == 0
コード例 #3
0
ファイル: test_State.py プロジェクト: Wheatwizard/pyVivid
def test_set_ascription():
    """Test set_ascription function."""
    def test_TypeError(state, ascription, valueset):
        """Test set_ascription for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_ValueError(state, ascription, valueset):
        """Test set_ascription for ValueErrors with given params."""
        with pytest.raises(ValueError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_KeyError(state, ascription, valueset):
        """Test set_ascription for KeyErrors with given params."""
        with pytest.raises(KeyError) as excinfo:
            state.set_ascription(ascription, valueset)

    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    # test bad ao_pair types/values
    test_TypeError(s, [], ['R'])
    test_ValueError(s, (), ['R'])
    test_ValueError(s, (1, 2, 3), ['R'])
    test_ValueError(s, (1, 2), ['R'])
    test_ValueError(s, (1, ''), ['R'])
    test_ValueError(s, ('', 1), ['R'])
    # test bad types for ValueSet
    test_TypeError(s, ('color', 's1'), None)
    test_TypeError(s, ('color', 's1'), ())
    test_TypeError(s, ('color', 's1'), 'a')
    test_TypeError(s, ('color', 's1'), object)
    # test empty ValueSet catching
    test_ValueError(s, ('color', 's1'), [])
    test_ValueError(s, ('color', 's1'), set([]))
    test_ValueError(s, ('color', 's1'), ValueSet([]))
    # test bad ao-pair keys
    test_KeyError(s, ('color', 'bad object'), ['R'])
    test_KeyError(s, ('bad label', 's2'), ['R'])
    # test nonsubset valuesets
    test_ValueError(s, ('color', 's2'), ['a'])
    test_ValueError(s, ('color', 's2'), [1])

    s.set_ascription(('color', 's2'), ['R'])
    assert s[('color', 's2')] == ValueSet(['R'])
    # check reversion to superset is possible
    s.set_ascription(('color', 's2'), ['R', 'G'])
    assert s[('color', 's2')] == ValueSet(['R', 'G'])
    s.set_ascription(('size', 's1'), ['M', 'S'])
    assert s[('size', 's1')] == ValueSet(['S', 'M'])
コード例 #4
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___nonzero__():
    """Test boolean behavior for ValueSet."""
    v = ValueSet([Interval(100, 105),
                  5, 3, 1, 'a',
                  Interval(2.0, 10.0),
                  'b', True, 'c', False,
                  Point(1.0)])
    assert v
    v2 = ValueSet([])
    assert not v2
コード例 #5
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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'))]
コード例 #6
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___getitem__():
    """Test indexing for ValueSet object."""
    def test_TypeError(valueset, index):
        "test TypeError raising for indexing."
        with pytest.raises(TypeError):
            valueset._values[index]

    def test_IndexError(valueset, index):
        "test IndexError raising for indexing."
        with pytest.raises(IndexError):
            valueset._values[index]

    v = ValueSet([1, 2, 'a', 'b', False, True,
                  Interval(100, 1000),
                  Point(1.0)])
    test_TypeError(v, '')
    test_IndexError(v, 8)
    assert v[0] == 1
    assert v[0] is v._values[0]
    assert v[1] == 2
    assert v[1] is v._values[1]
    assert v[2] == 'a'
    assert v[2] is v._values[2]
    assert v[3] == 'b'
    assert v[3] is v._values[3]
    assert v[4] is False
    assert v[4] is v._values[4]
    assert v[5] is True
    assert v[5] is v._values[5]
    assert v[6] == Interval(100, 1000)
    assert v[6] is v._values[6]
    assert v[7] == Point(1.0)
    assert v[7] is v._values[7]
コード例 #7
0
ファイル: test_State.py プロジェクト: Wheatwizard/pyVivid
def test_add_object():
    """Test add object function to state."""
    def test_TypeError(state, obj, ascriptions=None):
        """Test constructor for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            state.add_object(obj, ascriptions)

    def test_ValueError(state, obj, ascriptions=None):
        """Test constructor for ValueErrors with given params."""
        with pytest.raises(ValueError) as excinfo:
            state.add_object(obj, ascriptions)

    color = Attribute("color", ['R', 'G', 'B'])
    a = AttributeStructure(color)
    o = ['s1']
    asys = AttributeSystem(a, o)

    s = State(asys)

    test_TypeError(s, None)
    test_TypeError(s, 1)
    test_TypeError(s, object)
    test_TypeError(s, "")
    test_TypeError(s, "a", 1)
    test_TypeError(s, "a", object)
    test_ValueError(s, "s1")
    test_ValueError(s, "a", {"s1": 1})
    test_ValueError(s, "a", {("s1"): 1})
    test_ValueError(s, "a", {("s1", 's1', 's1'): 1})
    test_ValueError(s, "a", {("color", "s1"): 1})
    test_ValueError(s, "a", {("s", "a"): 1})

    s.add_object("a")
    ascr = {
        ("color", "s1"): ValueSet(['R', 'G', 'B']),
        ("color", "a"): ValueSet(['R', 'G', 'B'])
    }
    assert s._ascriptions == ascr

    s = State(asys)
    s.add_object("a", {("color", "a"): ['R']})
    ascr = {
        ("color", "s1"): ValueSet(['R', 'G', 'B']),
        ("color", "a"): ValueSet(['R'])
    }
    assert s._ascriptions == ascr
コード例 #8
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___repr__():
    """Test repr() for ValueSet object."""
    v1 = ValueSet([1, 3, 5, 'a', 'b', 'c', False, True,
                  Interval(100, 105), Interval(2.0, 10.0),
                  Point(1.0)])
    v2 = ValueSet([Interval(100, 105),
                  5, 3, 1,
                  Point(1.0),
                  'a',
                   Interval(2.0, 10.0),
                   'b', True, 'c', False])
    v3 = ValueSet([])
    assert v1.__repr__() == "V(1, 3, 5, a, b, c, False, True, I(100, 105), I(2.0, 10.0), P(1.0))"
    # test out of order
    assert v2.__repr__() == "V(1, 3, 5, a, b, c, False, True, I(100, 105), I(2.0, 10.0), P(1.0))"
    # test empty
    assert v3.__repr__() == "V()"
コード例 #10
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___deepcopy__():
    """Test copy.deepcopy for ValueSet object."""
    import copy
    v = ValueSet([1, 3, 5, 'a', 'b', 'c', False, True,
                  Interval(100, 105), Interval(2.0, 10.0),
                  Point(1.0)])
    v_copy = copy.deepcopy(v)
    assert v == v_copy
    assert v is not v_copy
    assert v[8] is not v_copy[8]
    assert v[9] is not v_copy[9]
    assert v[10] is not v_copy[10]
コード例 #11
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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
コード例 #12
0
ファイル: test_State.py プロジェクト: Wheatwizard/pyVivid
def test___init__():
    """Test State constructor."""
    def test_TypeError(attribute_system, ascriptions={}):
        """Test constructor for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            State(attribute_system, ascriptions)

    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    # test no attribute system
    test_TypeError(a)
    test_TypeError(object)
    test_TypeError(None)
    # test bad ascriptions
    test_TypeError(asys, [])
    test_TypeError(asys, None)
    test_TypeError(asys, object)

    s = State(asys)
    assert s._attribute_system == asys
    assert s._attribute_system is not asys
    s = State(
        asys, {
            ('color', 's1'): ['R'],
            ('color', 's2'): ['B', 'G'],
            ('size', 's1'): ['M'],
            ('size', 's2'): ['L', 'S']
        })

    assert s[(('color', 's1'))] == ValueSet(['R'])
    assert s[(('color', 's2'))] == ValueSet(['G', 'B'])
    assert s[(('size', 's1'))] == ValueSet(['M'])
    assert s[(('size', 's2'))] == ValueSet(['L', 'S'])
コード例 #13
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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
コード例 #14
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
def test___setitem__():
    """Test ValueSet[key] = value assignment for ValueSet object."""
    def test_TypeError(valueset, key, value):
        """Test TypeError raising in index assignment."""
        with pytest.raises(TypeError) as excinfo:
            valueset[key] = value

    def test_ValueError(valueset, key, value):
        """Test ValueError raising in index assignment."""
        with pytest.raises(ValueError) as excinfo:
            valueset[key] = value

    def test_AttributeError(valueset, key, value):
        """Test AttributeError raising in index assignment."""
        with pytest.raises(AttributeError) as excinfo:
            valueset[key] = value

    def test_IndexError(valueset, key, value):
        """Test IndexError raising in index assignment."""
        with pytest.raises(IndexError) as excinfo:
            valueset[key] = value

    v = ValueSet([1, 3, 5, 'a', 'b', 'c', False, True,
                  Interval(100, 105),
                  Interval(2.0, 10.0),
                  Point(1.0)])

    v[0] = 1000
    assert v[0] == 1000
    # test invalid key types
    test_TypeError(v, '', 1)
    test_TypeError(v, object, 1)
    test_TypeError(v, None, 1)
    test_TypeError(v, 1.0, 1)
    test_TypeError(v, 1L, 1)
    # test duplicate value catching
    test_ValueError(v, 1, 1)
    test_IndexError(v, 11, -37)
    test_TypeError(v, 1, object)
コード例 #15
0
ファイル: test_State.py プロジェクト: Wheatwizard/pyVivid
def test___getitem__():
    """Test indexing for State"""
    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    ascr = {
        ('color', 's1'): ['R'],
        ('color', 's2'): ['B', 'G'],
        ('size', 's1'): ['M'],
        ('size', 's2'): ['L', 'S']
    }

    s = State(asys, ascr)

    assert s[('color', 's1')] == ValueSet(['R'])
    assert s[('color', 's2')] == ValueSet(['G', 'B'])
    assert s[('size', 's1')] == ValueSet(['M'])
    assert s[('size', 's2')] == ValueSet(['L', 'S'])

    assert s['color'] == [ValueSet(['R']), ValueSet(['B', 'G'])]
    assert s['size'] == [ValueSet(['M']), ValueSet(['L', 'S'])]
コード例 #16
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
 def test_ValueError(object_type):
     """Test ValueError raising in add_object_type."""
     with pytest.raises(ValueError) as excinfo:
         ValueSet.add_object_type(object_type)
コード例 #17
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
 def test_TypeError(valueset):
     """Test an individual ValueSet construction."""
     with pytest.raises(TypeError) as excinfo:
         ValueSet(valueset)
コード例 #18
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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
コード例 #19
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
 def test_TypeError(values):
     """Test TypeError raising in split_by_types."""
     with pytest.raises(TypeError) as excinfo:
         ValueSet._parse(values)
コード例 #20
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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)])
コード例 #21
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
 def test_AttributeError(values):
     """Test AttributeError raising in split_by_types."""
     with pytest.raises(AttributeError) as excinfo:
         ValueSet._split_by_types(values)
コード例 #22
0
ファイル: test_ValueSet.py プロジェクト: Wheatwizard/pyVivid
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