You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoredBitmapTest.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2012, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.internal.storage.file;
  11. import static org.junit.Assert.assertEquals;
  12. import org.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap;
  13. import org.eclipse.jgit.lib.ObjectId;
  14. import org.junit.Test;
  15. import com.googlecode.javaewah.EWAHCompressedBitmap;
  16. public class StoredBitmapTest {
  17. @Test
  18. public void testGetBitmapWithoutXor() {
  19. EWAHCompressedBitmap b = bitmapOf(100);
  20. StoredBitmap sb = newStoredBitmap(bitmapOf(100));
  21. assertEquals(b, sb.getBitmap());
  22. }
  23. @Test
  24. public void testGetBitmapWithOneXor() {
  25. StoredBitmap sb = newStoredBitmap(bitmapOf(100), bitmapOf(100, 101));
  26. assertEquals(bitmapOf(101), sb.getBitmap());
  27. }
  28. @Test
  29. public void testGetBitmapWithThreeXor() {
  30. StoredBitmap sb = newStoredBitmap(
  31. bitmapOf(100),
  32. bitmapOf(90, 101),
  33. bitmapOf(100, 101),
  34. bitmapOf(50));
  35. assertEquals(bitmapOf(50, 90), sb.getBitmap());
  36. assertEquals(bitmapOf(50, 90), sb.getBitmap());
  37. }
  38. private static final StoredBitmap newStoredBitmap(
  39. EWAHCompressedBitmap... bitmaps) {
  40. StoredBitmap sb = null;
  41. for (EWAHCompressedBitmap bitmap : bitmaps)
  42. sb = new StoredBitmap(ObjectId.zeroId(), bitmap, sb, 0);
  43. return sb;
  44. }
  45. private static final EWAHCompressedBitmap bitmapOf(int... bits) {
  46. EWAHCompressedBitmap b = new EWAHCompressedBitmap();
  47. for (int bit : bits)
  48. b.set(bit);
  49. return b;
  50. }
  51. }