MCPcopy Create free account
hub / github.com/benbjohnson/immutable / TestMap_Overwrite

Function TestMap_Overwrite

immutable_test.go:1081–1114  ·  view source on GitHub ↗

Ensure map can support overwrites as it expands.

(t *testing.T)

Source from the content-addressed store, hash-verified

1079
1080// Ensure map can support overwrites as it expands.
1081func TestMap_Overwrite(t *testing.T) {
1082 if testing.Short() {
1083 t.Skip("short mode")
1084 }
1085
1086 const n = 10000
1087 m := NewMap[int, int](nil)
1088 for i := 0; i < n; i++ {
1089 // Set original value.
1090 m = m.Set(i, i)
1091
1092 // Overwrite every node.
1093 for j := 0; j <= i; j++ {
1094 m = m.Set(j, i*j)
1095 }
1096 }
1097
1098 // Verify all key/value pairs in map.
1099 for i := 0; i < n; i++ {
1100 if v, ok := m.Get(i); !ok || v != i*(n-1) {
1101 t.Fatalf("Get(%d)=<%v,%v>", i, v, ok)
1102 }
1103 }
1104
1105 t.Run("Simple", func(t *testing.T) {
1106 m := NewMap[int, string](nil)
1107 itr := m.Iterator()
1108 if !itr.Done() {
1109 t.Fatal("MapIterator.Done()=true, expected false")
1110 } else if k, v, ok := itr.Next(); ok {
1111 t.Fatalf("MapIterator.Next()=<%v,%v>, expected nil", k, v)
1112 }
1113 })
1114}
1115
1116func TestMap_Delete(t *testing.T) {
1117 t.Run("Empty", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

SetMethod · 0.45
GetMethod · 0.45
IteratorMethod · 0.45
DoneMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…