def test_log2(): if hasattr(math, 'log2'): assert isnear(math.log2(0.1), log2(0.1)) assert isnear(math.log2(1), log2(1)) assert isnear(math.log2(123.45), log2(123.45)) else: assert log2(1) == 0 assert log2(2) == 1 assert isnear(log2(8), 3)
def test_domains(): for sympyfunc in sorted(sympymappings, key=lambda x: str(x)): if sympyfunc in constants: continue mappings = sympymappings[sympyfunc] domain = get_domain(domains[sympyfunc]) if not callable(sympyfunc): sympyfunc = getattr(sympy, sympyfunc) for args in zip(*domain): sympyval = sympyfunc(*args) for othermodule, othername in mappings.items(): otherfunc = getattr(modules[othermodule], othername, None) if otherfunc is None and othername not in skip[othermodule]: print(othermodule, othername) getattr(modules[othermodule], othername) if otherfunc is None: continue otherval = otherfunc(*args) res1 = isnear(sympyval, otherval) res2 = isinf(sympyval) and isinf(otherval) res3 = isnan(sympyval) and isnan(otherval) res4 = otherval == sympyval if not (res1 or res2 or res3 or res4): print(othermodule, othername, args, sympyval, otherval) assert res1 or res2 or res3 or res4
def test_constants(): for name in constants: constant = getattr(sympy, name) for key, val in sympymappings[name].items(): other = getattr(modules[key], val) if name == 'nan': assert not isnear(constant, other) assert constant != other assert other != constant assert isnan(constant) assert isnan(other) elif name == 'oo': assert isinf(constant) assert isinf(other) assert not isfinite(constant) assert not isfinite(other) else: assert isnear(constant, other)
def test_trunc(): assert isnear(math.trunc(1.1), trunc(1.1)) assert isnear(math.trunc(1.9), trunc(1.9)) assert isnear(math.trunc(-1.1), trunc(-1.1)) assert isnear(math.trunc(-1.9), trunc(-1.9)) assert isnear(math.trunc(0), trunc(0)) assert isnear(math.trunc(3.0), trunc(3.0)) assert isnear(math.trunc(-5.0), trunc(-5.0))
def test_expm1(): if hasattr(math, 'expm1'): assert isnear(math.expm1(0), expm1(0)) assert isnear(math.expm1(0.001), expm1(0.001)) assert isnear(math.expm1(1.001), expm1(1.001)) else: assert isnear(0, expm1(0)) assert isnear(0.0010005, expm1(0.001)) assert isnear(1.72100147, expm1(1.001))
def test_divide(): assert isnear(numpy.divide(123.0, 456.0), divide(123.0, 456.0))
def test_rect(): assert isnear(cmath.rect(0, 1.2), rect(0, 1.2)) assert isnear(cmath.rect(1.2, 0), rect(1.2, 0)) assert isnear(cmath.rect(0, 0), rect(0, 0)) assert isnear(cmath.rect(3.4, 5.6), rect(3.4, 5.6))
def test_frexp(): assert isnear(math.frexp(0), frexp(0)) assert isnear(math.frexp(1), frexp(1)) assert isnear(math.frexp(-1), frexp(-1)) assert isnear(math.frexp(123.45), frexp(123.45)) assert isnear(math.frexp(-456.78), frexp(-456.78))
def test_true_divide(): assert isnear(numpy.true_divide(123.0, 456.0), true_divide(123.0, 456.0))
def test_phase(): assert isnear(cmath.phase(complex(0, 1.2)), phase(complex(0, 1.2))) assert isnear(cmath.phase(complex(1.2, 0)), phase(complex(1.2, 0))) assert isnear(cmath.phase(complex(-3.4, 5.6)), phase(complex(-3.4, 5.6)))
def test_reciprocal(): assert isnear(numpy.reciprocal(12.3), reciprocal(12.3)) assert isnear(numpy.reciprocal(-23.4), reciprocal(-23.4))
def test_square(): assert isnear(numpy.square(12.3), square(12.3)) assert isnear(numpy.square(-23.4), square(-23.4))
def test_exp2(): assert isnear(numpy.exp2(12.3), exp2(12.3))
def test_logaddexp2(): assert isnear(numpy.logaddexp2(7, 8), logaddexp2(7, 8))
def test_modf(): assert isnear(math.modf(0), modf(0)) assert isnear(math.modf(3), modf(3)) assert isnear(math.modf(1.2), modf(1.2)) assert isnear(math.modf(-3.7), modf(-3.7))
def test_fsum(): assert isnear(math.fsum(range(10)), fsum(range(10))) assert isnear(math.fsum(0.3 * x for x in range(10)), fsum(0.3 * x for x in range(10))) assert isnear(math.fsum([1]), fsum([1]))
def test_log1p(): assert isnear(math.log1p(0.1), log1p(0.1)) assert isnear(math.log1p(1), log1p(1)) assert isnear(math.log1p(123.45), log1p(123.45))
def test_ldexp(): assert isnear(math.ldexp(1.2, 3), ldexp(1.2, 3)) assert isnear(math.ldexp(4.5, -6), ldexp(4.5, -6)) assert isnear(math.ldexp(-1.2, 3), ldexp(-1.2, 3))
def test_hypot(): assert isnear(math.hypot(3, 4), hypot(3, 4))
def test_floor_divide(): assert isnear(numpy.floor_divide(456.0, 23.0), floor_divide(456.0, 23.0))
def test_acos(): assert isnear(math.acos(0), acos(0)) assert isnear(math.acos(0.5), acos(0.5)) assert isnear(math.acos(-0.123), acos(-0.123))
def test_negative(): assert isnear(numpy.negative(12.3), negative(12.3)) assert isnear(numpy.negative(-23.4), negative(-23.4))
def test_acosh(): assert isnear(math.acosh(1.0), acosh(1.0)) assert isnear(math.acosh(10.0), acosh(10.0))
def test_signbit(): assert isnear(numpy.signbit(12.3), signbit(12.3)) assert isnear(numpy.signbit(-23.4), signbit(-23.4))
def test_asin(): assert isnear(math.asin(0), asin(0)) assert isnear(math.asin(0.5), asin(0.5)) assert isnear(math.asin(-0.123), asin(-0.123))
def test_subtract(): assert isnear(numpy.subtract(1.2, 3.4), subtract(1.2, 3.4))
def test_asinh(): assert isnear(math.asinh(1.0), asinh(1.0)) assert isnear(math.asinh(10.0), asinh(10.0))
def test_log10(): assert isnear(cmath.log10(0.1), log10(0.1)) assert isnear(cmath.log10(1), log10(1)) assert isnear(cmath.log10(123.45), log10(123.45))
def test_atan(): assert isnear(math.atan(0), atan(0)) assert isnear(math.atan(-1.0), atan(-1.0)) assert isnear(math.atan(1000.0), atan(1000.0))
def test_polar(): assert isnear(cmath.polar(complex(0, 1.2)), polar(complex(0, 1.2))) assert isnear(cmath.polar(complex(1.2, 0)), polar(complex(1.2, 0))) assert isnear(cmath.polar(complex(-3.4, 5.6)), polar(complex(-3.4, 5.6)))
def test_atan2(): assert isnear(math.atan2(1, 2), atan2(1, 2)) assert isnear(math.atan2(-3, 4), atan2(-3, 4)) assert isnear(math.atan2(5, -6), atan2(5, -6)) assert isnear(math.atan2(-7, -8), atan2(-7, -8))
def test_ceil(): assert isnear(math.ceil(0.0), ceil(0.0)) assert isnear(math.ceil(1.1), ceil(1.1)) assert isnear(math.ceil(1.9), ceil(1.9)) assert isnear(math.ceil(-1.1), ceil(-1.1)) assert isnear(math.ceil(-1.9), ceil(-1.9))
def test_isnear(): assert isnear(1, 1.000001) assert not isnear(1, 1.001) assert isnear([1, 2], [1.000001, 2.000001]) assert not isnear([1, 2], [1.001, 2.000001])
def test_isnear(): assert isnear(1, 1.000001) assert not isnear(1, 1.001) assert isnear([1, 2], [1.000001, 2.000001]) assert not isnear([1, 2], [1.001, 2.000001])
def test_copysign(): assert isnear(math.copysign(-7.2, -87), copysign(-7.2, -87)) assert isnear(math.copysign(1.1, -3), copysign(1.1, -3)) assert isnear(math.copysign(-2.2, 4), math.copysign(-2.2, 4)) assert isnear(math.copysign(3.3, 5), copysign(3.3, 5))