409
409
t.Fatalf("missing value")
413
func TestMapIterOrder(t *testing.T) {
414
for _, n := range [...]int{3, 7, 9, 15} {
415
// Make m be {0: true, 1: true, ..., n-1: true}.
416
m := make(map[int]bool)
417
for i := 0; i < n; i++ {
420
// Check that iterating over the map produces at least two different orderings.
421
ord := func() []int {
430
for try := 0; try < 100; try++ {
431
if !reflect.DeepEqual(first, ord()) {
437
t.Errorf("Map with n=%d elements had consistent iteration order: %v", n, first)
442
func TestMapStringBytesLookup(t *testing.T) {
443
// Use large string keys to avoid small-allocation coalescing,
444
// which can cause AllocsPerRun to report lower counts than it should.
446
"1000000000000000000000000000000000000000000000000": 1,
447
"2000000000000000000000000000000000000000000000000": 2,
449
buf := []byte("1000000000000000000000000000000000000000000000000")
450
if x := m[string(buf)]; x != 1 {
451
t.Errorf(`m[string([]byte("1"))] = %d, want 1`, x)
454
if x := m[string(buf)]; x != 2 {
455
t.Errorf(`m[string([]byte("2"))] = %d, want 2`, x)
459
n := testing.AllocsPerRun(100, func() {
463
t.Errorf("AllocsPerRun for m[string(buf)] = %v, want 0", n)
467
n = testing.AllocsPerRun(100, func() {
468
y, ok := m[string(buf)]
475
t.Errorf("AllocsPerRun for x,ok = m[string(buf)] = %v, want 0", n)