コード例 #1
0
    def test_inclusive_range(self):
        r = Restriction("[1.0]")
        assert str(r.lower_bound) == "1.0"
        assert r.lower_bound_inclusive
        assert str(r.upper_bound) == "1.0"
        assert r.upper_bound_inclusive

        assert "0.8" not in r
        assert "1.0" in r
        assert "1.1" not in r
        assert "2.0" not in r

        r = Restriction("[1.2,1.3]")
        assert str(r.lower_bound) == "1.2"
        assert r.lower_bound_inclusive
        assert str(r.upper_bound) == "1.3"
        assert r.upper_bound_inclusive

        assert "0.8" not in r
        assert "1.1" not in r
        assert "1.2" in r
        assert "1.2.1" in r
        assert "1.3" in r
        assert "1.3.1" not in r
        assert "2.0" not in r
コード例 #2
0
 def test_no_lower_limit(self):
     r = Restriction("(,1.0]")
     assert r.lower_bound is None
     assert not r.lower_bound_inclusive
     assert str(r.upper_bound) == "1.0"
     assert r.upper_bound_inclusive
     assert "0.1" in r
     assert "1.0" in r
     assert "1.1" not in r
     assert "2.0" not in r
コード例 #3
0
    def test_exclusive_lower_bound(self):
        r = Restriction("(1.0,2.0]")
        assert str(r.lower_bound) == "1.0"
        assert not r.lower_bound_inclusive
        assert str(r.upper_bound) == "2.0"
        assert r.upper_bound_inclusive

        assert "0.1" not in r
        assert "1.0" not in r
        assert "1.1" in r
コード例 #4
0
    def test_everyting_spec(self):
        r = Restriction("[,)")
        assert r.lower_bound is None
        assert r.lower_bound_inclusive
        assert r.upper_bound is None
        assert not r.upper_bound_inclusive

        assert "0.1.0" in r
        assert "1.0" in r
        assert "2.0" in r
コード例 #5
0
    def test_exclusive_upper_bound(self):
        r = Restriction("[1.0,2.0)")
        assert str(r.lower_bound) == "1.0"
        assert r.lower_bound_inclusive
        assert str(r.upper_bound) == "2.0"
        assert not r.upper_bound_inclusive

        assert "0.8" not in r
        assert "1.0" in r
        assert "1.9" in r
        assert "2.0" not in r
        assert "3.0" not in r

        r = Restriction("[1.5,)")
        assert str(r.lower_bound) == "1.5"
        assert r.lower_bound_inclusive
        assert r.upper_bound is None
        assert not r.upper_bound_inclusive

        assert "0.8" not in r
        assert "1.4" not in r
        assert "1.5" in r
        assert "100.3" in r
コード例 #6
0
 def test_string_repr(self):
     for input in ("[1.0]", "[1.0,)", "[1.0,2.0]", "[1.0,2.0)", "(1.0,2.0)",
                   "[,2.0]", "[,2.0)", "(,2.0)"):
         actual = str(Restriction(input))
         assert input == actual, \
             "Restriction(%s) == %s, wanted %s" % (input, actual, input)
コード例 #7
0
    def test_compare(self):
        r1 = Restriction("(1.0,2.0]")

        assert r1 == r1
        assert r1 == "(1.0,2.0]"
        assert 1 < r1