diff options
author | Damian Gryski <[email protected]> | 2022-03-14 11:51:44 -0700 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-04-28 09:14:45 +0200 |
commit | 050d516264066d193b4269ff0b0a21e8597abd9e (patch) | |
tree | 73d646943951305eebb3d43304c6c00ca95a672f | |
parent | 9a8328fcb76314240d2632bd0deaa17d33170e45 (diff) | |
download | tinygo-050d516264066d193b4269ff0b0a21e8597abd9e.tar.gz tinygo-050d516264066d193b4269ff0b0a21e8597abd9e.zip |
testdata: add test for mapgrowth logic
-rw-r--r-- | main_test.go | 1 | ||||
-rw-r--r-- | testdata/mapgrowth.go | 66 | ||||
-rw-r--r-- | testdata/mapgrowth.txt | 1 |
3 files changed, 68 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go index 3b088ada8..01835a2c6 100644 --- a/main_test.go +++ b/main_test.go @@ -57,6 +57,7 @@ func TestBuild(t *testing.T) { "json.go", "map.go", "math.go", + "mapgrowth.go", "print.go", "reflect.go", "slice.go", diff --git a/testdata/mapgrowth.go b/testdata/mapgrowth.go new file mode 100644 index 000000000..5a37303af --- /dev/null +++ b/testdata/mapgrowth.go @@ -0,0 +1,66 @@ +package main + +func main() { + + m := make(map[int]int) + + const ( + Delete = 500 + N = Delete * 2 + ) + + for i := 0; i < Delete; i++ { + m[i] = i + } + + var deleted bool + for k, v := range m { + if k == 0 { + // grow map + for i := Delete; i < N; i++ { + m[i] = i + } + + // delete some elements + for i := 0; i < Delete; i++ { + delete(m, i) + } + deleted = true + continue + } + + // make sure we never see a deleted element later in our iteration + if deleted && v < Delete { + println("saw deleted element", v) + } + } + + if len(m) != N-Delete { + println("bad length post grow/delete", len(m)) + } + + seen := make([]bool, 500) + + var mcount int + for k, v := range m { + if k != v { + println("element mismatch", k, v) + } + if k < Delete { + println("saw deleted element post-grow", k) + } + seen[v-Delete] = true + mcount++ + } + + for _, v := range seen { + if !v { + println("missing key", v) + } + } + + if mcount != N-Delete { + println("bad number of elements post-grow:", mcount) + } + println("done") +} diff --git a/testdata/mapgrowth.txt b/testdata/mapgrowth.txt new file mode 100644 index 000000000..19f86f493 --- /dev/null +++ b/testdata/mapgrowth.txt @@ -0,0 +1 @@ +done |