Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: Changeset: r95476:a838af77f2af Date: 2018-12-13 13:25 +0100 http://bitbucket.org/pypy/pypy/changeset/a838af77f2af/
Log: cherry-pick some of the test from math-improvements to default diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py --- a/pypy/objspace/std/test/test_intobject.py +++ b/pypy/objspace/std/test/test_intobject.py @@ -671,6 +671,13 @@ assert type(x) is int assert str(x) == "0" + def test_binop_overflow(self): + x = int(2) + assert x.__lshift__(128) == 680564733841876926926749214863536422912L + + def test_rbinop_overflow(self): + x = int(321) + assert x.__rlshift__(333) == 1422567365923326114875084456308921708325401211889530744784729710809598337369906606315292749899759616L class AppTestIntShortcut(AppTestInt): spaceconfig = {"objspace.std.intshortcut": True} diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py +++ b/pypy/objspace/std/test/test_longobject.py @@ -2,7 +2,6 @@ from pypy.objspace.std import longobject as lobj from rpython.rlib.rbigint import rbigint - class TestW_LongObject: def test_bigint_w(self): space = self.space @@ -52,8 +51,9 @@ assert x + 2 + 3L + True == -14L def test_sub(self): - x = 58543L - assert int(x - 12332L) == 58543 - 12332 + assert int(58543L - 12332L) == 58543 - 12332 + assert int(58543L - 12332) == 58543 - 12332 + assert int(58543 - 12332L) == 58543 - 12332 x = 237123838281233L assert x * 12 == x * 12L @@ -70,6 +70,23 @@ a = x // 10000000L assert a == 3L + def test_int_floordiv(self): + import sys + + x = 3000L + a = x // 1000 + assert a == 3L + + x = 3000L + a = x // -1000 + assert a == -3L + + x = 3000L + raises(ZeroDivisionError, "x // 0") + + n = sys.maxint+1 + assert n / int(-n) == -1L + def test_numerator_denominator(self): assert (1L).numerator == 1L assert (1L).denominator == 1L @@ -79,25 +96,27 @@ def test_compare(self): Z = 0 ZL = 0L + + assert Z == ZL + assert not (Z != ZL) + assert ZL == Z + assert not (ZL != Z) + assert Z <= ZL + assert not (Z < ZL) + assert ZL <= ZL + assert not (ZL < ZL) + for BIG in (1L, 1L << 62, 1L << 9999): - assert Z == ZL - assert not (Z != ZL) - assert ZL == Z - assert not (ZL != Z) assert not (Z == BIG) assert Z != BIG assert not (BIG == Z) assert BIG != Z assert not (ZL == BIG) assert ZL != BIG - assert Z <= ZL - assert not (Z < ZL) assert Z <= BIG assert Z < BIG assert not (BIG <= Z) assert not (BIG < Z) - assert ZL <= ZL - assert not (ZL < ZL) assert ZL <= BIG assert ZL < BIG assert not (BIG <= ZL) @@ -171,10 +190,38 @@ assert type(-long2(0)) is long assert type(long2(5) // 1) is long + def test_shift(self): + assert 65l >> 2l == 16l + assert 65l >> 2 == 16l + assert 65 >> 2l == 16l + assert 65l << 2l == 65l * 4 + assert 65l << 2 == 65l * 4 + assert 65 << 2l == 65l * 4 + raises(ValueError, "1L << -1L") + raises(ValueError, "1L << -1") + raises(OverflowError, "1L << (2 ** 100)") + raises(ValueError, "1L >> -1L") + raises(ValueError, "1L >> -1") + raises(OverflowError, "1L >> (2 ** 100)") + def test_pow(self): x = 0L assert pow(x, 0L, 1L) == 0L assert pow(-1L, -1L) == -1.0 + assert pow(2 ** 68, 0.5) == 2.0 ** 34 + assert pow(2 ** 68, 2) == 2 ** 136 + raises(TypeError, pow, 2l, -1, 3) + raises(ValueError, pow, 2l, 5, 0) + + # some rpow tests + assert pow(0, 0L, 1L) == 0L + assert pow(-1, -1L) == -1.0 + + def test_int_pow(self): + x = 2L + assert pow(x, 2) == 4L + assert pow(x, 2, 2) == 0L + assert pow(x, 2, 3L) == 1L def test_getnewargs(self): assert 0L .__getnewargs__() == (0L,) @@ -185,8 +232,8 @@ q, r = divmod(x, y) pab, pba = x*y, y*x assert pab == pba - assert q == x//y - assert r == x%y + assert q == x // y + assert r == x % y assert x == q*y + r if y > 0: assert 0 <= r < y @@ -196,6 +243,8 @@ for y in [-105566530L, -1L, 1L, 1034522340L]: print "checking division for %s, %s" % (x, y) check_division(x, y) + check_division(x, int(y)) + check_division(int(x), y) # special case from python tests: s1 = 33 s2 = 2 @@ -207,6 +256,16 @@ y = 0x9800FFC1L check_division(x, y) raises(ZeroDivisionError, "x // 0L") + raises(ZeroDivisionError, "x % 0L") + raises(ZeroDivisionError, divmod, x, 0L) + raises(ZeroDivisionError, "x // 0") + raises(ZeroDivisionError, "x % 0") + raises(ZeroDivisionError, divmod, x, 0) + + def test_int_divmod(self): + q, r = divmod(100L, 11) + assert q == 9L + assert r == 1L def test_format(self): assert repr(12345678901234567890) == '12345678901234567890L' @@ -321,6 +380,10 @@ return 42 assert long(A('abc')) == 42 + def test_long_errors(self): + raises(TypeError, long, 12, 12) + raises(ValueError, long, 'xxxxxx?', 12) + def test_conjugate(self): assert (7L).conjugate() == 7L assert (-7L).conjugate() == -7L @@ -386,3 +449,4 @@ n = "a" * size expected = (2 << (size * 4)) // 3 assert long(n, 16) == expected + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit