diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2009-09-17 14:46:27 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2009-09-17 14:46:27 +0000 |
| commit | 2666460661d04f79b9c9bf7a6d4c4a9a1ac2ece5 (patch) | |
| tree | 4e1288a4c32417ed9cc104491b0a370c8221d1a6 /qpid/python | |
| parent | acc1d4c9eb818e038ab48143ddbce3fd51397cb2 (diff) | |
| download | qpid-python-2666460661d04f79b9c9bf7a6d4c4a9a1ac2ece5.tar.gz | |
added some empty, min, and max to RangedSet
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@816221 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
| -rw-r--r-- | qpid/python/qpid/datatypes.py | 18 | ||||
| -rw-r--r-- | qpid/python/tests/datatypes.py | 28 |
2 files changed, 46 insertions, 0 deletions
diff --git a/qpid/python/qpid/datatypes.py b/qpid/python/qpid/datatypes.py index f832ddae34..61643715e4 100644 --- a/qpid/python/qpid/datatypes.py +++ b/qpid/python/qpid/datatypes.py @@ -234,6 +234,24 @@ class RangedSet: def add(self, lower, upper = None): self.add_range(Range(lower, upper)) + def empty(self): + for r in self.ranges: + if r.lower <= r.upper: + return False + return True + + def max(self): + if self.ranges: + return self.ranges[-1].upper + else: + return None + + def min(self): + if self.ranges: + return self.ranges[0].lower + else: + return None + def __iter__(self): return iter(self.ranges) diff --git a/qpid/python/tests/datatypes.py b/qpid/python/tests/datatypes.py index b00e5e78f8..00e649d6cf 100644 --- a/qpid/python/tests/datatypes.py +++ b/qpid/python/tests/datatypes.py @@ -148,6 +148,34 @@ class RangedSetTest(TestCase): assert range.lower == 0 assert range.upper == 8 + def testEmpty(self): + s = RangedSet() + assert s.empty() + s.add(0, -1) + assert s.empty() + s.add(0, 0) + assert not s.empty() + + def testMinMax(self): + s = RangedSet() + assert s.max() is None + assert s.min() is None + s.add(0, 10) + assert s.max() == 10 + assert s.min() == 0 + s.add(0, 5) + assert s.max() == 10 + assert s.min() == 0 + s.add(0, 11) + assert s.max() == 11 + assert s.min() == 0 + s.add(15, 20) + assert s.max() == 20 + assert s.min() == 0 + s.add(-10, -5) + assert s.max() == 20 + assert s.min() == -10 + class RangeTest(TestCase): def testIntersect1(self): |
