Skip to content

Commit

Permalink
Add comparison methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jvadair committed May 8, 2023
1 parent 447ea9c commit 3ff978b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pyntree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,23 @@ def __imod__(self, other):
def __ipow__(self, other):
self.file.data[self.path[0]] **= other
return self()

# Comparison methods (<, >, <=, >=, ==, !=)
def __lt__(self, other):
return True if self() < other() else False

def __le__(self, other):
return True if self() <= other() else False

def __gt__(self, other):
return True if self() > other() else False

def __ge__(self, other):
return True if self() >= other() else False

def __eq__(self, other):
return True if self() == other() else False

def __ne__(self, other):
return True if self() != other() else False

11 changes: 11 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,17 @@ def test_imul_str(self):
db.a *= 3
self.assertEqual(db.a(), 'aaa')

def test_cmp(self):
db = Node()
db.a = 1
db.b = 2
self.assertTrue(db.a < db.b)
self.assertTrue(db.a <= db.b)
self.assertFalse(db.a > db.b)
self.assertFalse(db.a >= db.b)
self.assertFalse(db.a == db.b)
self.assertTrue(db.a != db.b)



if __name__ == '__main__':
Expand Down

0 comments on commit 3ff978b

Please sign in to comment.