(t *testing.T, arr []uint32, offset int64)
| 700 | } |
| 701 | |
| 702 | func testAddOffset(t *testing.T, arr []uint32, offset int64) { |
| 703 | expected := make([]uint32, 0, len(arr)) |
| 704 | for _, i := range arr { |
| 705 | v := int64(i) + offset |
| 706 | if v >= 0 && v <= MaxUint32 { |
| 707 | expected = append(expected, uint32(v)) |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | bmp := NewBitmap() |
| 712 | bmp.AddMany(arr) |
| 713 | |
| 714 | cop := AddOffset64(bmp, offset) |
| 715 | |
| 716 | if !assert.EqualValues(t, len(expected), cop.GetCardinality()) { |
| 717 | t.Logf("Applying offset %d", offset) |
| 718 | } |
| 719 | if !assert.EqualValues(t, expected, cop.ToArray()) { |
| 720 | t.Logf("Applying offset %d", offset) |
| 721 | } |
| 722 | |
| 723 | // Now check backing off gets us back all non-discarded numbers |
| 724 | expected2 := make([]uint32, 0, len(expected)) |
| 725 | for _, i := range expected { |
| 726 | v := int64(i) - offset |
| 727 | if v >= 0 && v <= MaxUint32 { |
| 728 | expected2 = append(expected2, uint32(v)) |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | cop2 := AddOffset64(cop, -offset) |
| 733 | |
| 734 | if !assert.EqualValues(t, len(expected2), cop2.GetCardinality()) { |
| 735 | t.Logf("Restoring from offset %d", offset) |
| 736 | } |
| 737 | if !assert.EqualValues(t, expected2, cop2.ToArray()) { |
| 738 | t.Logf("Restoring from offset %d", offset) |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | func TestRoaringBitmapAddOffset(t *testing.T) { |
| 743 | type testCase struct { |
no test coverage detected
searching dependent graphs…