blob: c3963499bcef1fec02933893a8ba142b32a18825 [file] [log] [blame]
Rob Pike2738f422008-08-11 13:32:13 -07001// $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
Rob Pike2738f422008-08-11 13:32:13 -07007package main
8
Rob Pike62b06fa2008-12-20 16:07:43 -08009import (
Rob Pike4f61fc92010-09-04 10:36:13 +100010 "fmt"
11 "strconv"
Rob Pike62b06fa2008-12-20 16:07:43 -080012)
Rob Pike2738f422008-08-11 13:32:13 -070013
Rob Pike4f61fc92010-09-04 10:36:13 +100014const count = 100
Rob Pike2738f422008-08-11 13:32:13 -070015
Russ Cox839a6842009-01-20 14:40:40 -080016func P(a []string) string {
Rob Pike4f61fc92010-09-04 10:36:13 +100017 s := "{"
Rob Pike2738f422008-08-11 13:32:13 -070018 for i := 0; i < len(a); i++ {
19 if i > 0 {
20 s += ","
21 }
Rob Pike4f61fc92010-09-04 10:36:13 +100022 s += `"` + a[i] + `"`
Rob Pike2738f422008-08-11 13:32:13 -070023 }
Russ Coxf2b5a072011-01-19 23:09:00 -050024 s += "}"
Rob Pike4f61fc92010-09-04 10:36:13 +100025 return s
Rob Pike2738f422008-08-11 13:32:13 -070026}
27
28func main() {
Rob Pike62b06fa2008-12-20 16:07:43 -080029 // Test a map literal.
Russ Coxf2b5a072011-01-19 23:09:00 -050030 mlit := map[string]int{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4}
Rob Pike62b06fa2008-12-20 16:07:43 -080031 for i := 0; i < len(mlit); i++ {
Russ Coxf2b5a072011-01-19 23:09:00 -050032 s := string([]byte{byte(i) + '0'})
Rob Pike62b06fa2008-12-20 16:07:43 -080033 if mlit[s] != i {
Rob Pike61f33022009-01-15 13:48:11 -080034 fmt.Printf("mlit[%s] = %d\n", s, mlit[s])
Rob Pike62b06fa2008-12-20 16:07:43 -080035 }
36 }
Rob Pike2738f422008-08-11 13:32:13 -070037
Russ Coxf2b5a072011-01-19 23:09:00 -050038 mib := make(map[int]bool)
39 mii := make(map[int]int)
40 mfi := make(map[float32]int)
41 mif := make(map[int]float32)
42 msi := make(map[string]int)
43 mis := make(map[int]string)
44 mss := make(map[string]string)
45 mspa := make(map[string][]string)
Rob Pike2738f422008-08-11 13:32:13 -070046 // BUG need an interface map both ways too
47
48 type T struct {
Russ Coxf2b5a072011-01-19 23:09:00 -050049 i int64 // can't use string here; struct values are only compared at the top level
50 f float32
Rob Pike4f61fc92010-09-04 10:36:13 +100051 }
Russ Coxf2b5a072011-01-19 23:09:00 -050052 mipT := make(map[int]*T)
53 mpTi := make(map[*T]int)
54 mit := make(map[int]T)
55 // mti := make(map[T] int)
Rob Pike2738f422008-08-11 13:32:13 -070056
Russ Coxf2b5a072011-01-19 23:09:00 -050057 type M map[int]int
58 mipM := make(map[int]M)
Rob Pike2738f422008-08-11 13:32:13 -070059
Russ Coxf2b5a072011-01-19 23:09:00 -050060 var apT [2 * count]*T
Rob Pike2738f422008-08-11 13:32:13 -070061
62 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +100063 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -050064 s10 := strconv.Itoa(i * 10)
65 f := float32(i)
66 t := T{int64(i), f}
Rob Pike4f61fc92010-09-04 10:36:13 +100067 apT[i] = new(T)
68 apT[i].i = int64(i)
69 apT[i].f = f
Russ Coxf2b5a072011-01-19 23:09:00 -050070 apT[2*i] = new(T) // need twice as many entries as we use, for the nonexistence check
Rob Pike4f61fc92010-09-04 10:36:13 +100071 apT[2*i].i = int64(i)
72 apT[2*i].f = f
Russ Coxf2b5a072011-01-19 23:09:00 -050073 m := M{i: i + 1}
Rob Pike4f61fc92010-09-04 10:36:13 +100074 mib[i] = (i != 0)
Russ Coxf2b5a072011-01-19 23:09:00 -050075 mii[i] = 10 * i
76 mfi[float32(i)] = 10 * i
77 mif[i] = 10.0 * f
Rob Pike4f61fc92010-09-04 10:36:13 +100078 mis[i] = s
79 msi[s] = i
80 mss[s] = s10
81 mss[s] = s10
82 as := make([]string, 2)
Russ Coxf2b5a072011-01-19 23:09:00 -050083 as[0] = s10
84 as[1] = s10
Rob Pike4f61fc92010-09-04 10:36:13 +100085 mspa[s] = as
86 mipT[i] = apT[i]
87 mpTi[apT[i]] = i
88 mipM[i] = m
89 mit[i] = t
Russ Coxf2b5a072011-01-19 23:09:00 -050090 // mti[t] = i
Rob Pike2738f422008-08-11 13:32:13 -070091 }
92
93 // test len
94 if len(mib) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +100095 fmt.Printf("len(mib) = %d\n", len(mib))
Rob Pike2738f422008-08-11 13:32:13 -070096 }
97 if len(mii) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +100098 fmt.Printf("len(mii) = %d\n", len(mii))
Rob Pike2738f422008-08-11 13:32:13 -070099 }
100 if len(mfi) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000101 fmt.Printf("len(mfi) = %d\n", len(mfi))
Rob Pike2738f422008-08-11 13:32:13 -0700102 }
103 if len(mif) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000104 fmt.Printf("len(mif) = %d\n", len(mif))
Rob Pike2738f422008-08-11 13:32:13 -0700105 }
106 if len(msi) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000107 fmt.Printf("len(msi) = %d\n", len(msi))
Rob Pike2738f422008-08-11 13:32:13 -0700108 }
109 if len(mis) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000110 fmt.Printf("len(mis) = %d\n", len(mis))
Rob Pike2738f422008-08-11 13:32:13 -0700111 }
112 if len(mss) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000113 fmt.Printf("len(mss) = %d\n", len(mss))
Rob Pike2738f422008-08-11 13:32:13 -0700114 }
115 if len(mspa) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000116 fmt.Printf("len(mspa) = %d\n", len(mspa))
Rob Pike2738f422008-08-11 13:32:13 -0700117 }
118 if len(mipT) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000119 fmt.Printf("len(mipT) = %d\n", len(mipT))
Rob Pike2738f422008-08-11 13:32:13 -0700120 }
121 if len(mpTi) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000122 fmt.Printf("len(mpTi) = %d\n", len(mpTi))
Rob Pike2738f422008-08-11 13:32:13 -0700123 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500124 // if len(mti) != count {
125 // fmt.Printf("len(mti) = %d\n", len(mti))
126 // }
Rob Pike2738f422008-08-11 13:32:13 -0700127 if len(mipM) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000128 fmt.Printf("len(mipM) = %d\n", len(mipM))
Rob Pike62b06fa2008-12-20 16:07:43 -0800129 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500130 // if len(mti) != count {
131 // fmt.Printf("len(mti) = %d\n", len(mti))
132 // }
Rob Pike62b06fa2008-12-20 16:07:43 -0800133 if len(mit) != count {
Rob Pike4f61fc92010-09-04 10:36:13 +1000134 fmt.Printf("len(mit) = %d\n", len(mit))
Rob Pike2738f422008-08-11 13:32:13 -0700135 }
Russ Cox08ca30b2008-12-19 03:05:37 -0800136
Rob Pike2738f422008-08-11 13:32:13 -0700137 // test construction directly
138 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000139 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500140 s10 := strconv.Itoa(i * 10)
141 f := float32(i)
Rob Pike4f61fc92010-09-04 10:36:13 +1000142 // BUG m := M(i, i+1)
Rob Pike2738f422008-08-11 13:32:13 -0700143 if mib[i] != (i != 0) {
Rob Pike4f61fc92010-09-04 10:36:13 +1000144 fmt.Printf("mib[%d] = %t\n", i, mib[i])
Rob Pike2738f422008-08-11 13:32:13 -0700145 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500146 if mii[i] != 10*i {
Rob Pike4f61fc92010-09-04 10:36:13 +1000147 fmt.Printf("mii[%d] = %d\n", i, mii[i])
Rob Pike2738f422008-08-11 13:32:13 -0700148 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500149 if mfi[f] != 10*i {
Rob Pike4f61fc92010-09-04 10:36:13 +1000150 fmt.Printf("mfi[%d] = %d\n", i, mfi[f])
Rob Pike2738f422008-08-11 13:32:13 -0700151 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500152 if mif[i] != 10.0*f {
Rob Pike4f61fc92010-09-04 10:36:13 +1000153 fmt.Printf("mif[%d] = %g\n", i, mif[i])
Rob Pike2738f422008-08-11 13:32:13 -0700154 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500155 if mis[i] != s {
Rob Pike4f61fc92010-09-04 10:36:13 +1000156 fmt.Printf("mis[%d] = %s\n", i, mis[i])
Rob Pike2738f422008-08-11 13:32:13 -0700157 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500158 if msi[s] != i {
Rob Pike4f61fc92010-09-04 10:36:13 +1000159 fmt.Printf("msi[%s] = %d\n", s, msi[s])
Rob Pike2738f422008-08-11 13:32:13 -0700160 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800161 if mss[s] != s10 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000162 fmt.Printf("mss[%s] = %g\n", s, mss[s])
Rob Pike2738f422008-08-11 13:32:13 -0700163 }
Russ Coxebd27d62009-10-09 11:18:32 -0700164 for j := 0; j < len(mspa[s]); j++ {
Rob Pike62b06fa2008-12-20 16:07:43 -0800165 if mspa[s][j] != s10 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000166 fmt.Printf("mspa[%s][%d] = %s\n", s, j, mspa[s][j])
Rob Pike2738f422008-08-11 13:32:13 -0700167 }
168 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500169 if mipT[i].i != int64(i) || mipT[i].f != f {
Rob Pike4f61fc92010-09-04 10:36:13 +1000170 fmt.Printf("mipT[%d] = %v\n", i, mipT[i])
Rob Pike2738f422008-08-11 13:32:13 -0700171 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500172 if mpTi[apT[i]] != i {
Rob Pike4f61fc92010-09-04 10:36:13 +1000173 fmt.Printf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]])
Rob Pike2738f422008-08-11 13:32:13 -0700174 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500175 // if(mti[t] != i) {
176 // fmt.Printf("mti[%s] = %s\n", s, mti[t])
177 // }
178 if mipM[i][i] != i+1 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000179 fmt.Printf("mipM[%d][%d] = %d\n", i, i, mipM[i][i])
Rob Pike62b06fa2008-12-20 16:07:43 -0800180 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500181 // if(mti[t] != i) {
182 // fmt.Printf("mti[%v] = %d\n", t, mti[t])
183 // }
184 if mit[i].i != int64(i) || mit[i].f != f {
Rob Pike4f61fc92010-09-04 10:36:13 +1000185 fmt.Printf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f)
Rob Pike2738f422008-08-11 13:32:13 -0700186 }
187 }
188
Rob Pike2738f422008-08-11 13:32:13 -0700189 // test existence with tuple check
190 // failed lookups yield a false value for the boolean.
191 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000192 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500193 f := float32(i)
Rob Pike2738f422008-08-11 13:32:13 -0700194 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000195 _, b := mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700196 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000197 fmt.Printf("tuple existence decl: mib[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700198 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000199 _, b = mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700200 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000201 fmt.Printf("tuple existence assign: mib[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700202 }
203 }
204 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000205 _, b := mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700206 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000207 fmt.Printf("tuple existence decl: mii[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700208 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000209 _, b = mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700210 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000211 fmt.Printf("tuple existence assign: mii[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700212 }
213 }
214 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000215 _, b := mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700216 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000217 fmt.Printf("tuple existence decl: mfi[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700218 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000219 _, b = mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700220 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000221 fmt.Printf("tuple existence assign: mfi[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700222 }
223 }
224 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000225 _, b := mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700226 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000227 fmt.Printf("tuple existence decl: mif[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700228 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000229 _, b = mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700230 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000231 fmt.Printf("tuple existence assign: mif[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700232 }
233 }
234 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000235 _, b := mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700236 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000237 fmt.Printf("tuple existence decl: mis[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700238 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000239 _, b = mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700240 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000241 fmt.Printf("tuple existence assign: mis[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700242 }
243 }
244 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000245 _, b := msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700246 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000247 fmt.Printf("tuple existence decl: msi[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700248 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000249 _, b = msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700250 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000251 fmt.Printf("tuple existence assign: msi[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700252 }
253 }
254 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000255 _, b := mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700256 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000257 fmt.Printf("tuple existence decl: mss[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700258 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000259 _, b = mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700260 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000261 fmt.Printf("tuple existence assign: mss[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700262 }
263 }
264 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000265 _, b := mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700266 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000267 fmt.Printf("tuple existence decl: mspa[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700268 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000269 _, b = mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700270 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000271 fmt.Printf("tuple existence assign: mspa[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700272 }
273 }
274 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000275 _, b := mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700276 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000277 fmt.Printf("tuple existence decl: mipT[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700278 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000279 _, b = mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700280 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000281 fmt.Printf("tuple existence assign: mipT[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700282 }
283 }
284 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000285 _, b := mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700286 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000287 fmt.Printf("tuple existence decl: mpTi[apT[%d]]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700288 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000289 _, b = mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700290 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000291 fmt.Printf("tuple existence assign: mpTi[apT[%d]]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700292 }
293 }
Rob Pike2738f422008-08-11 13:32:13 -0700294 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000295 _, b := mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700296 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000297 fmt.Printf("tuple existence decl: mipM[%d]\n", i)
Rob Pike2738f422008-08-11 13:32:13 -0700298 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000299 _, b = mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700300 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000301 fmt.Printf("tuple existence assign: mipM[%d]\n", i)
Rob Pike62b06fa2008-12-20 16:07:43 -0800302 }
303 }
304 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000305 _, b := mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800306 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000307 fmt.Printf("tuple existence decl: mit[%d]\n", i)
Rob Pike62b06fa2008-12-20 16:07:43 -0800308 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000309 _, b = mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800310 if !b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000311 fmt.Printf("tuple existence assign: mit[%d]\n", i)
Rob Pike62b06fa2008-12-20 16:07:43 -0800312 }
313 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500314 // {
315 // _, b := mti[t]
316 // if !b {
317 // fmt.Printf("tuple existence decl: mti[%d]\n", i)
318 // }
319 // _, b = mti[t]
320 // if !b {
321 // fmt.Printf("tuple existence assign: mti[%d]\n", i)
322 // }
323 // }
Rob Pike2738f422008-08-11 13:32:13 -0700324 }
325
326 // test nonexistence with tuple check
327 // failed lookups yield a false value for the boolean.
328 for i := count; i < 2*count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000329 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500330 f := float32(i)
Rob Pike2738f422008-08-11 13:32:13 -0700331 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000332 _, b := mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700333 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000334 fmt.Printf("tuple nonexistence decl: mib[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700335 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000336 _, b = mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700337 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000338 fmt.Printf("tuple nonexistence assign: mib[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700339 }
340 }
341 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000342 _, b := mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700343 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000344 fmt.Printf("tuple nonexistence decl: mii[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700345 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000346 _, b = mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700347 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000348 fmt.Printf("tuple nonexistence assign: mii[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700349 }
350 }
351 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000352 _, b := mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700353 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000354 fmt.Printf("tuple nonexistence decl: mfi[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700355 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000356 _, b = mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700357 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000358 fmt.Printf("tuple nonexistence assign: mfi[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700359 }
360 }
361 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000362 _, b := mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700363 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000364 fmt.Printf("tuple nonexistence decl: mif[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700365 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000366 _, b = mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700367 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000368 fmt.Printf("tuple nonexistence assign: mif[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700369 }
370 }
371 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000372 _, b := mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700373 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000374 fmt.Printf("tuple nonexistence decl: mis[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700375 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000376 _, b = mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700377 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000378 fmt.Printf("tuple nonexistence assign: mis[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700379 }
380 }
381 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000382 _, b := msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700383 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000384 fmt.Printf("tuple nonexistence decl: msi[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700385 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000386 _, b = msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700387 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000388 fmt.Printf("tuple nonexistence assign: msi[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700389 }
390 }
391 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000392 _, b := mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700393 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000394 fmt.Printf("tuple nonexistence decl: mss[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700395 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000396 _, b = mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700397 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000398 fmt.Printf("tuple nonexistence assign: mss[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700399 }
400 }
401 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000402 _, b := mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700403 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000404 fmt.Printf("tuple nonexistence decl: mspa[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700405 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000406 _, b = mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700407 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000408 fmt.Printf("tuple nonexistence assign: mspa[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700409 }
410 }
411 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000412 _, b := mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700413 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000414 fmt.Printf("tuple nonexistence decl: mipT[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700415 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000416 _, b = mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700417 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000418 fmt.Printf("tuple nonexistence assign: mipT[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700419 }
420 }
421 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000422 _, b := mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700423 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000424 fmt.Printf("tuple nonexistence decl: mpTi[apt[%d]]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700425 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000426 _, b = mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700427 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000428 fmt.Printf("tuple nonexistence assign: mpTi[apT[%d]]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700429 }
430 }
Rob Pike2738f422008-08-11 13:32:13 -0700431 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000432 _, b := mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700433 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000434 fmt.Printf("tuple nonexistence decl: mipM[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700435 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000436 _, b = mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700437 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000438 fmt.Printf("tuple nonexistence assign: mipM[%d]", i)
Rob Pike62b06fa2008-12-20 16:07:43 -0800439 }
440 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500441 // {
442 // _, b := mti[t]
443 // if b {
444 // fmt.Printf("tuple nonexistence decl: mti[%d]", i)
445 // }
446 // _, b = mti[t]
447 // if b {
448 // fmt.Printf("tuple nonexistence assign: mti[%d]", i)
449 // }
450 // }
Rob Pike62b06fa2008-12-20 16:07:43 -0800451 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000452 _, b := mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800453 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000454 fmt.Printf("tuple nonexistence decl: mit[%d]", i)
Rob Pike62b06fa2008-12-20 16:07:43 -0800455 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000456 _, b = mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800457 if b {
Rob Pike4f61fc92010-09-04 10:36:13 +1000458 fmt.Printf("tuple nonexistence assign: mit[%d]", i)
Rob Pike2738f422008-08-11 13:32:13 -0700459 }
460 }
461 }
Russ Cox08ca30b2008-12-19 03:05:37 -0800462
Rob Pike2738f422008-08-11 13:32:13 -0700463 // tests for structured map element updates
464 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000465 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500466 mspa[s][i%2] = "deleted"
467 if mspa[s][i%2] != "deleted" {
468 fmt.Printf("update mspa[%s][%d] = %s\n", s, i%2, mspa[s][i%2])
Rob Pike2738f422008-08-11 13:32:13 -0700469 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800470
Rob Pike4f61fc92010-09-04 10:36:13 +1000471 mipT[i].i += 1
Rob Pike62b06fa2008-12-20 16:07:43 -0800472 if mipT[i].i != int64(i)+1 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000473 fmt.Printf("update mipT[%d].i = %d\n", i, mipT[i].i)
Rob Pike2738f422008-08-11 13:32:13 -0700474 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500475 mipT[i].f = float32(i + 1)
476 if mipT[i].f != float32(i+1) {
Rob Pike4f61fc92010-09-04 10:36:13 +1000477 fmt.Printf("update mipT[%d].f = %g\n", i, mipT[i].f)
Rob Pike2738f422008-08-11 13:32:13 -0700478 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800479
Rob Pike4f61fc92010-09-04 10:36:13 +1000480 mipM[i][i]++
Russ Coxf2b5a072011-01-19 23:09:00 -0500481 if mipM[i][i] != (i+1)+1 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000482 fmt.Printf("update mipM[%d][%d] = %i\n", i, i, mipM[i][i])
Rob Pike2738f422008-08-11 13:32:13 -0700483 }
484 }
Russ Coxae54cf72009-09-15 12:42:24 -0700485
Russ Cox86145612009-03-23 18:32:37 -0700486 // test range on nil map
Russ Coxf2b5a072011-01-19 23:09:00 -0500487 var mnil map[string]int
Russ Coxae54cf72009-09-15 12:42:24 -0700488 for _, _ = range mnil {
Rob Pike4f61fc92010-09-04 10:36:13 +1000489 panic("range mnil")
Russ Cox86145612009-03-23 18:32:37 -0700490 }
Rob Pike2738f422008-08-11 13:32:13 -0700491}