def test_validate_good(self): f = self.f g = self.g NumericalExpression("x_0", (f, ), dtype=float64_dtype) NumericalExpression("x_0 ", (f, ), dtype=float64_dtype) NumericalExpression("x_0 + x_0", (f, ), dtype=float64_dtype) NumericalExpression("x_0 + 2", (f, ), dtype=float64_dtype) NumericalExpression("2 * x_0", (f, ), dtype=float64_dtype) NumericalExpression("x_0 + x_1", (f, g), dtype=float64_dtype) NumericalExpression("x_0 + x_1 + x_0", (f, g), dtype=float64_dtype) NumericalExpression("x_0 + 1 + x_1", (f, g), dtype=float64_dtype)
def test_validate_good(self): f = self.f g = self.g NumericalExpression("x_0", (f, )) NumericalExpression("x_0 ", (f, )) NumericalExpression("x_0 + x_0", (f, )) NumericalExpression("x_0 + 2", (f, )) NumericalExpression("2 * x_0", (f, )) NumericalExpression("x_0 + x_1", (f, g)) NumericalExpression("x_0 + x_1 + x_0", (f, g)) NumericalExpression("x_0 + 1 + x_1", (f, g))
def test_validate_bad(self): f, g, h = self.f, self.g, self.h # Too few inputs. with self.assertRaises(ValueError): NumericalExpression("x_0", (), dtype=float64_dtype) with self.assertRaises(ValueError): NumericalExpression("x_0 + x_1", (f, ), dtype=float64_dtype) # Too many inputs. with self.assertRaises(ValueError): NumericalExpression("x_0", (f, g), dtype=float64_dtype) with self.assertRaises(ValueError): NumericalExpression("x_0 + x_1", (f, g, h), dtype=float64_dtype) # Invalid variable name. with self.assertRaises(ValueError): NumericalExpression("x_0x_1", (f, ), dtype=float64_dtype) with self.assertRaises(ValueError): NumericalExpression("x_0x_1", (f, g), dtype=float64_dtype) # Variable index must start at 0. with self.assertRaises(ValueError): NumericalExpression("x_1", (f, ), dtype=float64_dtype) # Scalar operands must be numeric. with self.assertRaises(TypeError): "2" + f with self.assertRaises(TypeError): f + "2" with self.assertRaises(TypeError): f > "2" # Boolean binary operators must be between filters. with self.assertRaises(TypeError): f + (f > 2) with self.assertRaises(TypeError): (f > f) > f