(t *testing.T)
| 111 | } |
| 112 | |
| 113 | func TestSeek(t *testing.T) { |
| 114 | N := 10001 |
| 115 | enc := Encoder{BlockSize: 10} |
| 116 | for i := 0; i < N; i += 10 { |
| 117 | enc.Add(uint64(i)) |
| 118 | } |
| 119 | pack := enc.Done() |
| 120 | defer FreePack(pack) |
| 121 | dec := Decoder{Pack: pack} |
| 122 | |
| 123 | tests := []struct { |
| 124 | in, out uint64 |
| 125 | whence seekPos |
| 126 | empty bool |
| 127 | }{ |
| 128 | {in: 0, out: 0, whence: SeekStart}, |
| 129 | {in: 0, out: 0, whence: SeekCurrent}, |
| 130 | {in: 100, out: 100, whence: SeekStart}, |
| 131 | {in: 100, out: 110, whence: SeekCurrent}, |
| 132 | {in: 1000, out: 1000, whence: SeekStart}, |
| 133 | {in: 1000, out: 1010, whence: SeekCurrent}, |
| 134 | {in: 1999, out: 2000, whence: SeekStart}, |
| 135 | {in: 1999, out: 2000, whence: SeekCurrent}, |
| 136 | {in: 1101, out: 1110, whence: SeekStart}, |
| 137 | {in: 1101, out: 1110, whence: SeekCurrent}, |
| 138 | {in: 10000, out: 10000, whence: SeekStart}, |
| 139 | {in: 9999, out: 10000, whence: SeekCurrent}, |
| 140 | {in: uint64(N), empty: true, whence: SeekStart}, |
| 141 | {in: uint64(N), empty: true, whence: SeekCurrent}, |
| 142 | {in: math.MaxUint64, empty: true, whence: SeekStart}, |
| 143 | {in: math.MaxUint64, empty: true, whence: SeekCurrent}, |
| 144 | } |
| 145 | |
| 146 | for _, tc := range tests { |
| 147 | uids := dec.Seek(tc.in, tc.whence) |
| 148 | if tc.empty { |
| 149 | require.Empty(t, uids) |
| 150 | } else { |
| 151 | require.Equal(t, tc.out, uids[0]) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | dec.blockIdx = 0 |
| 156 | for i := 100; i < 10000; i += 100 { |
| 157 | uids := dec.LinearSeek(uint64(i)) |
| 158 | require.Contains(t, uids, uint64(i)) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func TestLinearSeek(t *testing.T) { |
| 163 | N := 10001 |
nothing calls this directly
no test coverage detected