def test_args_mismatch(self): def x(y): pass error = "Argument type annotations don't match function arguments" with self.assertRaisesRegexp(AnnotationError, error): function(Double, z=Double)(x)
def test_cmp(self): annotate = function(Bool, a=self.Type, b=self.Type) funcs = cmp_funcs() m = module(map(annotate, funcs)) for f in funcs: cf = getattr(m, f.__name__) self.assertEqual(cf(6.0, 5.0), f(6.0, 5.0)) self.assertEqual(cf(5.0, 5.0), f(5.0, 5.0)) self.assertEqual(cf(5.0, 6.0), f(5.0, 6.0))
def test_cmp(self): annotate = function(Bool, a=Long, b=Long) funcs = cmp_funcs() m = module(map(annotate, funcs)) for f in funcs: cf = getattr(m, f.__name__) self.assertEqual(cf(6, 5), f(6, 5)) self.assertEqual(cf(5, 5), f(5, 5)) self.assertEqual(cf(5, 6), f(5, 6))
def test_unary(self): annotate = function(self.Type, a=self.Type) funcs = unary_funcs() m = module(map(annotate, funcs)) values = [-5.0, 0.0, 5.0] for f in funcs: cf = getattr(m, f.__name__) for a in values: self.assertEqual(cf(a), f(a), "{0}({1})".format(f.__name__, a))
def test_unary(self): annotate = function(Long, a=Long) funcs = unary_funcs() + integer_unary_funcs() m = module(map(annotate, funcs)) values = [-5, 0, 5] for f in funcs: cf = getattr(m, f.__name__) for a in values: self.assertEqual(cf(a), f(a), "{0}({1})".format(f.__name__, a))
def test_binary(self): annotate = function(self.Type, a=self.Type, b=self.Type) funcs = binary_funcs() + floating_binary_funcs() m = module(map(annotate, funcs)) values = [(0.0, 1.0), (3.0, 2.0), (2.0, 3.0), (-3.0, 2.0), (3.0, -2.0)] for f in funcs: cf = getattr(m, f.__name__) for a, b in values: self.assertAlmostEqual(cf(a, b), f(a, b), self.digits, "{0}({1}, {2})".format(f.__name__, a, b))
def test_binary(self): annotate = function(Long, a=Long, b=Long) funcs = binary_funcs() + integer_binary_funcs() m = module(map(annotate, funcs)) values = [(0, 1), (3, 2), (2, 3), (-3, 2), (3, -2)] for f in funcs: cf = getattr(m, f.__name__) for a, b in values: self.assertEqual(cf(a, b), f(a, b), "{0}({1}, {2})".format(f.__name__, a, b))