Add isinstance check before gcd call in SumNode.__lt__ (#2450)

* Add isinstance check before gcd call

* Delete blank lines

* Fix unit test typo

* Delete blank lines again

---------

Co-authored-by: Paul Gustafson <paul.gustafson@theambrusgroup.com>
This commit is contained in:
Paul Gustafson
2023-11-26 13:05:04 -08:00
committed by GitHub
parent 58b1dd463e
commit 1d89c018fa
2 changed files with 9 additions and 2 deletions

View File

@@ -394,6 +394,14 @@ class TestSymbolicSymbolicOps(unittest.TestCase):
assert a < 3 and (a < 3).min == 0 and (a < 3).max == 1
assert a > 3 and (a > 3).min == 0 and (a > 3).max == 1
def test_sumnode_mulnode_lt(self):
a = Variable("a", 1, 2)
b = Variable("b", 1, 2)
c = Variable("c", 1, 2)
x = SumNode([MulNode(a, b), c])
assert isinstance((x < 3), Node) and (x < 3) == 0
assert isinstance((x < 4), LtNode) and (x < 4).min == 0 and (x < 4).max == 1
def test_num_node_mul_node(self):
a = Variable("a", 1, 5)
b = NumNode(2) * a
@@ -448,6 +456,5 @@ class TestSymbolicSymbolicOps(unittest.TestCase):
c = b.substitute({a: NumNode(1)})
assert c == NumNode(2)
if __name__ == '__main__':
unittest.main()