Maintenance will be performed on git.ligo.org, chat.ligo.org, containers.ligo.org, and docs.ligo.org on the morning of Tuesday 11th August 2020, starting at approximately 9am PDT. It is expected to take around 20 minutes and there will be a short period of downtime (less than five minutes) towards the end of the maintenance window. Please direct any comments, questions, or concerns to computing-help@ligo.org.

Commit 7c795bbb authored by Duncan Macleod's avatar Duncan Macleod

Merge branch 'python3-cmp' into 'master'

Fixed comparison operators for infinity on python3

See merge request !4
parents f3cf8f30 56940e78
Pipeline #24239 passed with stages
in 7 minutes and 38 seconds
......@@ -137,18 +137,23 @@ class infinity(object):
# tests
def __cmp__(self, other):
"""
Positive infinity compares as greater than everything
except itself, negative infinity compares as less than
everything except itself.
"""
if self is other:
return 0
if self is PosInfinity:
return 1
# self is NegInfinity
return -1
def __lt__(self, other):
return self is NegInfinity and other is not NegInfinity
def __gt__(self, other):
return self is PosInfinity and other is not PosInfinity
def __le__(self, other):
return self is NegInfinity or other is PosInfinity
def __ge__(self, other):
return self is PosInfinity or other is NegInfinity
def __eq__(self, other):
return self is other
def __ne__(self, other):
return self is not other
def __nonzero__(self):
"""
......
......@@ -67,6 +67,17 @@ def set2():
class test_infinity(unittest.TestCase):
def test_math(self):
a = segments.infinity()
self.assertEqual(-a, -a)
self.assertLess(-a, 0)
self.assertLess(-a, a)
self.assertGreater(0, -a)
self.assertLess(0, a)
self.assertGreater(a, -a)
self.assertGreater(a, 0)
self.assertEqual(a, a)
@unittest.skipIf(sys.version_info.major >= 3,
'Python 3 does not have cmp')
def test__cmp__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment