This looks good to me. Fredrik, what do you think? Ondrej
On Wed, Oct 22, 2008 at 1:11 AM, <[EMAIL PROTECTED]> wrote: > > From: Fabian Seoane <[EMAIL PROTECTED]> > > --- > sympy/core/numbers.py | 12 +++++++++--- > sympy/core/tests/test_numbers.py | 13 +++++++++++++ > 2 files changed, 22 insertions(+), 3 deletions(-) > > diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py > index 000d326..da2b833 100644 > --- a/sympy/core/numbers.py > +++ b/sympy/core/numbers.py > @@ -487,7 +487,7 @@ class Rational(Number): > > is_Rational = True > > - @Memoizer(type, (int, long, str), MemoizerArg((int, long, type(None)), > name="q")) > + @Memoizer(type, (int, long, str, 'Integer'), MemoizerArg((int, long, > 'Integer', type(None)), name="q")) > def __new__(cls, p, q = None): > if q is None: > if isinstance(p, str): > @@ -512,8 +512,8 @@ class Rational(Number): > if q==1: return Integer(p) > if p==1 and q==2: return S.Half > obj = Basic.__new__(cls) > - obj.p = p > - obj.q = q > + obj.p = int(p) > + obj.q = int(q) > #obj._args = (p, q) > return obj > > @@ -789,6 +789,12 @@ class Integer(Rational): > else: > return Integer(-self.p) > > + def __mod__(self, other): > + return self.p % other > + > + def __rmod__(self, other): > + return other % self.p > + > # TODO make it decorator + bytecodehacks? > def __add__(a, b): > if type(b) is int: > diff --git a/sympy/core/tests/test_numbers.py > b/sympy/core/tests/test_numbers.py > index 3fd10fe..44f4bf5 100644 > --- a/sympy/core/tests/test_numbers.py > +++ b/sympy/core/tests/test_numbers.py > @@ -41,6 +41,19 @@ def test_igcdex(): > assert igcdex(10, 12) == (-1, 1, 2) > assert igcdex(100, 2004) == (-20, 1, 4) > > +def test_Rational_new(): > + """" > + Test for Rational constructor > + """ > + n1 = Rational(1,2) > + assert n1 == Rational(Integer(1), 2) > + assert n1 == Rational(Integer(1), Integer(2)) > + assert n1 == Rational(1, Integer(2)) > + > + raises(ValueError, 'Rational(1.2)') > + raises(ValueError, "Rational(Symbol('x'))") > + raises(ValueError, 'Rational(Rational(1,2))') > + > def test_Rational_cmp(): > n1 = Rational(1,4) > n2 = Rational(1,3) > -- > 1.6.0.1 > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---