Author: mattip <matti.pi...@gmail.com> Branch: Changeset: r58554:0856e88f3e3e Date: 2012-10-29 06:03 +0200 http://bitbucket.org/pypy/pypy/changeset/0856e88f3e3e/
Log: merge heads 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 pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit