[pypy-svn] r69513 - in pypy/trunk/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 22 20:38:10 CET 2009


Author: arigo
Date: Sun Nov 22 20:38:10 2009
New Revision: 69513

Modified:
   pypy/trunk/pypy/objspace/std/floatobject.py
   pypy/trunk/pypy/objspace/std/model.py
   pypy/trunk/pypy/objspace/std/test/test_floatobject.py
Log:
issue384 testing

Merge the branch/float-comparison: we found out that we can get the
"expected" order of comparison

   'float > int'  delegates to    'float > float'
                  rather than to  'float > long'

simply by tweaking the order of delegations in model.py.  No other test
seems to fail because of that, neither our own nor from the stdlib, so
let's merge.


Modified: pypy/trunk/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/floatobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/floatobject.py	Sun Nov 22 20:38:10 2009
@@ -100,36 +100,9 @@
     name = opname + "__Float_Float"
     return func_with_new_name(f, name), name
 
-def declare_new_int_float_comparison(opname):
-    import operator
-    from pypy.tool.sourcetools import func_with_new_name
-    op = getattr(operator, opname)
-    def f(space, w_int1, w_float2):
-        i = w_int1.intval
-        j = w_float2.floatval
-        return space.newbool(op(float(i), j))
-    name = opname + "__Int_Float"
-    return func_with_new_name(f, name), name
-
-def declare_new_float_int_comparison(opname):
-    import operator
-    from pypy.tool.sourcetools import func_with_new_name
-    op = getattr(operator, opname)
-    def f(space, w_float1, w_int2):
-        i = w_float1.floatval
-        j = w_int2.intval
-        return space.newbool(op(i, float(j)))
-    name = opname + "__Float_Int"
-    return func_with_new_name(f, name), name
-
 for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
     func, name = declare_new_float_comparison(op)
     globals()[name] = func
-    # XXX shortcuts disabled: see r54171 and issue #384.
-    #func, name = declare_new_int_float_comparison(op)
-    #globals()[name] = func
-    #func, name = declare_new_float_int_comparison(op)
-    #globals()[name] = func
 
 # for overflowing comparisons between longs and floats
 # XXX we might have to worry (later) about eq__Float_Int, for the case

Modified: pypy/trunk/pypy/objspace/std/model.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/model.py	(original)
+++ pypy/trunk/pypy/objspace/std/model.py	Sun Nov 22 20:38:10 2009
@@ -153,20 +153,20 @@
                 ]
             self.typeorder[smallintobject.W_SmallIntObject] += [
                 (intobject.W_IntObject, smallintobject.delegate_SmallInt2Int),
-                (longobject.W_LongObject, smallintobject.delegate_SmallInt2Long),
                 (floatobject.W_FloatObject, smallintobject.delegate_SmallInt2Float),
+                (longobject.W_LongObject, smallintobject.delegate_SmallInt2Long),
                 (complexobject.W_ComplexObject, smallintobject.delegate_SmallInt2Complex),
                 ]
 
         self.typeorder[boolobject.W_BoolObject] += [
             (intobject.W_IntObject,     boolobject.delegate_Bool2IntObject),
-            (longobject.W_LongObject,   longobject.delegate_Bool2Long),
             (floatobject.W_FloatObject, floatobject.delegate_Bool2Float),
+            (longobject.W_LongObject,   longobject.delegate_Bool2Long),
             (complexobject.W_ComplexObject, complexobject.delegate_Bool2Complex),
             ]
         self.typeorder[intobject.W_IntObject] += [
-            (longobject.W_LongObject,   longobject.delegate_Int2Long),
             (floatobject.W_FloatObject, floatobject.delegate_Int2Float),
+            (longobject.W_LongObject,   longobject.delegate_Int2Long),
             (complexobject.W_ComplexObject, complexobject.delegate_Int2Complex),
             ]
         self.typeorder[longobject.W_LongObject] += [

Modified: pypy/trunk/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_floatobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_floatobject.py	Sun Nov 22 20:38:10 2009
@@ -35,6 +35,30 @@
         v = fobj.pow__Float_Float_ANY(self.space, f1, f2, self.space.w_None)
         assert v.floatval == x**y
 
+    def test_dont_use_long_impl(self):
+        from pypy.objspace.std.longobject import W_LongObject
+        space = self.space
+        saved = W_LongObject.__dict__['fromfloat']
+        W_LongObject.fromfloat = lambda x: disabled
+        try:
+            w_i = space.wrap(12)
+            w_f = space.wrap(12.3)
+            assert space.unwrap(space.eq(w_f, w_i)) is False
+            assert space.unwrap(space.eq(w_i, w_f)) is False
+            assert space.unwrap(space.ne(w_f, w_i)) is True
+            assert space.unwrap(space.ne(w_i, w_f)) is True
+            assert space.unwrap(space.lt(w_f, w_i)) is False
+            assert space.unwrap(space.lt(w_i, w_f)) is True
+            assert space.unwrap(space.le(w_f, w_i)) is False
+            assert space.unwrap(space.le(w_i, w_f)) is True
+            assert space.unwrap(space.gt(w_f, w_i)) is True
+            assert space.unwrap(space.gt(w_i, w_f)) is False
+            assert space.unwrap(space.ge(w_f, w_i)) is True
+            assert space.unwrap(space.ge(w_i, w_f)) is False
+        finally:
+            W_LongObject.fromfloat = saved
+
+
 class AppTestAppFloatTest:
     def test_negatives(self):
         assert -1.1 < 0
@@ -187,9 +211,75 @@
         assert 13 <= 13.0
         assert 13 <= 13.01
 
+    def test_comparison_more(self):
+        infinity = 1e200*1e200
+        nan = infinity/infinity
+        for x in (123, 1 << 30,
+                  (1 << 33) - 1, 1 << 33, (1 << 33) + 1,
+                  1 << 62, 1 << 70):
+            #
+            assert     (x == float(x))
+            assert     (x >= float(x))
+            assert     (x <= float(x))
+            assert not (x != float(x))
+            assert not (x >  float(x))
+            assert not (x <  float(x))
+            #
+            assert not ((x - 1) == float(x))
+            assert not ((x - 1) >= float(x))
+            assert     ((x - 1) <= float(x))
+            assert     ((x - 1) != float(x))
+            assert not ((x - 1) >  float(x))
+            assert     ((x - 1) <  float(x))
+            #
+            assert not ((x + 1) == float(x))
+            assert     ((x + 1) >= float(x))
+            assert not ((x + 1) <= float(x))
+            assert     ((x + 1) != float(x))
+            assert     ((x + 1) >  float(x))
+            assert not ((x + 1) <  float(x))
+            #
+            #assert not (x == nan)
+            #assert not (x >= nan)
+            #assert not (x <= nan)
+            #assert     (x != nan)
+            #assert not (x >  nan)
+            #assert not (x <  nan)
+            #
+            assert     (float(x) == x)
+            assert     (float(x) <= x)
+            assert     (float(x) >= x)
+            assert not (float(x) != x)
+            assert not (float(x) <  x)
+            assert not (float(x) >  x)
+            #
+            assert not (float(x) == (x - 1))
+            assert not (float(x) <= (x - 1))
+            assert     (float(x) >= (x - 1))
+            assert     (float(x) != (x - 1))
+            assert not (float(x) <  (x - 1))
+            assert     (float(x) >  (x - 1))
+            #
+            assert not (float(x) == (x + 1))
+            assert     (float(x) <= (x + 1))
+            assert not (float(x) >= (x + 1))
+            assert     (float(x) != (x + 1))
+            assert     (float(x) <  (x + 1))
+            assert not (float(x) >  (x + 1))
+            #
+            #assert not (nan == x)
+            #assert not (nan <= x)
+            #assert not (nan >= x)
+            #assert     (nan != x)
+            #assert not (nan <  x)
+            #assert not (nan >  x)
+
     def test_multimethod_slice(self):
         assert 5 .__add__(3.14) is NotImplemented
         assert 3.25 .__add__(5) == 8.25
         if hasattr(int, '__eq__'):  # for py.test -A: CPython is inconsistent
             assert 5 .__eq__(3.14) is NotImplemented
             assert 3.14 .__eq__(5) is False
+        #if hasattr(long, '__eq__'):  # for py.test -A: CPython is inconsistent
+        #    assert 5L .__eq__(3.14) is NotImplemented
+        #    assert 3.14 .__eq__(5L) is False



More information about the Pypy-commit mailing list