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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 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
var a, b, c, d, e, f, g, h, i int
10
 
11
func printit() {
12
        println(a, b, c, d, e, f, g, h, i)
13
}
14
 
15
func testit(permuteok bool) bool {
16
        if a+b+c+d+e+f+g+h+i != 45 {
17
                print("sum does not add to 45\n")
18
                printit()
19
                return false
20
        }
21
        return permuteok ||
22
                a == 1 &&
23
                        b == 2 &&
24
                        c == 3 &&
25
                        d == 4 &&
26
                        e == 5 &&
27
                        f == 6 &&
28
                        g == 7 &&
29
                        h == 8 &&
30
                        i == 9
31
}
32
 
33
func swap(x, y int) (u, v int) {
34
        return y, x
35
}
36
 
37
func main() {
38
        a = 1
39
        b = 2
40
        c = 3
41
        d = 4
42
        e = 5
43
        f = 6
44
        g = 7
45
        h = 8
46
        i = 9
47
 
48
        if !testit(false) {
49
                panic("init val\n")
50
        }
51
 
52
        for z := 0; z < 100; z++ {
53
                a, b, c, d, e, f, g, h, i = b, c, d, a, i, e, f, g, h
54
 
55
                if !testit(z%20 != 19) {
56
                        print("on ", z, "th iteration\n")
57
                        printit()
58
                        panic("fail")
59
                }
60
        }
61
 
62
        if !testit(false) {
63
                print("final val\n")
64
                printit()
65
                panic("fail")
66
        }
67
 
68
        a, b = swap(1, 2)
69
        if a != 2 || b != 1 {
70
                panic("bad swap")
71
        }
72
 
73
        a, b = swap(swap(a, b))
74
        if a != 2 || b != 1 {
75
                panic("bad swap")
76
        }
77
}

powered by: WebSVN 2.1.0

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