Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: Changeset: r93747:f225421c6b26 Date: 2018-02-03 23:22 +0100 http://bitbucket.org/pypy/pypy/changeset/f225421c6b26/
Log: be a lot more systematic about testing the rbigint.int_* variants. This increases test coverage diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -17,15 +17,31 @@ from hypothesis import given, strategies +def gen_signs(l): + for s in l: + if s == 0: + yield s + else: + yield s + yield -s + long_vals_not_too_big = range(17) + [ - 37, 50, + 37, 39, 50, 127, 128, 129, 511, 512, 513, sys.maxint, sys.maxint + 1, + 12345678901234567890L, 123456789123456789000000L, - ] +] long_vals = long_vals_not_too_big + [ 1 << 100, 3 ** 10000] +int_vals = range(33) + [ + 1000, + 0x11111111, 0x11111112, 8888, + 9999, sys.maxint, 2 ** 19, 2 ** 18 - 1 +] +signed_int_vals = list(gen_signs(int_vals)) + [-sys.maxint-1] + class TestRLong(object): def test_simple(self): for op1 in [-2, -1, 0, 1, 2, 50]: @@ -121,12 +137,14 @@ rl_op2 = rbigint.fromlong(op2) r1 = rl_op1.mod(rl_op2) r2 = op1 % op2 - print op1, op2 + assert r1.tolong() == r2 def test_int_mod(self): for x in gen_signs(long_vals): - for y in gen_signs([1, 2, 4, 8, 8888, sys.maxint, 2 ** 19, 2 ** 18 - 1]): + for y in signed_int_vals: + if not y: + continue op1 = rbigint.fromlong(x) r1 = op1.int_mod(y) r2 = x % y @@ -158,13 +176,6 @@ assert not (a1 == a3) -def gen_signs(l): - for s in l: - if s == 0: - yield s - else: - yield s - yield -s def bigint(lst, sign): for digit in lst: @@ -266,7 +277,7 @@ def test_int_add(self): for x in gen_signs(long_vals): - for y in gen_signs([0, 1, 9999, sys.maxint, 2 ** 19, 2 ** 18 - 1]): + for y in signed_int_vals: f1 = rbigint.fromlong(x) result = f1.int_add(y) assert result.tolong() == x + y @@ -283,7 +294,7 @@ def test_int_sub(self): for x in gen_signs([0, 123456789123456789000000L, 1 << 100, 3 ** 10000]): - for y in gen_signs([0, 1, 8888, sys.maxint, 2 ** 19, 2 ** 18 - 1]): + for y in signed_int_vals: f1 = rbigint.fromlong(x) result = f1.int_sub(y) assert result.tolong() == x - y @@ -304,8 +315,8 @@ assert result.tolong() == x * x def test_int_mul(self): - for x in gen_signs([39, 128, 111111111, 123456789123456789000000L, 1 << 100, 3 ** 10000]): - for y in gen_signs([0, 1, 8888, sys.maxint, 2 ** 19, 2 ** 18 - 1]): + for x in gen_signs(long_vals): + for y in signed_int_vals: f1 = rbigint.fromlong(x) result = f1.int_mul(y) assert result.tolong() == x * y @@ -394,14 +405,14 @@ def test_int_comparison(self): for x in gen_signs(long_vals): - for y in gen_signs([0, 1, 0x11111111, 0x11111112, 8888, sys.maxint, 2 ** 19, 2 ** 18 - 1]): + for y in signed_int_vals: f1 = rbigint.fromlong(x) - assert (x < y) == f1.int_lt(y) - assert (x <= y) == f1.int_le(y) - assert (x > y) == f1.int_gt(y) - assert (x >= y) == f1.int_ge(y) - assert (x == y) == f1.int_eq(y) - assert (x != y) == f1.int_ne(y) + assert (x < y) == f1.int_lt(y) + assert (x <= y) == f1.int_le(y) + assert (x > y) == f1.int_gt(y) + assert (x >= y) == f1.int_ge(y) + assert (x == y) == f1.int_eq(y) + assert (x != y) == f1.int_ne(y) def test_order(self): f6 = rbigint.fromint(6) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit