blob: 2c1cf8a14038259d1453a57e3d4e7a7d27da7ea6 [file] [log] [blame]
Russ Cox57eb06f2012-02-16 23:51:04 -05001// run
Rob Pike2738f422008-08-11 13:32:13 -07002
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 Pike501f0b52012-02-23 18:47:26 +11007// Test maps, almost exhaustively.
Alan Donovan161ba662014-08-06 17:02:55 -04008// Complexity (linearity) test is in maplinear.go.
Rob Pike501f0b52012-02-23 18:47:26 +11009
Rob Pike2738f422008-08-11 13:32:13 -070010package main
11
Rob Pike62b06fa2008-12-20 16:07:43 -080012import (
Rob Pike4f61fc92010-09-04 10:36:13 +100013 "fmt"
Russ Cox408f0b12012-01-26 16:25:07 -050014 "math"
Rob Pike4f61fc92010-09-04 10:36:13 +100015 "strconv"
Rob Pike62b06fa2008-12-20 16:07:43 -080016)
Rob Pike2738f422008-08-11 13:32:13 -070017
Rob Pike4f61fc92010-09-04 10:36:13 +100018const count = 100
Rob Pike2738f422008-08-11 13:32:13 -070019
Russ Cox839a6842009-01-20 14:40:40 -080020func P(a []string) string {
Rob Pike4f61fc92010-09-04 10:36:13 +100021 s := "{"
Rob Pike2738f422008-08-11 13:32:13 -070022 for i := 0; i < len(a); i++ {
23 if i > 0 {
24 s += ","
25 }
Rob Pike4f61fc92010-09-04 10:36:13 +100026 s += `"` + a[i] + `"`
Rob Pike2738f422008-08-11 13:32:13 -070027 }
Russ Coxf2b5a072011-01-19 23:09:00 -050028 s += "}"
Rob Pike4f61fc92010-09-04 10:36:13 +100029 return s
Rob Pike2738f422008-08-11 13:32:13 -070030}
31
32func main() {
Russ Cox6ebf8a62012-01-30 13:41:38 -050033 testbasic()
34 testfloat()
35 testnan()
36}
37
38func testbasic() {
Rob Pike62b06fa2008-12-20 16:07:43 -080039 // Test a map literal.
Russ Coxf2b5a072011-01-19 23:09:00 -050040 mlit := map[string]int{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4}
Rob Pike62b06fa2008-12-20 16:07:43 -080041 for i := 0; i < len(mlit); i++ {
Russ Coxf2b5a072011-01-19 23:09:00 -050042 s := string([]byte{byte(i) + '0'})
Rob Pike62b06fa2008-12-20 16:07:43 -080043 if mlit[s] != i {
Alan Donovan052c9422013-02-12 13:17:49 -050044 panic(fmt.Sprintf("mlit[%s] = %d\n", s, mlit[s]))
Rob Pike62b06fa2008-12-20 16:07:43 -080045 }
46 }
Rob Pike2738f422008-08-11 13:32:13 -070047
Russ Coxf2b5a072011-01-19 23:09:00 -050048 mib := make(map[int]bool)
49 mii := make(map[int]int)
50 mfi := make(map[float32]int)
51 mif := make(map[int]float32)
52 msi := make(map[string]int)
53 mis := make(map[int]string)
54 mss := make(map[string]string)
55 mspa := make(map[string][]string)
Rob Pike2738f422008-08-11 13:32:13 -070056 // BUG need an interface map both ways too
57
58 type T struct {
Russ Coxf2b5a072011-01-19 23:09:00 -050059 i int64 // can't use string here; struct values are only compared at the top level
60 f float32
Rob Pike4f61fc92010-09-04 10:36:13 +100061 }
Russ Coxf2b5a072011-01-19 23:09:00 -050062 mipT := make(map[int]*T)
63 mpTi := make(map[*T]int)
64 mit := make(map[int]T)
65 // mti := make(map[T] int)
Rob Pike2738f422008-08-11 13:32:13 -070066
Russ Coxf2b5a072011-01-19 23:09:00 -050067 type M map[int]int
68 mipM := make(map[int]M)
Rob Pike2738f422008-08-11 13:32:13 -070069
Russ Coxf2b5a072011-01-19 23:09:00 -050070 var apT [2 * count]*T
Rob Pike2738f422008-08-11 13:32:13 -070071
72 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +100073 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -050074 s10 := strconv.Itoa(i * 10)
75 f := float32(i)
76 t := T{int64(i), f}
Rob Pike4f61fc92010-09-04 10:36:13 +100077 apT[i] = new(T)
78 apT[i].i = int64(i)
79 apT[i].f = f
Russ Coxf2b5a072011-01-19 23:09:00 -050080 apT[2*i] = new(T) // need twice as many entries as we use, for the nonexistence check
Rob Pike4f61fc92010-09-04 10:36:13 +100081 apT[2*i].i = int64(i)
82 apT[2*i].f = f
Russ Coxf2b5a072011-01-19 23:09:00 -050083 m := M{i: i + 1}
Rob Pike4f61fc92010-09-04 10:36:13 +100084 mib[i] = (i != 0)
Russ Coxf2b5a072011-01-19 23:09:00 -050085 mii[i] = 10 * i
86 mfi[float32(i)] = 10 * i
87 mif[i] = 10.0 * f
Rob Pike4f61fc92010-09-04 10:36:13 +100088 mis[i] = s
89 msi[s] = i
90 mss[s] = s10
91 mss[s] = s10
92 as := make([]string, 2)
Russ Coxf2b5a072011-01-19 23:09:00 -050093 as[0] = s10
94 as[1] = s10
Rob Pike4f61fc92010-09-04 10:36:13 +100095 mspa[s] = as
96 mipT[i] = apT[i]
97 mpTi[apT[i]] = i
98 mipM[i] = m
99 mit[i] = t
Russ Coxf2b5a072011-01-19 23:09:00 -0500100 // mti[t] = i
Rob Pike2738f422008-08-11 13:32:13 -0700101 }
102
103 // test len
104 if len(mib) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500105 panic(fmt.Sprintf("len(mib) = %d\n", len(mib)))
Rob Pike2738f422008-08-11 13:32:13 -0700106 }
107 if len(mii) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500108 panic(fmt.Sprintf("len(mii) = %d\n", len(mii)))
Rob Pike2738f422008-08-11 13:32:13 -0700109 }
110 if len(mfi) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500111 panic(fmt.Sprintf("len(mfi) = %d\n", len(mfi)))
Rob Pike2738f422008-08-11 13:32:13 -0700112 }
113 if len(mif) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500114 panic(fmt.Sprintf("len(mif) = %d\n", len(mif)))
Rob Pike2738f422008-08-11 13:32:13 -0700115 }
116 if len(msi) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500117 panic(fmt.Sprintf("len(msi) = %d\n", len(msi)))
Rob Pike2738f422008-08-11 13:32:13 -0700118 }
119 if len(mis) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500120 panic(fmt.Sprintf("len(mis) = %d\n", len(mis)))
Rob Pike2738f422008-08-11 13:32:13 -0700121 }
122 if len(mss) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500123 panic(fmt.Sprintf("len(mss) = %d\n", len(mss)))
Rob Pike2738f422008-08-11 13:32:13 -0700124 }
125 if len(mspa) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500126 panic(fmt.Sprintf("len(mspa) = %d\n", len(mspa)))
Rob Pike2738f422008-08-11 13:32:13 -0700127 }
128 if len(mipT) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500129 panic(fmt.Sprintf("len(mipT) = %d\n", len(mipT)))
Rob Pike2738f422008-08-11 13:32:13 -0700130 }
131 if len(mpTi) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500132 panic(fmt.Sprintf("len(mpTi) = %d\n", len(mpTi)))
Rob Pike2738f422008-08-11 13:32:13 -0700133 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500134 // if len(mti) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500135 // panic(fmt.Sprintf("len(mti) = %d\n", len(mti)))
Russ Coxf2b5a072011-01-19 23:09:00 -0500136 // }
Rob Pike2738f422008-08-11 13:32:13 -0700137 if len(mipM) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500138 panic(fmt.Sprintf("len(mipM) = %d\n", len(mipM)))
Rob Pike62b06fa2008-12-20 16:07:43 -0800139 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500140 // if len(mti) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500141 // panic(fmt.Sprintf("len(mti) = %d\n", len(mti)))
Russ Coxf2b5a072011-01-19 23:09:00 -0500142 // }
Rob Pike62b06fa2008-12-20 16:07:43 -0800143 if len(mit) != count {
Alan Donovan052c9422013-02-12 13:17:49 -0500144 panic(fmt.Sprintf("len(mit) = %d\n", len(mit)))
Rob Pike2738f422008-08-11 13:32:13 -0700145 }
Russ Cox08ca30b2008-12-19 03:05:37 -0800146
Rob Pike2738f422008-08-11 13:32:13 -0700147 // test construction directly
148 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000149 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500150 s10 := strconv.Itoa(i * 10)
151 f := float32(i)
Rob Pike4f61fc92010-09-04 10:36:13 +1000152 // BUG m := M(i, i+1)
Rob Pike2738f422008-08-11 13:32:13 -0700153 if mib[i] != (i != 0) {
Alan Donovan052c9422013-02-12 13:17:49 -0500154 panic(fmt.Sprintf("mib[%d] = %t\n", i, mib[i]))
Rob Pike2738f422008-08-11 13:32:13 -0700155 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500156 if mii[i] != 10*i {
Alan Donovan052c9422013-02-12 13:17:49 -0500157 panic(fmt.Sprintf("mii[%d] = %d\n", i, mii[i]))
Rob Pike2738f422008-08-11 13:32:13 -0700158 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500159 if mfi[f] != 10*i {
Alan Donovan052c9422013-02-12 13:17:49 -0500160 panic(fmt.Sprintf("mfi[%d] = %d\n", i, mfi[f]))
Rob Pike2738f422008-08-11 13:32:13 -0700161 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500162 if mif[i] != 10.0*f {
Alan Donovan052c9422013-02-12 13:17:49 -0500163 panic(fmt.Sprintf("mif[%d] = %g\n", i, mif[i]))
Rob Pike2738f422008-08-11 13:32:13 -0700164 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500165 if mis[i] != s {
Alan Donovan052c9422013-02-12 13:17:49 -0500166 panic(fmt.Sprintf("mis[%d] = %s\n", i, mis[i]))
Rob Pike2738f422008-08-11 13:32:13 -0700167 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500168 if msi[s] != i {
Alan Donovan052c9422013-02-12 13:17:49 -0500169 panic(fmt.Sprintf("msi[%s] = %d\n", s, msi[s]))
Rob Pike2738f422008-08-11 13:32:13 -0700170 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800171 if mss[s] != s10 {
Alan Donovan052c9422013-02-12 13:17:49 -0500172 panic(fmt.Sprintf("mss[%s] = %g\n", s, mss[s]))
Rob Pike2738f422008-08-11 13:32:13 -0700173 }
Russ Coxebd27d62009-10-09 11:18:32 -0700174 for j := 0; j < len(mspa[s]); j++ {
Rob Pike62b06fa2008-12-20 16:07:43 -0800175 if mspa[s][j] != s10 {
Alan Donovan052c9422013-02-12 13:17:49 -0500176 panic(fmt.Sprintf("mspa[%s][%d] = %s\n", s, j, mspa[s][j]))
Rob Pike2738f422008-08-11 13:32:13 -0700177 }
178 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500179 if mipT[i].i != int64(i) || mipT[i].f != f {
Alan Donovan052c9422013-02-12 13:17:49 -0500180 panic(fmt.Sprintf("mipT[%d] = %v\n", i, mipT[i]))
Rob Pike2738f422008-08-11 13:32:13 -0700181 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500182 if mpTi[apT[i]] != i {
Alan Donovan052c9422013-02-12 13:17:49 -0500183 panic(fmt.Sprintf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]]))
Rob Pike2738f422008-08-11 13:32:13 -0700184 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500185 // if(mti[t] != i) {
Alan Donovan052c9422013-02-12 13:17:49 -0500186 // panic(fmt.Sprintf("mti[%s] = %s\n", s, mti[t]))
Russ Coxf2b5a072011-01-19 23:09:00 -0500187 // }
188 if mipM[i][i] != i+1 {
Alan Donovan052c9422013-02-12 13:17:49 -0500189 panic(fmt.Sprintf("mipM[%d][%d] = %d\n", i, i, mipM[i][i]))
Rob Pike62b06fa2008-12-20 16:07:43 -0800190 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500191 // if(mti[t] != i) {
Alan Donovan052c9422013-02-12 13:17:49 -0500192 // panic(fmt.Sprintf("mti[%v] = %d\n", t, mti[t]))
Russ Coxf2b5a072011-01-19 23:09:00 -0500193 // }
194 if mit[i].i != int64(i) || mit[i].f != f {
Alan Donovan052c9422013-02-12 13:17:49 -0500195 panic(fmt.Sprintf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f))
Rob Pike2738f422008-08-11 13:32:13 -0700196 }
197 }
198
Rob Pike2738f422008-08-11 13:32:13 -0700199 // test existence with tuple check
200 // failed lookups yield a false value for the boolean.
201 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000202 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500203 f := float32(i)
Rob Pike2738f422008-08-11 13:32:13 -0700204 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000205 _, b := mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700206 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500207 panic(fmt.Sprintf("tuple existence decl: mib[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700208 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000209 _, b = mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700210 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500211 panic(fmt.Sprintf("tuple existence assign: mib[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700212 }
213 }
214 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000215 _, b := mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700216 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500217 panic(fmt.Sprintf("tuple existence decl: mii[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700218 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000219 _, b = mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700220 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500221 panic(fmt.Sprintf("tuple existence assign: mii[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700222 }
223 }
224 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000225 _, b := mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700226 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500227 panic(fmt.Sprintf("tuple existence decl: mfi[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700228 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000229 _, b = mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700230 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500231 panic(fmt.Sprintf("tuple existence assign: mfi[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700232 }
233 }
234 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000235 _, b := mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700236 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500237 panic(fmt.Sprintf("tuple existence decl: mif[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700238 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000239 _, b = mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700240 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500241 panic(fmt.Sprintf("tuple existence assign: mif[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700242 }
243 }
244 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000245 _, b := mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700246 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500247 panic(fmt.Sprintf("tuple existence decl: mis[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700248 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000249 _, b = mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700250 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500251 panic(fmt.Sprintf("tuple existence assign: mis[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700252 }
253 }
254 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000255 _, b := msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700256 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500257 panic(fmt.Sprintf("tuple existence decl: msi[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700258 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000259 _, b = msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700260 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500261 panic(fmt.Sprintf("tuple existence assign: msi[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700262 }
263 }
264 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000265 _, b := mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700266 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500267 panic(fmt.Sprintf("tuple existence decl: mss[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700268 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000269 _, b = mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700270 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500271 panic(fmt.Sprintf("tuple existence assign: mss[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700272 }
273 }
274 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000275 _, b := mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700276 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500277 panic(fmt.Sprintf("tuple existence decl: mspa[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700278 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000279 _, b = mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700280 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500281 panic(fmt.Sprintf("tuple existence assign: mspa[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700282 }
283 }
284 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000285 _, b := mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700286 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500287 panic(fmt.Sprintf("tuple existence decl: mipT[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700288 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000289 _, b = mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700290 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500291 panic(fmt.Sprintf("tuple existence assign: mipT[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700292 }
293 }
294 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000295 _, b := mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700296 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500297 panic(fmt.Sprintf("tuple existence decl: mpTi[apT[%d]]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700298 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000299 _, b = mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700300 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500301 panic(fmt.Sprintf("tuple existence assign: mpTi[apT[%d]]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700302 }
303 }
Rob Pike2738f422008-08-11 13:32:13 -0700304 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000305 _, b := mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700306 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500307 panic(fmt.Sprintf("tuple existence decl: mipM[%d]\n", i))
Rob Pike2738f422008-08-11 13:32:13 -0700308 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000309 _, b = mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700310 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500311 panic(fmt.Sprintf("tuple existence assign: mipM[%d]\n", i))
Rob Pike62b06fa2008-12-20 16:07:43 -0800312 }
313 }
314 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000315 _, b := mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800316 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500317 panic(fmt.Sprintf("tuple existence decl: mit[%d]\n", i))
Rob Pike62b06fa2008-12-20 16:07:43 -0800318 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000319 _, b = mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800320 if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500321 panic(fmt.Sprintf("tuple existence assign: mit[%d]\n", i))
Rob Pike62b06fa2008-12-20 16:07:43 -0800322 }
323 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500324 // {
325 // _, b := mti[t]
326 // if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500327 // panic(fmt.Sprintf("tuple existence decl: mti[%d]\n", i))
Russ Coxf2b5a072011-01-19 23:09:00 -0500328 // }
329 // _, b = mti[t]
330 // if !b {
Alan Donovan052c9422013-02-12 13:17:49 -0500331 // panic(fmt.Sprintf("tuple existence assign: mti[%d]\n", i))
Russ Coxf2b5a072011-01-19 23:09:00 -0500332 // }
333 // }
Rob Pike2738f422008-08-11 13:32:13 -0700334 }
335
336 // test nonexistence with tuple check
337 // failed lookups yield a false value for the boolean.
338 for i := count; i < 2*count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000339 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500340 f := float32(i)
Rob Pike2738f422008-08-11 13:32:13 -0700341 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000342 _, b := mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700343 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500344 panic(fmt.Sprintf("tuple nonexistence decl: mib[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700345 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000346 _, b = mib[i]
Rob Pike2738f422008-08-11 13:32:13 -0700347 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500348 panic(fmt.Sprintf("tuple nonexistence assign: mib[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700349 }
350 }
351 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000352 _, b := mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700353 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500354 panic(fmt.Sprintf("tuple nonexistence decl: mii[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700355 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000356 _, b = mii[i]
Rob Pike2738f422008-08-11 13:32:13 -0700357 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500358 panic(fmt.Sprintf("tuple nonexistence assign: mii[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700359 }
360 }
361 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000362 _, b := mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700363 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500364 panic(fmt.Sprintf("tuple nonexistence decl: mfi[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700365 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000366 _, b = mfi[f]
Rob Pike2738f422008-08-11 13:32:13 -0700367 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500368 panic(fmt.Sprintf("tuple nonexistence assign: mfi[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700369 }
370 }
371 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000372 _, b := mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700373 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500374 panic(fmt.Sprintf("tuple nonexistence decl: mif[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700375 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000376 _, b = mif[i]
Rob Pike2738f422008-08-11 13:32:13 -0700377 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500378 panic(fmt.Sprintf("tuple nonexistence assign: mif[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700379 }
380 }
381 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000382 _, b := mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700383 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500384 panic(fmt.Sprintf("tuple nonexistence decl: mis[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700385 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000386 _, b = mis[i]
Rob Pike2738f422008-08-11 13:32:13 -0700387 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500388 panic(fmt.Sprintf("tuple nonexistence assign: mis[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700389 }
390 }
391 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000392 _, b := msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700393 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500394 panic(fmt.Sprintf("tuple nonexistence decl: msi[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700395 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000396 _, b = msi[s]
Rob Pike2738f422008-08-11 13:32:13 -0700397 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500398 panic(fmt.Sprintf("tuple nonexistence assign: msi[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700399 }
400 }
401 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000402 _, b := mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700403 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500404 panic(fmt.Sprintf("tuple nonexistence decl: mss[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700405 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000406 _, b = mss[s]
Rob Pike2738f422008-08-11 13:32:13 -0700407 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500408 panic(fmt.Sprintf("tuple nonexistence assign: mss[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700409 }
410 }
411 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000412 _, b := mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700413 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500414 panic(fmt.Sprintf("tuple nonexistence decl: mspa[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700415 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000416 _, b = mspa[s]
Rob Pike2738f422008-08-11 13:32:13 -0700417 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500418 panic(fmt.Sprintf("tuple nonexistence assign: mspa[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700419 }
420 }
421 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000422 _, b := mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700423 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500424 panic(fmt.Sprintf("tuple nonexistence decl: mipT[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700425 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000426 _, b = mipT[i]
Rob Pike2738f422008-08-11 13:32:13 -0700427 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500428 panic(fmt.Sprintf("tuple nonexistence assign: mipT[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700429 }
430 }
431 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000432 _, b := mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700433 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500434 panic(fmt.Sprintf("tuple nonexistence decl: mpTi[apt[%d]]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700435 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000436 _, b = mpTi[apT[i]]
Rob Pike2738f422008-08-11 13:32:13 -0700437 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500438 panic(fmt.Sprintf("tuple nonexistence assign: mpTi[apT[%d]]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700439 }
440 }
Rob Pike2738f422008-08-11 13:32:13 -0700441 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000442 _, b := mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700443 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500444 panic(fmt.Sprintf("tuple nonexistence decl: mipM[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700445 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000446 _, b = mipM[i]
Rob Pike2738f422008-08-11 13:32:13 -0700447 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500448 panic(fmt.Sprintf("tuple nonexistence assign: mipM[%d]", i))
Rob Pike62b06fa2008-12-20 16:07:43 -0800449 }
450 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500451 // {
452 // _, b := mti[t]
453 // if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500454 // panic(fmt.Sprintf("tuple nonexistence decl: mti[%d]", i))
Russ Coxf2b5a072011-01-19 23:09:00 -0500455 // }
456 // _, b = mti[t]
457 // if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500458 // panic(fmt.Sprintf("tuple nonexistence assign: mti[%d]", i))
Russ Coxf2b5a072011-01-19 23:09:00 -0500459 // }
460 // }
Rob Pike62b06fa2008-12-20 16:07:43 -0800461 {
Rob Pike4f61fc92010-09-04 10:36:13 +1000462 _, b := mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800463 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500464 panic(fmt.Sprintf("tuple nonexistence decl: mit[%d]", i))
Rob Pike62b06fa2008-12-20 16:07:43 -0800465 }
Rob Pike4f61fc92010-09-04 10:36:13 +1000466 _, b = mit[i]
Rob Pike62b06fa2008-12-20 16:07:43 -0800467 if b {
Alan Donovan052c9422013-02-12 13:17:49 -0500468 panic(fmt.Sprintf("tuple nonexistence assign: mit[%d]", i))
Rob Pike2738f422008-08-11 13:32:13 -0700469 }
470 }
471 }
Russ Cox08ca30b2008-12-19 03:05:37 -0800472
Rob Pike2738f422008-08-11 13:32:13 -0700473 // tests for structured map element updates
474 for i := 0; i < count; i++ {
Rob Pike4f61fc92010-09-04 10:36:13 +1000475 s := strconv.Itoa(i)
Russ Coxf2b5a072011-01-19 23:09:00 -0500476 mspa[s][i%2] = "deleted"
477 if mspa[s][i%2] != "deleted" {
Alan Donovan052c9422013-02-12 13:17:49 -0500478 panic(fmt.Sprintf("update mspa[%s][%d] = %s\n", s, i%2, mspa[s][i%2]))
479
Rob Pike2738f422008-08-11 13:32:13 -0700480 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800481
Rob Pike4f61fc92010-09-04 10:36:13 +1000482 mipT[i].i += 1
Rob Pike62b06fa2008-12-20 16:07:43 -0800483 if mipT[i].i != int64(i)+1 {
Alan Donovan052c9422013-02-12 13:17:49 -0500484 panic(fmt.Sprintf("update mipT[%d].i = %d\n", i, mipT[i].i))
485
Rob Pike2738f422008-08-11 13:32:13 -0700486 }
Russ Coxf2b5a072011-01-19 23:09:00 -0500487 mipT[i].f = float32(i + 1)
488 if mipT[i].f != float32(i+1) {
Alan Donovan052c9422013-02-12 13:17:49 -0500489 panic(fmt.Sprintf("update mipT[%d].f = %g\n", i, mipT[i].f))
490
Rob Pike2738f422008-08-11 13:32:13 -0700491 }
Rob Pike62b06fa2008-12-20 16:07:43 -0800492
Rob Pike4f61fc92010-09-04 10:36:13 +1000493 mipM[i][i]++
Russ Coxf2b5a072011-01-19 23:09:00 -0500494 if mipM[i][i] != (i+1)+1 {
Alan Donovan052c9422013-02-12 13:17:49 -0500495 panic(fmt.Sprintf("update mipM[%d][%d] = %d\n", i, i, mipM[i][i]))
496
Rob Pike2738f422008-08-11 13:32:13 -0700497 }
498 }
Russ Coxae54cf72009-09-15 12:42:24 -0700499
Russ Cox86145612009-03-23 18:32:37 -0700500 // test range on nil map
Russ Coxf2b5a072011-01-19 23:09:00 -0500501 var mnil map[string]int
Russ Coxae54cf72009-09-15 12:42:24 -0700502 for _, _ = range mnil {
Rob Pike4f61fc92010-09-04 10:36:13 +1000503 panic("range mnil")
Russ Cox86145612009-03-23 18:32:37 -0700504 }
Russ Cox408f0b12012-01-26 16:25:07 -0500505}
506
507func testfloat() {
508 // Test floating point numbers in maps.
509 // Two map keys refer to the same entry if the keys are ==.
510 // The special cases, then, are that +0 == -0 and that NaN != NaN.
511
512 {
513 var (
514 pz = float32(0)
515 nz = math.Float32frombits(1 << 31)
516 nana = float32(math.NaN())
517 nanb = math.Float32frombits(math.Float32bits(nana) ^ 2)
518 )
519
520 m := map[float32]string{
521 pz: "+0",
522 nana: "NaN",
523 nanb: "NaN",
524 }
525 if m[pz] != "+0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500526 panic(fmt.Sprintln("float32 map cannot read back m[+0]:", m[pz]))
Russ Cox408f0b12012-01-26 16:25:07 -0500527 }
528 if m[nz] != "+0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500529 fmt.Sprintln("float32 map does not treat", pz, "and", nz, "as equal for read")
530 panic(fmt.Sprintln("float32 map does not treat -0 and +0 as equal for read"))
Russ Cox408f0b12012-01-26 16:25:07 -0500531 }
532 m[nz] = "-0"
533 if m[pz] != "-0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500534 panic(fmt.Sprintln("float32 map does not treat -0 and +0 as equal for write"))
Russ Cox408f0b12012-01-26 16:25:07 -0500535 }
536 if _, ok := m[nana]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500537 panic(fmt.Sprintln("float32 map allows NaN lookup (a)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500538 }
539 if _, ok := m[nanb]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500540 panic(fmt.Sprintln("float32 map allows NaN lookup (b)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500541 }
542 if len(m) != 3 {
Alan Donovan052c9422013-02-12 13:17:49 -0500543 panic(fmt.Sprintln("float32 map should have 3 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500544 }
545 m[nana] = "NaN"
546 m[nanb] = "NaN"
547 if len(m) != 5 {
Alan Donovan052c9422013-02-12 13:17:49 -0500548 panic(fmt.Sprintln("float32 map should have 5 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500549 }
550 }
551
552 {
553 var (
554 pz = float64(0)
555 nz = math.Float64frombits(1 << 63)
556 nana = float64(math.NaN())
557 nanb = math.Float64frombits(math.Float64bits(nana) ^ 2)
558 )
559
560 m := map[float64]string{
561 pz: "+0",
562 nana: "NaN",
563 nanb: "NaN",
564 }
565 if m[nz] != "+0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500566 panic(fmt.Sprintln("float64 map does not treat -0 and +0 as equal for read"))
Russ Cox408f0b12012-01-26 16:25:07 -0500567 }
568 m[nz] = "-0"
569 if m[pz] != "-0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500570 panic(fmt.Sprintln("float64 map does not treat -0 and +0 as equal for write"))
Russ Cox408f0b12012-01-26 16:25:07 -0500571 }
572 if _, ok := m[nana]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500573 panic(fmt.Sprintln("float64 map allows NaN lookup (a)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500574 }
575 if _, ok := m[nanb]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500576 panic(fmt.Sprintln("float64 map allows NaN lookup (b)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500577 }
578 if len(m) != 3 {
Alan Donovan052c9422013-02-12 13:17:49 -0500579 panic(fmt.Sprintln("float64 map should have 3 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500580 }
581 m[nana] = "NaN"
582 m[nanb] = "NaN"
583 if len(m) != 5 {
Alan Donovan052c9422013-02-12 13:17:49 -0500584 panic(fmt.Sprintln("float64 map should have 5 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500585 }
586 }
587
588 {
589 var (
590 pz = complex64(0)
591 nz = complex(0, math.Float32frombits(1<<31))
592 nana = complex(5, float32(math.NaN()))
593 nanb = complex(5, math.Float32frombits(math.Float32bits(float32(math.NaN()))^2))
594 )
595
596 m := map[complex64]string{
597 pz: "+0",
598 nana: "NaN",
599 nanb: "NaN",
600 }
601 if m[nz] != "+0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500602 panic(fmt.Sprintln("complex64 map does not treat -0 and +0 as equal for read"))
Russ Cox408f0b12012-01-26 16:25:07 -0500603 }
604 m[nz] = "-0"
605 if m[pz] != "-0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500606 panic(fmt.Sprintln("complex64 map does not treat -0 and +0 as equal for write"))
Russ Cox408f0b12012-01-26 16:25:07 -0500607 }
608 if _, ok := m[nana]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500609 panic(fmt.Sprintln("complex64 map allows NaN lookup (a)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500610 }
611 if _, ok := m[nanb]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500612 panic(fmt.Sprintln("complex64 map allows NaN lookup (b)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500613 }
614 if len(m) != 3 {
Alan Donovan052c9422013-02-12 13:17:49 -0500615 panic(fmt.Sprintln("complex64 map should have 3 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500616 }
617 m[nana] = "NaN"
618 m[nanb] = "NaN"
619 if len(m) != 5 {
Alan Donovan052c9422013-02-12 13:17:49 -0500620 panic(fmt.Sprintln("complex64 map should have 5 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500621 }
622 }
623
624 {
625 var (
626 pz = complex128(0)
627 nz = complex(0, math.Float64frombits(1<<63))
628 nana = complex(5, float64(math.NaN()))
629 nanb = complex(5, math.Float64frombits(math.Float64bits(float64(math.NaN()))^2))
630 )
631
632 m := map[complex128]string{
633 pz: "+0",
634 nana: "NaN",
635 nanb: "NaN",
636 }
637 if m[nz] != "+0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500638 panic(fmt.Sprintln("complex128 map does not treat -0 and +0 as equal for read"))
Russ Cox408f0b12012-01-26 16:25:07 -0500639 }
640 m[nz] = "-0"
641 if m[pz] != "-0" {
Alan Donovan052c9422013-02-12 13:17:49 -0500642 panic(fmt.Sprintln("complex128 map does not treat -0 and +0 as equal for write"))
Russ Cox408f0b12012-01-26 16:25:07 -0500643 }
644 if _, ok := m[nana]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500645 panic(fmt.Sprintln("complex128 map allows NaN lookup (a)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500646 }
647 if _, ok := m[nanb]; ok {
Alan Donovan052c9422013-02-12 13:17:49 -0500648 panic(fmt.Sprintln("complex128 map allows NaN lookup (b)"))
Russ Cox408f0b12012-01-26 16:25:07 -0500649 }
650 if len(m) != 3 {
Alan Donovan052c9422013-02-12 13:17:49 -0500651 panic(fmt.Sprintln("complex128 map should have 3 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500652 }
653 m[nana] = "NaN"
654 m[nanb] = "NaN"
655 if len(m) != 5 {
Alan Donovan052c9422013-02-12 13:17:49 -0500656 panic(fmt.Sprintln("complex128 map should have 5 entries:", m))
Russ Cox408f0b12012-01-26 16:25:07 -0500657 }
658 }
Rob Pike2738f422008-08-11 13:32:13 -0700659}
Russ Cox6ebf8a62012-01-30 13:41:38 -0500660
661func testnan() {
Brad Fitzpatrick5e21cb72013-04-07 11:56:15 -0700662 n := 500
663 m := map[float64]int{}
664 nan := math.NaN()
665 for i := 0; i < n; i++ {
666 m[nan] = 1
Russ Cox6ebf8a62012-01-30 13:41:38 -0500667 }
Brad Fitzpatrick5e21cb72013-04-07 11:56:15 -0700668 if len(m) != n {
669 panic("wrong size map after nan insertion")
670 }
671 iters := 0
672 for k, v := range m {
673 iters++
674 if !math.IsNaN(k) {
675 panic("not NaN")
Brad Fitzpatrick69a5b232012-02-02 11:49:28 -0800676 }
Brad Fitzpatrick5e21cb72013-04-07 11:56:15 -0700677 if v != 1 {
678 panic("wrong value")
Brad Fitzpatrick69a5b232012-02-02 11:49:28 -0800679 }
Brad Fitzpatrick5e21cb72013-04-07 11:56:15 -0700680 }
681 if iters != n {
682 panic("wrong number of nan range iters")
Russ Cox6ebf8a62012-01-30 13:41:38 -0500683 }
684}