1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import static org.junit.Assert.assertEquals;
14
15 import org.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap;
16 import org.eclipse.jgit.lib.ObjectId;
17 import org.junit.Test;
18
19 import com.googlecode.javaewah.EWAHCompressedBitmap;
20
21 public class StoredBitmapTest {
22
23 @Test
24 public void testGetBitmapWithoutXor() {
25 EWAHCompressedBitmap b = bitmapOf(100);
26 StoredBitmap sb = newStoredBitmap(bitmapOf(100));
27 assertEquals(b, sb.getBitmap());
28 }
29
30 @Test
31 public void testGetBitmapWithOneXor() {
32 StoredBitmap sb = newStoredBitmap(bitmapOf(100), bitmapOf(100, 101));
33 assertEquals(bitmapOf(101), sb.getBitmap());
34 }
35
36 @Test
37 public void testGetBitmapWithThreeXor() {
38 StoredBitmap sb = newStoredBitmap(
39 bitmapOf(100),
40 bitmapOf(90, 101),
41 bitmapOf(100, 101),
42 bitmapOf(50));
43 assertEquals(bitmapOf(50, 90), sb.getBitmap());
44 assertEquals(bitmapOf(50, 90), sb.getBitmap());
45 }
46
47 private static final StoredBitmap newStoredBitmap(
48 EWAHCompressedBitmap... bitmaps) {
49 StoredBitmap sb = null;
50 for (EWAHCompressedBitmap bitmap : bitmaps)
51 sb = new StoredBitmap(ObjectId.zeroId(), bitmap, sb, 0);
52 return sb;
53 }
54
55 private static final EWAHCompressedBitmap bitmapOf(int... bits) {
56 EWAHCompressedBitmap b = new EWAHCompressedBitmap();
57 for (int bit : bits)
58 b.set(bit);
59 return b;
60 }
61 }