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

Function TestMap_Set

immutable_test.go:958–1078  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

956}
957
958func TestMap_Set(t *testing.T) {
959 t.Run("Simple", func(t *testing.T) {
960 m := NewMap[int, string](nil)
961 itr := m.Iterator()
962 if !itr.Done() {
963 t.Fatal("MapIterator.Done()=true, expected false")
964 } else if k, v, ok := itr.Next(); ok {
965 t.Fatalf("MapIterator.Next()=<%v,%v>, expected nil", k, v)
966 }
967 })
968
969 t.Run("Simple", func(t *testing.T) {
970 m := NewMap[int, string](nil)
971 m = m.Set(100, "foo")
972 if v, ok := m.Get(100); !ok || v != "foo" {
973 t.Fatalf("unexpected value: <%v,%v>", v, ok)
974 }
975 })
976
977 t.Run("Multi", func(t *testing.T) {
978 m := NewMapOf(nil, map[int]string{1: "foo"})
979 itr := m.Iterator()
980 if itr.Done() {
981 t.Fatal("MapIterator.Done()=false, expected true")
982 }
983 if k, v, ok := itr.Next(); !ok {
984 t.Fatalf("MapIterator.Next()!=ok, expected ok")
985 } else if k != 1 || v != "foo" {
986 t.Fatalf("MapIterator.Next()=<%v,%v>, expected <1, \"foo\">", k, v)
987 }
988 if k, v, ok := itr.Next(); ok {
989 t.Fatalf("MapIterator.Next()=<%v,%v>, expected nil", k, v)
990 }
991 })
992
993 t.Run("VerySmall", func(t *testing.T) {
994 const n = 6
995 m := NewMap[int, int](nil)
996 for i := 0; i < n; i++ {
997 m = m.Set(i, i+1)
998 }
999 for i := 0; i < n; i++ {
1000 if v, ok := m.Get(i); !ok || v != i+1 {
1001 t.Fatalf("unexpected value for key=%v: <%v,%v>", i, v, ok)
1002 }
1003 }
1004
1005 // NOTE: Array nodes store entries in insertion order.
1006 itr := m.Iterator()
1007 for i := 0; i < n; i++ {
1008 if k, v, ok := itr.Next(); !ok || k != i || v != i+1 {
1009 t.Fatalf("MapIterator.Next()=<%v,%v>, exp <%v,%v>", k, v, i, i+1)
1010 }
1011 }
1012 if !itr.Done() {
1013 t.Fatal("expected iterator done")
1014 }
1015 })

Callers

nothing calls this directly

Calls 11

NewMapOfFunction · 0.85
RunRandomFunction · 0.85
NewTestMapFunction · 0.85
IteratorMethod · 0.45
DoneMethod · 0.45
NextMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45
ExistingKeyMethod · 0.45
NewKeyMethod · 0.45
ValidateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…