Skip to content

Instantly share code, notes, and snippets.

@chaimleib
Created December 16, 2015 02:35
Show Gist options
  • Save chaimleib/62169e2f73902b68faf1 to your computer and use it in GitHub Desktop.
Save chaimleib/62169e2f73902b68faf1 to your computer and use it in GitHub Desktop.
def test_interval_interval_cmp_with_objects():
iv0 = Interval(0, 10)
ivd0 = Interval(0, 1, {'a': 1})
ivd1 = Interval(0, 1, {'a': 1})
assert ivd1.__cmp__(ivd0) == 0
assert ivd0.__cmp__(ivd1) == 0
assert ivd0.__cmp__(iv0) == -1
assert iv0.__cmp__(ivd0) == 1
class Loner(object):
def __eq__(self, other):
return False
ivl0 = Interval(2, 3, Loner())
ivl1 = Interval(2, 3, Loner())
# equal because type names equal. How else would you sort them?
assert ivl0.__cmp__(ivl0) == 0
assert ivl0.__cmp__(ivl1) == 0
class Socialite(object):
def __eq__(self, other):
return True
ivs0 = Interval(3, 4, Socialite())
ivs1 = Interval(3, 4, Socialite())
# equal because they __eq__() each other
assert ivs0.__cmp__(ivs0) == 0
assert ivs0.__cmp__(ivs1) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment