| 245 | } |
| 246 | |
| 247 | func TestBase_Get(t *testing.T) { |
| 248 | |
| 249 | ta := require.New(t) |
| 250 | |
| 251 | indexes := []int32{1, 3, 100} |
| 252 | elts := []uint16{1, 3, 100} |
| 253 | |
| 254 | ab := &array.Base{} |
| 255 | ab.EltEncoder = encode.U16{} |
| 256 | |
| 257 | // test empty array |
| 258 | ta.Panics(func() { ab.Get(1) }) |
| 259 | |
| 260 | err := ab.Init(indexes, elts) |
| 261 | ta.Nil(err) |
| 262 | |
| 263 | for i, idx := range indexes { |
| 264 | v, found := ab.Get(idx) |
| 265 | ta.True(found) |
| 266 | ta.Equal(elts[i], v, "%d-th, %d expect %d found but: %v", i+1, idx, elts[i], v) |
| 267 | |
| 268 | v, found = ab.Get(idx + 1) |
| 269 | ta.False(found) |
| 270 | ta.Nil(v) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | var OutputBool bool |
| 275 | |