OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ddd.go] - Blame information for rev 858

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2010 The Go Authors.  All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
func sum(args ...int) int {
10
        s := 0
11
        for _, v := range args {
12
                s += v
13
        }
14
        return s
15
}
16
 
17
func sumC(args ...int) int { return func() int { return sum(args...) }() }
18
 
19
var sumD = func(args ...int) int { return sum(args...) }
20
 
21
var sumE = func() func(...int) int { return func(args ...int) int { return sum(args...) } }()
22
 
23
var sumF = func(args ...int) func() int { return func() int { return sum(args...) } }
24
 
25
func sumA(args []int) int {
26
        s := 0
27
        for _, v := range args {
28
                s += v
29
        }
30
        return s
31
}
32
 
33
func sumB(args []int) int { return sum(args...) }
34
 
35
func sum2(args ...int) int { return 2 * sum(args...) }
36
 
37
func sum3(args ...int) int { return 3 * sumA(args) }
38
 
39
func sum4(args ...int) int { return 4 * sumB(args) }
40
 
41
func intersum(args ...interface{}) int {
42
        s := 0
43
        for _, v := range args {
44
                s += v.(int)
45
        }
46
        return s
47
}
48
 
49
type T []T
50
 
51
func ln(args ...T) int { return len(args) }
52
 
53
func ln2(args ...T) int { return 2 * ln(args...) }
54
 
55
func (*T) Sum(args ...int) int { return sum(args...) }
56
 
57
type U struct {
58
        *T
59
}
60
 
61
func main() {
62
        if x := sum(1, 2, 3); x != 6 {
63
                println("sum 6", x)
64
                panic("fail")
65
        }
66
        if x := sum(); x != 0 {
67
                println("sum 0", x)
68
                panic("fail")
69
        }
70
        if x := sum(10); x != 10 {
71
                println("sum 10", x)
72
                panic("fail")
73
        }
74
        if x := sum(1, 8); x != 9 {
75
                println("sum 9", x)
76
                panic("fail")
77
        }
78
        if x := sumC(4, 5, 6); x != 15 {
79
                println("sumC 15", x)
80
                panic("fail")
81
        }
82
        if x := sumD(4, 5, 7); x != 16 {
83
                println("sumD 16", x)
84
                panic("fail")
85
        }
86
        if x := sumE(4, 5, 8); x != 17 {
87
                println("sumE 17", x)
88
                panic("fail")
89
        }
90
        if x := sumF(4, 5, 9)(); x != 18 {
91
                println("sumF 18", x)
92
                panic("fail")
93
        }
94
        if x := sum2(1, 2, 3); x != 2*6 {
95
                println("sum 6", x)
96
                panic("fail")
97
        }
98
        if x := sum2(); x != 2*0 {
99
                println("sum 0", x)
100
                panic("fail")
101
        }
102
        if x := sum2(10); x != 2*10 {
103
                println("sum 10", x)
104
                panic("fail")
105
        }
106
        if x := sum2(1, 8); x != 2*9 {
107
                println("sum 9", x)
108
                panic("fail")
109
        }
110
        if x := sum3(1, 2, 3); x != 3*6 {
111
                println("sum 6", x)
112
                panic("fail")
113
        }
114
        if x := sum3(); x != 3*0 {
115
                println("sum 0", x)
116
                panic("fail")
117
        }
118
        if x := sum3(10); x != 3*10 {
119
                println("sum 10", x)
120
                panic("fail")
121
        }
122
        if x := sum3(1, 8); x != 3*9 {
123
                println("sum 9", x)
124
                panic("fail")
125
        }
126
        if x := sum4(1, 2, 3); x != 4*6 {
127
                println("sum 6", x)
128
                panic("fail")
129
        }
130
        if x := sum4(); x != 4*0 {
131
                println("sum 0", x)
132
                panic("fail")
133
        }
134
        if x := sum4(10); x != 4*10 {
135
                println("sum 10", x)
136
                panic("fail")
137
        }
138
        if x := sum4(1, 8); x != 4*9 {
139
                println("sum 9", x)
140
                panic("fail")
141
        }
142
        if x := intersum(1, 2, 3); x != 6 {
143
                println("intersum 6", x)
144
                panic("fail")
145
        }
146
        if x := intersum(); x != 0 {
147
                println("intersum 0", x)
148
                panic("fail")
149
        }
150
        if x := intersum(10); x != 10 {
151
                println("intersum 10", x)
152
                panic("fail")
153
        }
154
        if x := intersum(1, 8); x != 9 {
155
                println("intersum 9", x)
156
                panic("fail")
157
        }
158
 
159
        if x := ln(nil, nil, nil); x != 3 {
160
                println("ln 3", x)
161
                panic("fail")
162
        }
163
        if x := ln([]T{}); x != 1 {
164
                println("ln 1", x)
165
                panic("fail")
166
        }
167
        if x := ln2(nil, nil, nil); x != 2*3 {
168
                println("ln2 3", x)
169
                panic("fail")
170
        }
171
        if x := ln2([]T{}); x != 2*1 {
172
                println("ln2 1", x)
173
                panic("fail")
174
        }
175
        if x := ((*T)(nil)).Sum(1, 3, 5, 7); x != 16 {
176
                println("(*T)(nil).Sum", x)
177
                panic("fail")
178
        }
179
        if x := (*T).Sum(nil, 1, 3, 5, 6); x != 15 {
180
                println("(*T).Sum", x)
181
                panic("fail")
182
        }
183
        if x := (&U{}).Sum(1, 3, 5, 5); x != 14 {
184
                println("(&U{}).Sum", x)
185
                panic("fail")
186
        }
187
        var u U
188
        if x := u.Sum(1, 3, 5, 4); x != 13 {
189
                println("u.Sum", x)
190
                panic("fail")
191
        }
192
        if x := (&u).Sum(1, 3, 5, 3); x != 12 {
193
                println("(&u).Sum", x)
194
                panic("fail")
195
        }
196
        var i interface {
197
                Sum(...int) int
198
        } = &u
199
        if x := i.Sum(2, 3, 5, 7); x != 17 {
200
                println("i(=&u).Sum", x)
201
                panic("fail")
202
        }
203
        i = u
204
        if x := i.Sum(2, 3, 5, 6); x != 16 {
205
                println("i(=u).Sum", x)
206
                panic("fail")
207
        }
208
        /* TODO(rsc): Enable once nested method expressions work.
209
        if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 {
210
                println("(*U).Sum", x)
211
                panic("fail")
212
        }
213
        if x := U.Sum(U{}, 1, 3, 5, 1); x != 10 {
214
                println("U.Sum", x)
215
                panic("fail")
216
        }
217
        */
218
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.