Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 1 | // $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 | |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 7 | package main |
| 8 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 9 | import "rand" |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 10 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 11 | const Count = 1e5 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 12 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 13 | func i64rand() int64 { |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 14 | for { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 15 | a := int64(rand.Uint32()) |
| 16 | a = (a << 32) | int64(rand.Uint32()) |
| 17 | a >>= uint(rand.Intn(64)) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 18 | if -a != a { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 19 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 20 | } |
| 21 | } |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 22 | return 0 // impossible |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 25 | func i64test(a, b, c int64) { |
| 26 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 27 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 28 | println("i64", a, b, c, d) |
| 29 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 33 | func i64run() { |
| 34 | var a, b int64 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 35 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 36 | for i := 0; i < Count; i++ { |
| 37 | a = i64rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 38 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 39 | b = a % 1 |
| 40 | i64test(a, b, 1) |
| 41 | b = a % 2 |
| 42 | i64test(a, b, 2) |
| 43 | b = a % 3 |
| 44 | i64test(a, b, 3) |
| 45 | b = a % 4 |
| 46 | i64test(a, b, 4) |
| 47 | b = a % 5 |
| 48 | i64test(a, b, 5) |
| 49 | b = a % 6 |
| 50 | i64test(a, b, 6) |
| 51 | b = a % 7 |
| 52 | i64test(a, b, 7) |
| 53 | b = a % 8 |
| 54 | i64test(a, b, 8) |
| 55 | b = a % 10 |
| 56 | i64test(a, b, 10) |
| 57 | b = a % 16 |
| 58 | i64test(a, b, 16) |
| 59 | b = a % 20 |
| 60 | i64test(a, b, 20) |
| 61 | b = a % 32 |
| 62 | i64test(a, b, 32) |
| 63 | b = a % 60 |
| 64 | i64test(a, b, 60) |
| 65 | b = a % 64 |
| 66 | i64test(a, b, 64) |
| 67 | b = a % 128 |
| 68 | i64test(a, b, 128) |
| 69 | b = a % 256 |
| 70 | i64test(a, b, 256) |
| 71 | b = a % 16384 |
| 72 | i64test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 73 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 74 | b = a % -1 |
| 75 | i64test(a, b, -1) |
| 76 | b = a % -2 |
| 77 | i64test(a, b, -2) |
| 78 | b = a % -3 |
| 79 | i64test(a, b, -3) |
| 80 | b = a % -4 |
| 81 | i64test(a, b, -4) |
| 82 | b = a % -5 |
| 83 | i64test(a, b, -5) |
| 84 | b = a % -6 |
| 85 | i64test(a, b, -6) |
| 86 | b = a % -7 |
| 87 | i64test(a, b, -7) |
| 88 | b = a % -8 |
| 89 | i64test(a, b, -8) |
| 90 | b = a % -10 |
| 91 | i64test(a, b, -10) |
| 92 | b = a % -16 |
| 93 | i64test(a, b, -16) |
| 94 | b = a % -20 |
| 95 | i64test(a, b, -20) |
| 96 | b = a % -32 |
| 97 | i64test(a, b, -32) |
| 98 | b = a % -60 |
| 99 | i64test(a, b, -60) |
| 100 | b = a % -64 |
| 101 | i64test(a, b, -64) |
| 102 | b = a % -128 |
| 103 | i64test(a, b, -128) |
| 104 | b = a % -256 |
| 105 | i64test(a, b, -256) |
| 106 | b = a % -16384 |
| 107 | i64test(a, b, -16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 111 | func u64rand() uint64 { |
| 112 | a := uint64(rand.Uint32()) |
| 113 | a = (a << 32) | uint64(rand.Uint32()) |
| 114 | a >>= uint(rand.Intn(64)) |
| 115 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 118 | func u64test(a, b, c uint64) { |
| 119 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 120 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 121 | println("u64", a, b, c, d) |
| 122 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 126 | func u64run() { |
| 127 | var a, b uint64 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 128 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 129 | for i := 0; i < Count; i++ { |
| 130 | a = u64rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 131 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 132 | b = a % 1 |
| 133 | u64test(a, b, 1) |
| 134 | b = a % 2 |
| 135 | u64test(a, b, 2) |
| 136 | b = a % 3 |
| 137 | u64test(a, b, 3) |
| 138 | b = a % 4 |
| 139 | u64test(a, b, 4) |
| 140 | b = a % 5 |
| 141 | u64test(a, b, 5) |
| 142 | b = a % 6 |
| 143 | u64test(a, b, 6) |
| 144 | b = a % 7 |
| 145 | u64test(a, b, 7) |
| 146 | b = a % 8 |
| 147 | u64test(a, b, 8) |
| 148 | b = a % 10 |
| 149 | u64test(a, b, 10) |
| 150 | b = a % 16 |
| 151 | u64test(a, b, 16) |
| 152 | b = a % 20 |
| 153 | u64test(a, b, 20) |
| 154 | b = a % 32 |
| 155 | u64test(a, b, 32) |
| 156 | b = a % 60 |
| 157 | u64test(a, b, 60) |
| 158 | b = a % 64 |
| 159 | u64test(a, b, 64) |
| 160 | b = a % 128 |
| 161 | u64test(a, b, 128) |
| 162 | b = a % 256 |
| 163 | u64test(a, b, 256) |
| 164 | b = a % 16384 |
| 165 | u64test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 169 | func i32rand() int32 { |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 170 | for { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 171 | a := int32(rand.Uint32()) |
| 172 | a >>= uint(rand.Intn(32)) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 173 | if -a != a { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 174 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 177 | return 0 // impossible |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 180 | func i32test(a, b, c int32) { |
| 181 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 182 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 183 | println("i32", a, b, c, d) |
| 184 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 188 | func i32run() { |
| 189 | var a, b int32 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 190 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 191 | for i := 0; i < Count; i++ { |
| 192 | a = i32rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 193 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 194 | b = a % 1 |
| 195 | i32test(a, b, 1) |
| 196 | b = a % 2 |
| 197 | i32test(a, b, 2) |
| 198 | b = a % 3 |
| 199 | i32test(a, b, 3) |
| 200 | b = a % 4 |
| 201 | i32test(a, b, 4) |
| 202 | b = a % 5 |
| 203 | i32test(a, b, 5) |
| 204 | b = a % 6 |
| 205 | i32test(a, b, 6) |
| 206 | b = a % 7 |
| 207 | i32test(a, b, 7) |
| 208 | b = a % 8 |
| 209 | i32test(a, b, 8) |
| 210 | b = a % 10 |
| 211 | i32test(a, b, 10) |
| 212 | b = a % 16 |
| 213 | i32test(a, b, 16) |
| 214 | b = a % 20 |
| 215 | i32test(a, b, 20) |
| 216 | b = a % 32 |
| 217 | i32test(a, b, 32) |
| 218 | b = a % 60 |
| 219 | i32test(a, b, 60) |
| 220 | b = a % 64 |
| 221 | i32test(a, b, 64) |
| 222 | b = a % 128 |
| 223 | i32test(a, b, 128) |
| 224 | b = a % 256 |
| 225 | i32test(a, b, 256) |
| 226 | b = a % 16384 |
| 227 | i32test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 228 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 229 | b = a % -1 |
| 230 | i32test(a, b, -1) |
| 231 | b = a % -2 |
| 232 | i32test(a, b, -2) |
| 233 | b = a % -3 |
| 234 | i32test(a, b, -3) |
| 235 | b = a % -4 |
| 236 | i32test(a, b, -4) |
| 237 | b = a % -5 |
| 238 | i32test(a, b, -5) |
| 239 | b = a % -6 |
| 240 | i32test(a, b, -6) |
| 241 | b = a % -7 |
| 242 | i32test(a, b, -7) |
| 243 | b = a % -8 |
| 244 | i32test(a, b, -8) |
| 245 | b = a % -10 |
| 246 | i32test(a, b, -10) |
| 247 | b = a % -16 |
| 248 | i32test(a, b, -16) |
| 249 | b = a % -20 |
| 250 | i32test(a, b, -20) |
| 251 | b = a % -32 |
| 252 | i32test(a, b, -32) |
| 253 | b = a % -60 |
| 254 | i32test(a, b, -60) |
| 255 | b = a % -64 |
| 256 | i32test(a, b, -64) |
| 257 | b = a % -128 |
| 258 | i32test(a, b, -128) |
| 259 | b = a % -256 |
| 260 | i32test(a, b, -256) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 264 | func u32rand() uint32 { |
| 265 | a := uint32(rand.Uint32()) |
| 266 | a >>= uint(rand.Intn(32)) |
| 267 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 270 | func u32test(a, b, c uint32) { |
| 271 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 272 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 273 | println("u32", a, b, c, d) |
| 274 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 278 | func u32run() { |
| 279 | var a, b uint32 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 280 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 281 | for i := 0; i < Count; i++ { |
| 282 | a = u32rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 283 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 284 | b = a % 1 |
| 285 | u32test(a, b, 1) |
| 286 | b = a % 2 |
| 287 | u32test(a, b, 2) |
| 288 | b = a % 3 |
| 289 | u32test(a, b, 3) |
| 290 | b = a % 4 |
| 291 | u32test(a, b, 4) |
| 292 | b = a % 5 |
| 293 | u32test(a, b, 5) |
| 294 | b = a % 6 |
| 295 | u32test(a, b, 6) |
| 296 | b = a % 7 |
| 297 | u32test(a, b, 7) |
| 298 | b = a % 8 |
| 299 | u32test(a, b, 8) |
| 300 | b = a % 10 |
| 301 | u32test(a, b, 10) |
| 302 | b = a % 16 |
| 303 | u32test(a, b, 16) |
| 304 | b = a % 20 |
| 305 | u32test(a, b, 20) |
| 306 | b = a % 32 |
| 307 | u32test(a, b, 32) |
| 308 | b = a % 60 |
| 309 | u32test(a, b, 60) |
| 310 | b = a % 64 |
| 311 | u32test(a, b, 64) |
| 312 | b = a % 128 |
| 313 | u32test(a, b, 128) |
| 314 | b = a % 256 |
| 315 | u32test(a, b, 256) |
| 316 | b = a % 16384 |
| 317 | u32test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 321 | func i16rand() int16 { |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 322 | for { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 323 | a := int16(rand.Uint32()) |
| 324 | a >>= uint(rand.Intn(16)) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 325 | if -a != a { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 326 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 327 | } |
| 328 | } |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 329 | return 0 // impossible |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 332 | func i16test(a, b, c int16) { |
| 333 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 334 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 335 | println("i16", a, b, c, d) |
| 336 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 340 | func i16run() { |
| 341 | var a, b int16 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 342 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 343 | for i := 0; i < Count; i++ { |
| 344 | a = i16rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 345 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 346 | b = a % 1 |
| 347 | i16test(a, b, 1) |
| 348 | b = a % 2 |
| 349 | i16test(a, b, 2) |
| 350 | b = a % 3 |
| 351 | i16test(a, b, 3) |
| 352 | b = a % 4 |
| 353 | i16test(a, b, 4) |
| 354 | b = a % 5 |
| 355 | i16test(a, b, 5) |
| 356 | b = a % 6 |
| 357 | i16test(a, b, 6) |
| 358 | b = a % 7 |
| 359 | i16test(a, b, 7) |
| 360 | b = a % 8 |
| 361 | i16test(a, b, 8) |
| 362 | b = a % 10 |
| 363 | i16test(a, b, 10) |
| 364 | b = a % 16 |
| 365 | i16test(a, b, 16) |
| 366 | b = a % 20 |
| 367 | i16test(a, b, 20) |
| 368 | b = a % 32 |
| 369 | i16test(a, b, 32) |
| 370 | b = a % 60 |
| 371 | i16test(a, b, 60) |
| 372 | b = a % 64 |
| 373 | i16test(a, b, 64) |
| 374 | b = a % 128 |
| 375 | i16test(a, b, 128) |
| 376 | b = a % 256 |
| 377 | i16test(a, b, 256) |
| 378 | b = a % 16384 |
| 379 | i16test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 380 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 381 | b = a % -1 |
| 382 | i16test(a, b, -1) |
| 383 | b = a % -2 |
| 384 | i16test(a, b, -2) |
| 385 | b = a % -3 |
| 386 | i16test(a, b, -3) |
| 387 | b = a % -4 |
| 388 | i16test(a, b, -4) |
| 389 | b = a % -5 |
| 390 | i16test(a, b, -5) |
| 391 | b = a % -6 |
| 392 | i16test(a, b, -6) |
| 393 | b = a % -7 |
| 394 | i16test(a, b, -7) |
| 395 | b = a % -8 |
| 396 | i16test(a, b, -8) |
| 397 | b = a % -10 |
| 398 | i16test(a, b, -10) |
| 399 | b = a % -16 |
| 400 | i16test(a, b, -16) |
| 401 | b = a % -20 |
| 402 | i16test(a, b, -20) |
| 403 | b = a % -32 |
| 404 | i16test(a, b, -32) |
| 405 | b = a % -60 |
| 406 | i16test(a, b, -60) |
| 407 | b = a % -64 |
| 408 | i16test(a, b, -64) |
| 409 | b = a % -128 |
| 410 | i16test(a, b, -128) |
| 411 | b = a % -256 |
| 412 | i16test(a, b, -256) |
| 413 | b = a % -16384 |
| 414 | i16test(a, b, -16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 418 | func u16rand() uint16 { |
| 419 | a := uint16(rand.Uint32()) |
| 420 | a >>= uint(rand.Intn(16)) |
| 421 | return a |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 424 | func u16test(a, b, c uint16) { |
| 425 | d := a % c |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 426 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 427 | println("u16", a, b, c, d) |
| 428 | panic("fail") |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 432 | func u16run() { |
| 433 | var a, b uint16 |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 434 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 435 | for i := 0; i < Count; i++ { |
| 436 | a = u16rand() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 437 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 438 | b = a % 1 |
| 439 | u16test(a, b, 1) |
| 440 | b = a % 2 |
| 441 | u16test(a, b, 2) |
| 442 | b = a % 3 |
| 443 | u16test(a, b, 3) |
| 444 | b = a % 4 |
| 445 | u16test(a, b, 4) |
| 446 | b = a % 5 |
| 447 | u16test(a, b, 5) |
| 448 | b = a % 6 |
| 449 | u16test(a, b, 6) |
| 450 | b = a % 7 |
| 451 | u16test(a, b, 7) |
| 452 | b = a % 8 |
| 453 | u16test(a, b, 8) |
| 454 | b = a % 10 |
| 455 | u16test(a, b, 10) |
| 456 | b = a % 16 |
| 457 | u16test(a, b, 16) |
| 458 | b = a % 20 |
| 459 | u16test(a, b, 20) |
| 460 | b = a % 32 |
| 461 | u16test(a, b, 32) |
| 462 | b = a % 60 |
| 463 | u16test(a, b, 60) |
| 464 | b = a % 64 |
| 465 | u16test(a, b, 64) |
| 466 | b = a % 128 |
| 467 | u16test(a, b, 128) |
| 468 | b = a % 256 |
| 469 | u16test(a, b, 256) |
| 470 | b = a % 16384 |
| 471 | u16test(a, b, 16384) |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 475 | func i8rand() int8 { |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 476 | for { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 477 | a := int8(rand.Uint32()) |
| 478 | a >>= uint(rand.Intn(8)) |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 479 | if -a != a { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 480 | return a |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 483 | return 0 // impossible |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 486 | func i8test(a, b, c int8) { |
| 487 | d := a % c |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 488 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 489 | println("i8", a, b, c, d) |
| 490 | panic("fail") |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 494 | func i8run() { |
| 495 | var a, b int8 |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 496 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 497 | for i := 0; i < Count; i++ { |
| 498 | a = i8rand() |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 499 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 500 | b = a % 1 |
| 501 | i8test(a, b, 1) |
| 502 | b = a % 2 |
| 503 | i8test(a, b, 2) |
| 504 | b = a % 3 |
| 505 | i8test(a, b, 3) |
| 506 | b = a % 4 |
| 507 | i8test(a, b, 4) |
| 508 | b = a % 5 |
| 509 | i8test(a, b, 5) |
| 510 | b = a % 6 |
| 511 | i8test(a, b, 6) |
| 512 | b = a % 7 |
| 513 | i8test(a, b, 7) |
| 514 | b = a % 8 |
| 515 | i8test(a, b, 8) |
| 516 | b = a % 10 |
| 517 | i8test(a, b, 10) |
| 518 | b = a % 8 |
| 519 | i8test(a, b, 8) |
| 520 | b = a % 20 |
| 521 | i8test(a, b, 20) |
| 522 | b = a % 32 |
| 523 | i8test(a, b, 32) |
| 524 | b = a % 60 |
| 525 | i8test(a, b, 60) |
| 526 | b = a % 64 |
| 527 | i8test(a, b, 64) |
| 528 | b = a % 127 |
| 529 | i8test(a, b, 127) |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 530 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 531 | b = a % -1 |
| 532 | i8test(a, b, -1) |
| 533 | b = a % -2 |
| 534 | i8test(a, b, -2) |
| 535 | b = a % -3 |
| 536 | i8test(a, b, -3) |
| 537 | b = a % -4 |
| 538 | i8test(a, b, -4) |
| 539 | b = a % -5 |
| 540 | i8test(a, b, -5) |
| 541 | b = a % -6 |
| 542 | i8test(a, b, -6) |
| 543 | b = a % -7 |
| 544 | i8test(a, b, -7) |
| 545 | b = a % -8 |
| 546 | i8test(a, b, -8) |
| 547 | b = a % -10 |
| 548 | i8test(a, b, -10) |
| 549 | b = a % -8 |
| 550 | i8test(a, b, -8) |
| 551 | b = a % -20 |
| 552 | i8test(a, b, -20) |
| 553 | b = a % -32 |
| 554 | i8test(a, b, -32) |
| 555 | b = a % -60 |
| 556 | i8test(a, b, -60) |
| 557 | b = a % -64 |
| 558 | i8test(a, b, -64) |
| 559 | b = a % -128 |
| 560 | i8test(a, b, -128) |
| 561 | b = a % -101 |
| 562 | i8test(a, b, -101) |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 566 | func u8rand() uint8 { |
| 567 | a := uint8(rand.Uint32()) |
| 568 | a >>= uint(rand.Intn(8)) |
| 569 | return a |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 572 | func u8test(a, b, c uint8) { |
| 573 | d := a % c |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 574 | if d != b { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 575 | println("u8", a, b, c, d) |
| 576 | panic("fail") |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 580 | func u8run() { |
| 581 | var a, b uint8 |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 582 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 583 | for i := 0; i < Count; i++ { |
| 584 | a = u8rand() |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 585 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 586 | b = a % 1 |
| 587 | u8test(a, b, 1) |
| 588 | b = a % 2 |
| 589 | u8test(a, b, 2) |
| 590 | b = a % 3 |
| 591 | u8test(a, b, 3) |
| 592 | b = a % 4 |
| 593 | u8test(a, b, 4) |
| 594 | b = a % 5 |
| 595 | u8test(a, b, 5) |
| 596 | b = a % 6 |
| 597 | u8test(a, b, 6) |
| 598 | b = a % 7 |
| 599 | u8test(a, b, 7) |
| 600 | b = a % 8 |
| 601 | u8test(a, b, 8) |
| 602 | b = a % 10 |
| 603 | u8test(a, b, 10) |
| 604 | b = a % 8 |
| 605 | u8test(a, b, 8) |
| 606 | b = a % 20 |
| 607 | u8test(a, b, 20) |
| 608 | b = a % 32 |
| 609 | u8test(a, b, 32) |
| 610 | b = a % 60 |
| 611 | u8test(a, b, 60) |
| 612 | b = a % 64 |
| 613 | u8test(a, b, 64) |
| 614 | b = a % 127 |
| 615 | u8test(a, b, 127) |
Russ Cox | 3f91f80 | 2009-08-10 12:46:23 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 619 | func main() { |
| 620 | xtest() |
| 621 | i64run() |
| 622 | u64run() |
| 623 | i32run() |
| 624 | u32run() |
| 625 | i16run() |
| 626 | u16run() |
| 627 | i8run() |
| 628 | u8run() |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 631 | func xtest() { |
Ken Thompson | 812f06b | 2009-08-08 16:53:21 -0700 | [diff] [blame] | 632 | } |