[pypy-svn] r51833 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Sun Feb 24 13:31:37 CET 2008


Author: tverwaes
Date: Sun Feb 24 13:31:37 2008
New Revision: 51833

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
Log:
fixing equal according to blue book + adding test


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	Sun Feb 24 13:31:37 2008
@@ -42,11 +42,11 @@
     def shadow_of_my_class(self):
         return self.getclass().as_class_get_shadow()
 
-    def shallow_equals(self,other):
+    def pointer_equals(self,other):
         return self == other
 
     def equals(self, other):
-        return self.shallow_equals(other)
+        return self.pointer_equals(other)
 
 class W_SmallInteger(W_Object):
     __slots__ = ('value',)     # the only allowed slot here
@@ -67,7 +67,7 @@
     def __repr__(self):
         return "W_SmallInteger(%d)" % self.value
 
-    def shallow_equals(self, other):
+    def equals(self, other):
         if not isinstance(other, W_SmallInteger):
             return False
         return self.value == other.value
@@ -89,7 +89,7 @@
     def __repr__(self):
         return "W_Float(%f)" % self.value
 
-    def shallow_equals(self, other):
+    def equals(self, other):
         if not isinstance(other, W_Float):
             return False
         return self.value == other.value
@@ -236,18 +236,6 @@
         from pypy.lang.smalltalk.shadow import ContextPartShadow
         return self.as_special_get_shadow(ContextPartShadow)
 
-    def equals(self, other):
-        if not isinstance(other, W_PointersObject):
-            return False
-        if not other.getclass() == self.getclass():
-            return False
-        if not other.size() == self.size():
-            return False
-        for i in range(self.size()):
-            if not other.fetch(i).shallow_equals(self.fetch(i)):
-                return False
-        return True
-
 class W_BytesObject(W_AbstractObjectWithClassReference):
     def __init__(self, w_class, size):
         W_AbstractObjectWithClassReference.__init__(self, w_class)
@@ -288,11 +276,6 @@
                 return False
         return True
 
-    def shallow_equals(self, other):
-        if not isinstance(other,W_BytesObject):
-            return False
-        return self.bytes == other.bytes
-
 class W_WordsObject(W_AbstractObjectWithClassReference):
     def __init__(self, w_class, size):
         W_AbstractObjectWithClassReference.__init__(self, w_class)
@@ -319,11 +302,6 @@
         return (W_AbstractObjectWithClassReference.invariant(self) and
                 isinstance(self.words, list))
 
-    def shallow_equals(self, other):
-        if not isinstance(other,W_WordsObject):
-            return False
-        return self.words == other.words
-
 class W_CompiledMethod(W_AbstractObjectWithIdentityHash):
     """My instances are methods suitable for interpretation by the virtual machine.  This is the only class in the system whose instances intermix both indexable pointer fields and indexable integer fields.
 

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	Sun Feb 24 13:31:37 2008
@@ -131,3 +131,30 @@
     assert utility.unwrap_int(w_method.at0(12)) == ord('a')
     assert utility.unwrap_int(w_method.at0(13)) == ord('b')
     assert utility.unwrap_int(w_method.at0(14)) == ord('c')
+
+def test_equals(w_o1=model.W_PointersObject(None,0), w_o2=None):
+    if w_o2 is None:
+        w_o2 = w_o1
+    assert w_o1.equals(w_o2)
+    assert w_o2.equals(w_o1)
+    
+def test_not_equals(w_o1=model.W_PointersObject(None,0),w_o2=model.W_PointersObject(None,0)):
+    assert not w_o1.equals(w_o2)
+    assert not w_o2.equals(w_o1)
+    w_o2 = model.W_SmallInteger(2)
+    assert not w_o1.equals(w_o2)
+    assert not w_o2.equals(w_o1)
+    w_o2 = model.W_Float(5.5)
+    assert not w_o1.equals(w_o2)
+    assert not w_o2.equals(w_o1)
+
+def test_intfloat_equals():
+    test_equals(model.W_SmallInteger(1), model.W_SmallInteger(1))
+    test_equals(model.W_SmallInteger(100), model.W_SmallInteger(100))
+    test_equals(model.W_Float(1.100), model.W_Float(1.100))
+
+def test_intfloat_notequals():
+    test_not_equals(model.W_SmallInteger(1), model.W_Float(1))
+    test_not_equals(model.W_Float(100), model.W_SmallInteger(100))
+    test_not_equals(model.W_Float(1.100), model.W_Float(1.200))
+    test_not_equals(model.W_SmallInteger(101), model.W_SmallInteger(100))



More information about the Pypy-commit mailing list