Пример #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))"
Пример #2
0
    def test_individual_values(self):
        vs = ValueSet()

        vs.add_value(123)
        assert 123 in vs
        assert 321 not in vs

        vs.add_value("foo")
        assert 123 in vs
        assert "foo" in vs
        assert 321 not in vs
        assert "bar" not in vs
Пример #3
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)])
Пример #4
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
Пример #5
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])
Пример #6
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}"
Пример #7
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
Пример #8
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)])
Пример #9
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)]
Пример #10
0
 def test_str_uses_repr(self):
     vs = ValueSet()
     vs.add_value("foo")
     assert str(vs) == "{'foo'}"