Ejemplo n.º 1
0
    def test_repr(self):
        vs = ValueSet()
        assert repr(vs) == "ValueSet()"

        vs.add_value(123)
        vs.add_range(10, 20)
        assert repr(vs) == "ValueSet(123, (10, 20))"
Ejemplo n.º 2
0
    def test_ranges(self):
        vs = ValueSet()

        vs.add_range(10, 20)
        assert 9 not in vs
        assert 9.9999 not in vs
        assert 10 in vs
        assert 15 in vs
        assert 20 in vs
        assert 20.0001 not in vs
        assert 21 not in vs

        vs.add_range(30, 40)
        assert 9 not in vs
        assert 9.9999 not in vs
        assert 10 in vs
        assert 15 in vs
        assert 20 in vs
        assert 20.0001 not in vs
        assert 21 not in vs
        assert 29 not in vs
        assert 29.9999 not in vs
        assert 30 in vs
        assert 35 in vs
        assert 40 in vs
        assert 40.0001 not in vs
        assert 41 not in vs
Ejemplo n.º 3
0
 def test_add_range_overlap_single_values(self):
     vs = ValueSet()
     vs.add_value(5)
     vs.add_value(10)
     vs.add_value(15)
     vs.add_value(20)
     vs.add_value(25)
     vs.add_range(10, 20)
     assert vs._values == set([5, 25])
     assert vs._ranges == set([(10, 20)])
Ejemplo n.º 4
0
    def test_iter(self):
        vs = ValueSet()

        assert set(vs) == set()

        vs.add_value(1)
        vs.add_value(2)
        vs.add_value(3)
        assert set(vs) == set([1, 2, 3])

        vs.add_range(10, 20)
        vs.add_range(30, 40)
        assert set(vs) == set([1, 2, 3, (10, 20), (30, 40)])
Ejemplo n.º 5
0
    def test_combination(self):
        vs = ValueSet()
        vs.add_value(1)
        vs.add_range(10, 20)

        assert 0 not in vs
        assert 1 in vs
        assert 2 not in vs
        assert 9 not in vs
        assert 10 in vs
        assert 15 in vs
        assert 20 in vs
        assert 21 not in vs
Ejemplo n.º 6
0
    def test_iter_values(self):
        vs = ValueSet()

        assert set(vs.iter_values()) == set()

        vs.add_value(1)
        vs.add_value(2)
        vs.add_value(3)
        assert set(vs.iter_values()) == set([1, 2, 3])

        vs.add_range(10, 13)
        vs.add_range(15, 20)
        assert set(vs.iter_values()) == set(
            [1, 2, 3, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20])
Ejemplo n.º 7
0
    def test_add_value(self):
        vs = ValueSet()

        # Duplicate values not allowed
        vs.add_value(123)
        vs.add_value(123)
        assert list(vs) == [123]

        # Values already in a range not allowed
        vs.add_range(10, 20)
        vs.add_value(10)
        vs.add_value(15)
        vs.add_value(20)
        assert list(vs) == [123, (10, 20)]
Ejemplo n.º 8
0
    def test_combine_value_sets(self):
        vs1 = ValueSet()
        vs1.add_value(1)
        vs1.add_range(10, 20)

        vs2 = ValueSet()
        vs2.add_value(2)
        vs2.add_range(20, 30)

        vs = vs1 + vs2

        assert 0 not in vs
        assert 1 in vs
        assert 2 in vs
        assert 3 not in vs
        assert 9 not in vs
        assert 10 in vs
        assert 15 in vs
        assert 20 in vs
        assert 25 in vs
        assert 30 in vs
        assert 31 not in vs
Ejemplo n.º 9
0
    def test_str(self):
        vs = ValueSet()

        assert str(vs) == "{<no values>}"

        vs.add_value(10)
        vs.add_value(20)
        vs.add_value(30)
        assert str(vs) == "{10, 20, 30}"

        vs.add_range(3, 7)
        vs.add_range(13, 17)
        vs.add_range(20, 25)
        vs.add_range(33, 37)
        assert str(vs) == "{3-7, 10, 13-17, 20-25, 30, 33-37}"
Ejemplo n.º 10
0
 def test_add_range_overlap_existing_ranges(self, ranges):
     vs = ValueSet()
     for r in ranges:
         vs.add_range(*r)
     assert vs._ranges == set([(10, 30)])
Ejemplo n.º 11
0
 def test_add_range_non_overlapping(self):
     vs = ValueSet()
     vs.add_range(10, 20)
     vs.add_range(30, 40)
     vs.add_range(22, 27)
     assert sorted(vs) == [(10, 20), (22, 27), (30, 40)]