diff options
Diffstat (limited to 'libgo/go/runtime/map_test.go')
-rw-r--r-- | libgo/go/runtime/map_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libgo/go/runtime/map_test.go b/libgo/go/runtime/map_test.go index c53066aea6a..3d18e3be82c 100644 --- a/libgo/go/runtime/map_test.go +++ b/libgo/go/runtime/map_test.go @@ -416,3 +416,37 @@ func TestMapNanGrowIterator(t *testing.T) { t.Fatalf("missing value") } } + +func TestMapIterOrder(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("skipping for gccgo") + } + + // TODO: For issue 6719, add 3 and 7 to this list. + for _, n := range [...]int{9, 15} { + // Make m be {0: true, 1: true, ..., n-1: true}. + m := make(map[int]bool) + for i := 0; i < n; i++ { + m[i] = true + } + // Check that iterating over the map produces at least two different orderings. + ord := func() []int { + var s []int + for key := range m { + s = append(s, key) + } + return s + } + first := ord() + ok := false + for try := 0; try < 100; try++ { + if !reflect.DeepEqual(first, ord()) { + ok = true + break + } + } + if !ok { + t.Errorf("Map with n=%d elements had consistent iteration order: %v", n, first) + } + } +} |