(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func TestCopies(t *testing.T) { |
| 32 | tests := []struct { |
| 33 | name string |
| 34 | cow1 bool |
| 35 | cow2 bool |
| 36 | }{ |
| 37 | {"AppendCopiesAfterCoW", true, true}, |
| 38 | } |
| 39 | |
| 40 | for _, test := range tests { |
| 41 | t.Run(test.name, func(t *testing.T) { |
| 42 | r1 := uint64(1) << 32 |
| 43 | r2 := uint64(2) << 32 |
| 44 | r3 := uint64(3) << 32 |
| 45 | r4 := uint64(4) << 32 |
| 46 | |
| 47 | bitmap1 := New() |
| 48 | bitmap2 := New() |
| 49 | bitmap1.SetCopyOnWrite(test.cow1) |
| 50 | bitmap2.SetCopyOnWrite(test.cow2) |
| 51 | |
| 52 | bitmap2.AddRange(r1-1, r1+2) |
| 53 | bitmap2.AddRange(r2-1, r2+2) |
| 54 | bitmap2.AddRange(r3-1, r3+2) |
| 55 | bitmap2.AddRange(r4-1, r4+2) |
| 56 | |
| 57 | assert.False(t, bitmap1.Contains(r2)) |
| 58 | assert.False(t, bitmap1.Contains(r3)) |
| 59 | assert.Equal(t, 0, len(bitmap1.highlowcontainer.keys)) |
| 60 | bitmap1.highlowcontainer.appendCopiesAfter(bitmap2.highlowcontainer, 0) |
| 61 | assert.Equal(t, 4, len(bitmap1.highlowcontainer.keys)) |
| 62 | assert.True(t, bitmap1.Contains(r2)) |
| 63 | assert.True(t, bitmap1.Contains(r3)) |
| 64 | |
| 65 | for idx1, c1 := range bitmap1.highlowcontainer.containers { |
| 66 | for idx2, c2 := range bitmap2.highlowcontainer.containers { |
| 67 | // idx+1 is required because appendCopiesAfter starts at key 1 |
| 68 | if idx1+1 == idx2 { |
| 69 | if test.cow1 && test.cow2 { |
| 70 | assert.True(t, c1 == c2) |
| 71 | } else { |
| 72 | assert.False(t, c1 == c2) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | tests = []struct { |
| 81 | name string |
| 82 | cow1 bool |
| 83 | cow2 bool |
| 84 | }{ |
| 85 | {"AppendCopiesUntilCoW", true, true}, |
| 86 | {"AppendCopiesUntilCoW", false, false}, |
| 87 | {"AppendCopiesUntilMixedCoW", true, false}, |
| 88 | {"AppendCopiesUntilMixedCoW", false, true}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…