def test_wrong_equ_no_left_bracket(self): try: split("+ 1 2)") except ValueError: pass else: self.assertTrue(False)
def test_nested(self): equ = "(+ 1 (+ 1 2))" ps = split(equ) self.assertEqual(len(ps), 3) self.assertEqual(ps[0], "+") self.assertEqual(ps[1], "1") self.assertEqual(ps[2], "(+ 1 2)")
def test_flat(self): equ = "(+ 1 2)" ps = split(equ) self.assertEqual(len(ps), 3) self.assertEqual(ps[0], "+") self.assertEqual(ps[1], "1") self.assertEqual(ps[2], "2")
def __call__(self, equ): equ_norm = brush_equ(equ) parts = split(equ_norm) func = parts[0] args = [] for x in parts[1:]: if x[0] == "(": y = self(x) else: y = convert(x) args.append(y) return self._funcs[func](*args)
def test_wrong_equ_no_brackets(self): with self.assertRaises(ValueError): split("+ 1 2")
def test_trailing_more_spaces(self): equ = "( + 1 2 )" ps = split(equ) self.assertEqual(ps, ["+", "1", "2"])