(t *testing.T)
| 2014 | } |
| 2015 | |
| 2016 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…