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

Subversion Repositories openrisc

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

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 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
type T struct {
10
        a float64
11
        b int64
12
        c string
13
        d byte
14
}
15
 
16
var a = []int{ 1, 2, 3 }
17
var NIL []int
18
 
19
func arraycmptest() {
20
        if NIL != nil {
21
                println("fail1:", NIL, "!= nil")
22
        }
23
        if nil != NIL {
24
                println("fail2: nil !=", NIL)
25
        }
26
        if a == nil || nil == a {
27
                println("fail3:", a, "== nil")
28
        }
29
}
30
 
31
func SameArray(a, b []int) bool {
32
        if len(a) != len(b) || cap(a) != cap(b) {
33
                return false
34
        }
35
        if len(a) > 0 && &a[0] != &b[0] {
36
                return false
37
        }
38
        return true
39
}
40
 
41
var t = T{1.5, 123, "hello", 255}
42
var mt = make(map[int]T)
43
var ma = make(map[int][]int)
44
 
45
func maptest() {
46
        mt[0] = t
47
        t1 := mt[0]
48
        if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
49
                println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
50
        }
51
 
52
        ma[1] = a
53
        a1 := ma[1]
54
        if !SameArray(a, a1) {
55
                println("fail: map val array", a, a1)
56
        }
57
}
58
 
59
var ct = make(chan T)
60
var ca = make(chan []int)
61
 
62
func send() {
63
        ct <- t
64
        ca <- a
65
}
66
 
67
func chantest() {
68
        go send()
69
 
70
        t1 := <-ct
71
        if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
72
                println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
73
        }
74
 
75
        a1 := <-ca
76
        if !SameArray(a, a1) {
77
                println("fail: map val array", a, a1)
78
        }
79
}
80
 
81
type E struct { }
82
var e E
83
 
84
func interfacetest() {
85
        var i interface{}
86
 
87
        i = a
88
        a1 := i.([]int)
89
        if !SameArray(a, a1) {
90
                println("interface <-> []int", a, a1)
91
        }
92
        pa := new([]int)
93
        *pa = a
94
        i = pa
95
        a1 = *i.(*[]int)
96
        if !SameArray(a, a1) {
97
                println("interface <-> *[]int", a, a1)
98
        }
99
 
100
        i = t
101
        t1 := i.(T)
102
        if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
103
                println("interface <-> struct", t1.a, t1.b, t1.c, t1.d)
104
        }
105
 
106
        i = e
107
        e1 := i.(E)
108
        // nothing to check; just verify it doesn't crash
109
        _ = e1
110
}
111
 
112
func main() {
113
        arraycmptest()
114
        maptest()
115
        chantest()
116
        interfacetest()
117
}

powered by: WebSVN 2.1.0

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