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

Function TestSortedMap_Iterator

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

Source from the content-addressed store, hash-verified

2014}
2015
2016func TestSortedMap_Iterator(t *testing.T) {
2017 t.Run("Empty", func(t *testing.T) {
2018 t.Run("First", func(t *testing.T) {
2019 itr := NewSortedMap[int, int](nil).Iterator()
2020 itr.First()
2021 if k, v, ok := itr.Next(); ok {
2022 t.Fatalf("SortedMapIterator.Next()=<%v,%v>, expected nil", k, v)
2023 }
2024 })
2025
2026 t.Run("Last", func(t *testing.T) {
2027 itr := NewSortedMap[int, int](nil).Iterator()
2028 itr.Last()
2029 if k, v, ok := itr.Prev(); ok {
2030 t.Fatalf("SortedMapIterator.Prev()=<%v,%v>, expected nil", k, v)
2031 }
2032 })
2033
2034 t.Run("Seek", func(t *testing.T) {
2035 itr := NewSortedMap[string, int](nil).Iterator()
2036 itr.Seek("foo")
2037 if k, v, ok := itr.Next(); ok {
2038 t.Fatalf("SortedMapIterator.Next()=<%v,%v>, expected nil", k, v)
2039 }
2040 })
2041 })
2042
2043 t.Run("Seek", func(t *testing.T) {
2044 const n = 100
2045 m := NewSortedMap[string, int](nil)
2046 for i := 0; i < n; i += 2 {
2047 m = m.Set(fmt.Sprintf("%04d", i), i)
2048 }
2049
2050 t.Run("Exact", func(t *testing.T) {
2051 itr := m.Iterator()
2052 for i := 0; i < n; i += 2 {
2053 itr.Seek(fmt.Sprintf("%04d", i))
2054 for j := i; j < n; j += 2 {
2055 if k, _, ok := itr.Next(); !ok || k != fmt.Sprintf("%04d", j) {
2056 t.Fatalf("%d/%d. SortedMapIterator.Next()=%v, expected key %04d", i, j, k, j)
2057 }
2058 }
2059 if !itr.Done() {
2060 t.Fatalf("SortedMapIterator.Done()=true, expected false")
2061 }
2062 }
2063 })
2064
2065 t.Run("Miss", func(t *testing.T) {
2066 itr := m.Iterator()
2067 for i := 1; i < n-2; i += 2 {
2068 itr.Seek(fmt.Sprintf("%04d", i))
2069 for j := i + 1; j < n; j += 2 {
2070 if k, _, ok := itr.Next(); !ok || k != fmt.Sprintf("%04d", j) {
2071 t.Fatalf("%d/%d. SortedMapIterator.Next()=%v, expected key %04d", i, j, k, j)
2072 }
2073 }

Callers

nothing calls this directly

Calls 8

IteratorMethod · 0.45
FirstMethod · 0.45
NextMethod · 0.45
LastMethod · 0.45
PrevMethod · 0.45
SeekMethod · 0.45
SetMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…