~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/translator/cli/test/test_backendopt.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import py
 
2
from pypy.translator.cli.test.runtest import compile_function
 
3
from pypy.translator.c.test.test_backendoptimized import \
 
4
     TestTypedOptimizedSwitchTestCase as c_TestTypedOptimizedSwitchTestCase
 
5
 
 
6
class CTestCompat:
 
7
    backend_opt = {
 
8
        'merge_if_blocks': True
 
9
        }
 
10
 
 
11
    def CodeGenerator(self):
 
12
        return self
 
13
 
 
14
    def getcompiled(self, fn, annotation):
 
15
        return compile_function(fn, annotation, backend_opt=self.backend_opt)
 
16
 
 
17
class TestOptimizedSwitchTestCase(CTestCompat, c_TestTypedOptimizedSwitchTestCase):
 
18
 
 
19
    def test_switch_naive(self):
 
20
        def fn(x):
 
21
            if x == -1:
 
22
                return 3
 
23
            elif x == 3:
 
24
                return 9
 
25
            elif x == 9:
 
26
                return -1
 
27
            return 42
 
28
        codegenerator = self.CodeGenerator()
 
29
        fn = codegenerator.getcompiled(fn, [int])
 
30
        for x in (-5,-1,0,3,9,27,48):
 
31
            assert fn(x) == fn(x)