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

Function TestSortedMap_Delete

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

Source from the content-addressed store, hash-verified

1915}
1916
1917func TestSortedMap_Delete(t *testing.T) {
1918 t.Run("Empty", func(t *testing.T) {
1919 m := NewSortedMap[int, int](nil)
1920 m = m.Delete(100)
1921 if n := m.Len(); n != 0 {
1922 t.Fatalf("SortedMap.Len()=%d, expected 0", n)
1923 }
1924 })
1925
1926 t.Run("Simple", func(t *testing.T) {
1927 m := NewSortedMap[int, string](nil)
1928 m = m.Set(100, "foo")
1929 if v, ok := m.Get(100); !ok || v != "foo" {
1930 t.Fatalf("unexpected value: <%v,%v>", v, ok)
1931 }
1932 m = m.Delete(100)
1933 if v, ok := m.Get(100); ok {
1934 t.Fatalf("unexpected no value: <%v,%v>", v, ok)
1935 }
1936 })
1937
1938 t.Run("Small", func(t *testing.T) {
1939 const n = 1000
1940 m := NewSortedMap[int, int](nil)
1941 for i := 0; i < n; i++ {
1942 m = m.Set(i, i+1)
1943 }
1944 for i := 0; i < n; i++ {
1945 if v, ok := m.Get(i); !ok || v != i+1 {
1946 t.Fatalf("unexpected value for key=%v: <%v,%v>", i, v, ok)
1947 }
1948 }
1949
1950 for i := 0; i < n; i++ {
1951 m = m.Delete(i)
1952 }
1953 for i := 0; i < n; i++ {
1954 if v, ok := m.Get(i); ok {
1955 t.Fatalf("expected no value for key=%v: <%v,%v>", i, v, ok)
1956 }
1957 }
1958 })
1959
1960 t.Run("Large", func(t *testing.T) {
1961 if testing.Short() {
1962 t.Skip("skipping: short")
1963 }
1964
1965 const n = 1000000
1966 m := NewSortedMap[int, int](nil)
1967 for i := 0; i < n; i++ {
1968 m = m.Set(i, i+1)
1969 }
1970 for i := 0; i < n; i++ {
1971 if v, ok := m.Get(i); !ok || v != i+1 {
1972 t.Fatalf("unexpected value for key=%v: <%v,%v>", i, v, ok)
1973 }
1974 }

Callers

nothing calls this directly

Calls 9

DeleteMethod · 0.95
SetMethod · 0.95
ExistingKeyMethod · 0.95
NewKeyMethod · 0.95
ValidateMethod · 0.95
RunRandomFunction · 0.85
NewTSortedMapFunction · 0.85
LenMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…