[pypy-svn] pypy default: port test_factorial from test_pypy_c

antocuni commits-noreply at bitbucket.org
Wed Feb 23 18:33:35 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r42236:695b175d4cff
Date: 2011-02-23 18:31 +0100
http://bitbucket.org/pypy/pypy/changeset/695b175d4cff/

Log:	port test_factorial from test_pypy_c

diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -35,6 +35,27 @@
             jump(p0, p1, p2, p3, p4, p5, i13, i11, i8)
         """)
 
+    def test_factorial(self):
+        def fact(n):
+            r = 1
+            while n > 1:
+                r *= n
+                n -= 1
+            return r
+        log = self.run(fact, [7], threshold=5)
+        assert log.result == 5040
+        loop, = log.loops_by_filename(self.filepath)
+        assert loop.match("""
+            i7 = int_gt(i4, 1)
+            guard_true(i7)
+            i8 = int_mul_ovf(i5, i4)
+            guard_no_overflow()
+            i10 = int_sub(i4, 1)
+            --TICK--
+            jump(p0, p1, p2, p3, i10, i8)
+        """)
+
+
     def test_cmp_exc(self):
         def f1(n):
             def f():


More information about the Pypy-commit mailing list