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

« back to all changes in this revision

Viewing changes to pypy/translator/llvm/test/test_seq.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
from __future__ import division
 
2
 
 
3
import py
 
4
from pypy.objspace.flow.model import Constant, Variable
 
5
from pypy.translator.llvm.test import llvmsnippet
 
6
 
 
7
from pypy.translator.llvm.test.runtest import *
 
8
 
 
9
class TestLLVMArray(object):
 
10
    def test_char_array(self):
 
11
        from pypy.rpython.lltypesystem import lltype
 
12
        A = lltype.GcArray(lltype.Char)
 
13
        def fn(n):
 
14
            a = lltype.malloc(A, 5)
 
15
            a[4] = 'H'
 
16
            a[3] = 'e'
 
17
            a[2] = 'l'
 
18
            a[1] = 'l'
 
19
            a[0] = 'o'
 
20
            return ord(a[n]) 
 
21
        fp = compile_function(fn, [int])
 
22
        for i in range(5):
 
23
            assert fp(i) == fn(i)
 
24
 
 
25
    def test_array(self):
 
26
        f = compile_function(llvmsnippet.array_simple, [])
 
27
        assert f() == 42
 
28
 
 
29
    def test_array1(self):
 
30
        f = compile_function(llvmsnippet.array_simple1, [int])
 
31
        assert f(1) == 10
 
32
        assert f(-42) == -420
 
33
 
 
34
    def test_array_setitem(self):
 
35
        f = compile_function(llvmsnippet.array_setitem, [int])
 
36
        assert f(1) == 12
 
37
        assert f(2) == 13
 
38
        assert f(3) == 3
 
39
 
 
40
    def test_array_add(self):
 
41
        f = compile_function(llvmsnippet.array_add, [int, int, int, int, int])
 
42
        assert f(1,2,3,4,0) == 1
 
43
        assert f(1,2,3,4,1) == 2
 
44
        assert f(1,2,3,4,2) == 3
 
45
        assert f(1,2,5,6,3) == 6
 
46
 
 
47
    def test_array_double(self):
 
48
        f = compile_function(llvmsnippet.double_array, [])
 
49
        assert f() == 15
 
50
 
 
51
    def test_bool_array(self):
 
52
        f = compile_function(llvmsnippet.bool_array, [])
 
53
        assert f() == 1
 
54
 
 
55
    def test_array_arg(self):
 
56
        f = compile_function(llvmsnippet.array_arg, [int])
 
57
        assert f(5) == 0
 
58
 
 
59
    def test_array_len(self):
 
60
        f = compile_function(llvmsnippet.array_len, [])
 
61
        assert f() == 10
 
62
 
 
63
    def test_array_append(self):
 
64
        f = compile_function(llvmsnippet.array_append, [int])
 
65
        for i in range(3):
 
66
            assert f(i) == 0
 
67
        assert f(3) == 10
 
68
 
 
69
    def test_array_reverse(self):
 
70
        f = compile_function(llvmsnippet.array_reverse, [int])
 
71
        assert f(0) == 1
 
72
        assert f(1) == 0
 
73
 
 
74
    def test_range(self):
 
75
        f = compile_function(llvmsnippet.rangetest, [int])
 
76
        for i in range(10):
 
77
            assert f(i) == i
 
78
 
 
79
    def test_array_pop(self):
 
80
        f = compile_function(llvmsnippet.array_pop, [int])
 
81
        assert f(0) == 6
 
82
        assert f(1) == 7
 
83
        assert f(2) == 8
 
84
 
 
85
    def test_newlist_zero_arg(self):
 
86
        f = compile_function(llvmsnippet.newlist_zero_arg, [int])
 
87
        assert f(10) == 11
 
88
        assert f(-41) == -40
 
89
 
 
90
    def test_big_array(self):
 
91
        f = compile_function(llvmsnippet.big_array, [int])
 
92
        for i in range(18):
 
93
            assert f(i) == i
 
94
 
 
95
    def test_access_global_array(self):
 
96
        f = compile_function(llvmsnippet.access_global_array, [int, int, int])
 
97
        for i in range(5):
 
98
            for j in range(5):
 
99
                assert f(i, j, i + j) == i
 
100
        for i in range(5):
 
101
            for j in range(5):
 
102
                assert f(i, j, 0) == i + j
 
103
 
 
104
    def test_circular_list(self):
 
105
        f = compile_function(llvmsnippet.circular_list, [int])
 
106
        assert f(0) == 0
 
107
        assert f(1) == 1
 
108
        assert f(10) == 1
 
109
 
 
110
 
 
111
class TestTuple(object):
 
112
    def test_f1(self):
 
113
        f = compile_function(llvmsnippet.tuple_f1, [int])
 
114
        assert f(10) == 10
 
115
        assert f(15) == 15
 
116
 
 
117
    def test_f3(self):
 
118
        f = compile_function(llvmsnippet.tuple_f3, [int])
 
119
        assert f(10) == 10
 
120
        assert f(15) == 15
 
121
        assert f(30) == 30
 
122
 
 
123
    def test_constant_tuple(self):
 
124
        f = compile_function(llvmsnippet.constant_tuple, [int])
 
125
        for i in range(3, 7):
 
126
            assert f(i) == i + 3