[pypy-svn] r66637 - in pypy/branch/io-lang/pypy/lang/io: . test

david at codespeak.net david at codespeak.net
Sun Jul 26 17:55:02 CEST 2009


Author: david
Date: Sun Jul 26 17:54:59 2009
New Revision: 66637

Modified:
   pypy/branch/io-lang/pypy/lang/io/number.py
   pypy/branch/io-lang/pypy/lang/io/test/test_number.py
Log:
Number compare and == methods

Modified: pypy/branch/io-lang/pypy/lang/io/number.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/number.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/number.py	Sun Jul 26 17:54:59 2009
@@ -57,4 +57,16 @@
     
 @register_method('Number', '*', unwrap_spec=[float, float])
 def w_number_multiply(space, a, b):
-    return W_Number(space, a*b)
\ No newline at end of file
+    return W_Number(space, a*b)
+    
+ at register_method('Number', '==', unwrap_spec=[float, float])
+def w_number_equals(space, a, b):
+    w_value = space.w_false
+    if w_number_compare(space, a, b) == 0:
+        w_value = space.w_true
+    return w_value
+    
+ at register_method('Number', 'compare', unwrap_spec=[float, float])
+def w_number_compare(space, a, b):
+     return W_Number(space, cmp(a,b), [space.w_number])
+    
\ No newline at end of file

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_number.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_number.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_number.py	Sun Jul 26 17:54:59 2009
@@ -146,4 +146,25 @@
     inp = '6*7'
     res, _  = interpret(inp)
     assert res.value == 42
-    
\ No newline at end of file
+    
+def test_equals():
+    inp = '3 == 5'
+    res, space = interpret(inp)
+    assert res == space.w_false
+    
+    inp = '5 == 5'
+    res, space = interpret(inp)
+    assert res == space.w_true
+    
+def test_compare():
+    inp = '7 compare(7)'
+    res, space = interpret(inp)
+    assert res.value == 0
+    
+    inp = '7 compare(8)'
+    res, space = interpret(inp)
+    assert res.value == -1
+    
+    inp = '7 compare(6)'
+    res, space = interpret(inp)
+    assert res.value == 1
\ No newline at end of file



More information about the Pypy-commit mailing list