Skip to content

Commit

Permalink
Merge pull request #207 from jonls/boolean-length
Browse files Browse the repository at this point in the history
boolean: Allow getting length of And/Or terms
  • Loading branch information
jonls authored Feb 27, 2017
2 parents e03ca30 + 848c6c6 commit 16e1888
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions psamm/expression/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def __iter__(self):
def __hash__(self):
return hash(self._terms)

def __len__(self):
return len(self._terms)

def __eq__(self, other):
return (isinstance(other, self.__class__) and
self._terms == other._terms)
Expand Down
10 changes: 10 additions & 0 deletions psamm/tests/test_expression_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def test_variable_hash(self):
self.assertEqual(hash(Variable('xyz')), hash(Variable('xyz')))


class TestTerm(unittest.TestCase):
def test_length_of_and(self):
term = And(Variable('b1'), Variable('b2'))
self.assertEqual(len(term), 2)

def test_length_of_or(self):
term = Or(Variable('b1'), And(Variable('b2'), Variable('b3')))
self.assertEqual(len(term), 2)


class TestExpression(unittest.TestCase):
def test_expression_substitute_existing(self):
e = Expression('b1')
Expand Down

0 comments on commit 16e1888

Please sign in to comment.