[pypy-commit] pypy math-improvements: improve random testing of divmod, this finds a bug!
cfbolz
pypy.commits at gmail.com
Thu Dec 13 07:18:50 EST 2018
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: math-improvements
Changeset: r95473:6b10ba9fde9c
Date: 2018-12-13 13:13 +0100
http://bitbucket.org/pypy/pypy/changeset/6b10ba9fde9c/
Log: improve random testing of divmod, this finds a bug! bad Stian, no
cookie
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
@@ -16,12 +16,22 @@
from rpython.rtyper.test.test_llinterp import interpret
from rpython.translator.c.test.test_standalone import StandaloneTests
-from hypothesis import given, strategies
+from hypothesis import given, strategies, example
longs = strategies.builds(
long, strategies.integers())
ints = strategies.integers(-sys.maxint-1, sys.maxint)
+def makelong(data):
+ numbits = data.draw(strategies.integers(1, 2000))
+ r = data.draw(strategies.integers(0, 1 << numbits))
+ if data.draw(strategies.booleans()):
+ return -r
+ return r
+
+biglongs = strategies.builds(makelong, strategies.data())
+
+
def gen_signs(l):
for s in l:
if s == 0:
@@ -1125,7 +1135,6 @@
data = cbuilder.cmdexec('hi there')
assert data == '[%d]\n[0, 1]\n' % sys.maxint
-
class TestHypothesis(object):
@given(longs, longs, longs)
def test_pow(self, x, y, z):
@@ -1140,23 +1149,35 @@
v = f1.pow(f2, f3)
assert v.tolong() == res
- @given(longs, longs, longs)
- def test_divmod(self, x, y, z):
+ @given(biglongs, biglongs)
+ @example(510439143470502793407446782273075179618477362188870662225920,
+ 108089693021945158982483698831267549521)
+ def test_divmod(self, x, y):
+ if x < y:
+ x, y = y, x
+
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
- f3 = rbigint.fromlong(z)
try:
- res = divmod(x, y, z)
+ res = divmod(x, y)
except Exception as e:
- pytest.raises(type(e), f1.divmod, f2, f3)
- if isinstance(int(y), int):
- pytest.raises(type(e), f1.int_divmod, f2, f3)
+ pytest.raises(type(e), f1.divmod, f2)
else:
- a, b = f1.divmod(f2, f3)
- assert a.tolong(), b.tolong() == res
- if isinstance(int(y), int):
- a, b = f1.int_divmod(f2, f3)
- assert a.tolong(), b.tolong() == res
+ print x, y
+ a, b = f1.divmod(f2)
+ assert (a.tolong(), b.tolong()) == res
+
+ @given(biglongs, ints)
+ def test_int_divmod(self, x, iy):
+ f1 = rbigint.fromlong(x)
+ try:
+ res = divmod(x, iy)
+ except Exception as e:
+ pytest.raises(type(e), f1.int_divmod, iy)
+ else:
+ print x, iy
+ a, b = f1.int_divmod(iy)
+ assert (a.tolong(), b.tolong()) == res
@given(longs)
def test_hash(self, x):
More information about the pypy-commit
mailing list