## "Fossies" - the Fresh Open Source Software Archive

### Source code changes of the file "mpmath/tests/test_basic_ops.py" betweenmpmath-0.19.tar.gz and mpmath-1.0.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

test_basic_ops.py  (mpmath-0.19):test_basic_ops.py  (mpmath-1.0.0)
skipping to change at line 128 skipping to change at line 128
assert mpf(0) + mpf(1.07e-22) == mpf(1.07e-22) assert mpf(0) + mpf(1.07e-22) == mpf(1.07e-22)
def test_complex_misc(): def test_complex_misc():
# many more tests needed # many more tests needed
assert 1 + mpc(2) == 3 assert 1 + mpc(2) == 3
assert not mpc(2).ae(2 + 1e-13) assert not mpc(2).ae(2 + 1e-13)
assert mpc(2+1e-15j).ae(2) assert mpc(2+1e-15j).ae(2)
def test_complex_zeros(): def test_complex_zeros():
for a in [0,2]: for a in [0,2]:
for b in [0,3]: for b in [0,3]:
for c in [0,4]: for c in [0,4]:
for d in [0,5]: for d in [0,5]:
assert mpc(a,b)*mpc(c,d) == complex(a,b)*complex(c,d) assert mpc(a,b)*mpc(c,d) == complex(a,b)*complex(c,d)
def test_hash(): def test_hash():
for i in range(-256, 256): for i in range(-256, 256):
assert hash(mpf(i)) == hash(i) assert hash(mpf(i)) == hash(i)
assert hash(mpf(0.5)) == hash(0.5) assert hash(mpf(0.5)) == hash(0.5)
assert hash(mpc(2,3)) == hash(2+3j) assert hash(mpc(2,3)) == hash(2+3j)
# Check that this doesn't fail # Check that this doesn't fail
assert hash(inf) assert hash(inf)
# Check that overflow doesn't assign equal hashes to large numbers # Check that overflow doesn't assign equal hashes to large numbers
assert hash(mpf('1e1000')) != hash('1e10000') assert hash(mpf('1e1000')) != hash('1e10000')
skipping to change at line 200 skipping to change at line 200
assert fop(x, y, dps=inf) == z0 assert fop(x, y, dps=inf) == z0
assert fop(x, y, exact=True) == z0 assert fop(x, y, exact=True) == z0
assert fneg(fneg(z1, exact=True), prec=inf) == z1 assert fneg(fneg(z1, exact=True), prec=inf) == z1
assert fneg(z1) == -(+z1) assert fneg(z1) == -(+z1)
mp.dps = 15 mp.dps = 15
def test_exact_integer_arithmetic(): def test_exact_integer_arithmetic():
# XXX: re-fix this so that all operations are tested with all rounding modes # XXX: re-fix this so that all operations are tested with all rounding modes
random.seed(0) random.seed(0)
for prec in [6, 10, 25, 40, 100, 250, 725]: for prec in [6, 10, 25, 40, 100, 250, 725]:
for rounding in ['d', 'u', 'f', 'c', 'n']: for rounding in ['d', 'u', 'f', 'c', 'n']:
mp.dps = prec mp.dps = prec
M = 10**(prec-2) M = 10**(prec-2)
M2 = 10**(prec//2-2) M2 = 10**(prec//2-2)
for i in range(10): for i in range(10):
a = random.randint(-M, M) a = random.randint(-M, M)
b = random.randint(-M, M) b = random.randint(-M, M)
assert mpf(a, rounding=rounding) == a assert mpf(a, rounding=rounding) == a
assert int(mpf(a, rounding=rounding)) == a assert int(mpf(a, rounding=rounding)) == a
assert int(mpf(str(a), rounding=rounding)) == a assert int(mpf(str(a), rounding=rounding)) == a
assert mpf(a) + mpf(b) == a + b assert mpf(a) + mpf(b) == a + b
assert mpf(a) - mpf(b) == a - b assert mpf(a) - mpf(b) == a - b
assert -mpf(a) == -a assert -mpf(a) == -a
a = random.randint(-M2, M2) a = random.randint(-M2, M2)
b = random.randint(-M2, M2) b = random.randint(-M2, M2)
assert mpf(a) * mpf(b) == a*b assert mpf(a) * mpf(b) == a*b
assert mpf_mul(from_int(a), from_int(b), mp.prec, rounding) == assert mpf_mul(from_int(a), from_int(b), mp.prec, rounding) == f
rom_int(a*b)
mp.dps = 15 mp.dps = 15
def test_odd_int_bug(): def test_odd_int_bug():
assert to_int(from_int(3), round_nearest) == 3 assert to_int(from_int(3), round_nearest) == 3
def test_str_1000_digits(): def test_str_1000_digits():
mp.dps = 1001 mp.dps = 1001
# last digit may be wrong # last digit may be wrong
assert str(mpf(2)**0.5)[-10:-1] == '9518488472'[:9] assert str(mpf(2)**0.5)[-10:-1] == '9518488472'[:9]
assert str(pi)[-10:-1] == '2164201989'[:9] assert str(pi)[-10:-1] == '2164201989'[:9]
End of changes. 2 change blocks.
22 lines changed or deleted 22 lines changed or added