Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r58548:12f7aa38e6e2
Date: 2012-10-28 15:15 -0700
http://bitbucket.org/pypy/pypy/changeset/12f7aa38e6e2/
Log: make it possible to compare rbigints with == and != for testing
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -119,6 +119,17 @@
self.size = size or len(digits)
self.sign = sign
+ # __eq__ and __ne__ method exist for testingl only, they are not RPython!
+ def __eq__(self, other):
+ # NOT_RPYTHON
+ if not isinstance(other, rbigint):
+ return NotImplemented
+ return self.eq(other)
+
+ def __ne__(self, other):
+ # NOT_RPYTHON
+ return not (self == other)
+
def digit(self, x):
"""Return the x'th digit, as an int."""
return self._digits[x]
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -1,14 +1,19 @@
from __future__ import division
+
+import operator
+import sys
+from random import random, randint, sample
+
import py
-import operator, sys, array
-from random import random, randint, sample
-from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF
-from pypy.rlib.rbigint import _store_digit, _mask_digit
-from pypy.rlib.rfloat import NAN
+
from pypy.rlib import rbigint as lobj
from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
+from pypy.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
+ _store_digit, _mask_digit)
+from pypy.rlib.rfloat import NAN
from pypy.rpython.test.test_llinterp import interpret
+
class TestRLong(object):
def test_simple(self):
for op1 in [-2, -1, 0, 1, 2, 50]:
@@ -112,6 +117,17 @@
rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
assert rl.touint() == result
+ def test_eq_ne_operators(self):
+ a1 = rbigint.fromint(12)
+ a2 = rbigint.fromint(12)
+ a3 = rbigint.fromint(123)
+
+ assert a1 == a2
+ assert a1 != a3
+ assert not (a1 != a2)
+ assert not (a1 == a3)
+
+
def gen_signs(l):
for s in l:
if s == 0:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit