[pypy-svn] r66145 - in pypy/branch/pyjitpl5/pypy/jit/tl: . test

antocuni at codespeak.net antocuni at codespeak.net
Tue Jul 7 11:47:39 CEST 2009


Author: antocuni
Date: Tue Jul  7 11:47:37 2009
New Revision: 66145

Modified:
   pypy/branch/pyjitpl5/pypy/jit/tl/test/test_tla.py
   pypy/branch/pyjitpl5/pypy/jit/tl/tla.py
Log:
kill W_StringObject.add, and write some exercises


Modified: pypy/branch/pyjitpl5/pypy/jit/tl/test/test_tla.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/test/test_tla.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/test/test_tla.py	Tue Jul  7 11:47:37 2009
@@ -104,7 +104,13 @@
     assert isinstance(res, tla.W_StringObject)
     assert res.strvalue == 'x'
 
+# ____________________________________________________________
+# EXERCISES
+# ____________________________________________________________
+
+
 def test_add_strings():
+    py.test.skip('exercise!')
     code = [
         tla.NEWSTR, ord('d'),
         tla.ADD,
@@ -115,5 +121,36 @@
     res = interp(code, tla.W_StringObject('Hello worl'))
     assert res.strvalue == 'Hello world!'
 
+def test_mul():
+    py.test.skip('exercise!')
+    code = [
+        tla.CONST_INT, 2,
+        tla.MUL,
+        tla.RETURN
+        ]
+    res = interp(code, tla.W_IntObject(21))
+    assert res.intvalue == 42
+
+def test_mul_strings():
+    py.test.skip('exercise!')
+    code = [
+        tla.CONST_INT, 3
+        tla.MUL,
+        tla.RETURN
+        ] 
+    res = interp(code, tla.W_StringObject('foo '))
+    assert res.strvalue == 'foo foo foo '
+
+def test_div_float():
+    py.test.skip('exercise!')
+    code = [
+        tla.CONST_INT, 2
+        tla.DIV,
+        tla.RETURN
+        ]
+    res = interp(code, tla.W_IntObject(5))
+    assert isinstance(res, tla.W_FloatObject)
+    assert res.floatval == 2.5
+
 # ____________________________________________________________ 
 

Modified: pypy/branch/pyjitpl5/pypy/jit/tl/tla.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/tla.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/tla.py	Tue Jul  7 11:47:37 2009
@@ -3,7 +3,13 @@
 
 
 class W_Object:
-    pass
+
+    def is_true(self):
+        raise NotImplementedError
+
+    def add(self):
+        raise NotImplementedError
+
 
 
 class W_IntObject(W_Object):
@@ -36,12 +42,6 @@
     def is_true(self):
         return len(self.strvalue) != 0
 
-    def add(self, w_other):
-        if isinstance(w_other, W_StringObject):
-            concat = self.strvalue + w_other.strvalue
-            return W_StringObject(concat)
-        else:
-            raise OperationError
 
 class OperationError:
     pass



More information about the Pypy-commit mailing list