diff --git a/common/lib/calc/calc.py b/common/lib/calc/calc.py index 2271676f34..2f33b66bfd 100644 --- a/common/lib/calc/calc.py +++ b/common/lib/calc/calc.py @@ -144,6 +144,8 @@ def evaluator(variables, functions, string, cs=False): return x def parallel(x): # Parallel resistors [ 1 2 ] => 2/3 + # convert from pyparsing.ParseResults, which doesn't support '0 in x' + x = list(x) if len(x) == 1: return x[0] if 0 in x: diff --git a/common/lib/calc/tests/test_calc.py b/common/lib/calc/tests/test_calc.py index cd28801d83..58d0860af6 100644 --- a/common/lib/calc/tests/test_calc.py +++ b/common/lib/calc/tests/test_calc.py @@ -92,6 +92,10 @@ class EvaluatorTest(unittest.TestCase): """ self.assertRaises(ZeroDivisionError, calc.evaluator, {}, {}, '1/0') + self.assertRaises(ZeroDivisionError, calc.evaluator, + {}, {}, '1/0.0') + self.assertRaises(ZeroDivisionError, calc.evaluator, + {'x': 0.0}, {}, '1/x') def test_parallel_resistors(self): """ @@ -107,12 +111,13 @@ class EvaluatorTest(unittest.TestCase): self.assertEqual(calc.evaluator({}, {}, '1||1||2'), 0.4) self.assertEqual(calc.evaluator({}, {}, "j||1"), 0.5 + 0.5j) - def test_parallel_resistors_zero_error(self): + def test_parallel_resistors_with_zero(self): """ Check the behavior of the || operator with 0 """ - self.assertRaises(ZeroDivisionError, calc.evaluator, - {}, {}, '0||1') + self.assertTrue(numpy.isnan(calc.evaluator({}, {}, '0||1'))) + self.assertTrue(numpy.isnan(calc.evaluator({}, {}, '0.0||1'))) + self.assertTrue(numpy.isnan(calc.evaluator({'x': 0.0}, {}, 'x||1'))) def assert_function_values(self, fname, ins, outs, tolerance=1e-3): """ diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index 77cd547e55..780c475b09 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -10,7 +10,6 @@ import random import unittest import textwrap import mock -import textwrap from . import new_loncapa_problem, test_system