Пример #1
0
  public void shouldReturnUnitializedValues() {
    CircularBitSet bs = new CircularBitSet(100, null);
    for (int i = 0; i < 100; i++) {
      assertEquals(bs.setNext(true), -1);
    }

    assertEquals(bs.setNext(true), 1);
    assertEquals(bs.setNext(true), 1);
  }
Пример #2
0
  public void testCopyBitsToLargerSet() {
    CircularBitSet left = new CircularBitSet(5, null);
    setBits(left, true, 2);
    setBits(left, false, 3);

    left.nextIndex = 0;
    CircularBitSet right = new CircularBitSet(6, left);
    assertValues(right, true, true, false, false, false);

    left.nextIndex = 2;
    right = new CircularBitSet(6, left);
    assertValues(right, false, false, false, true, true);

    left.nextIndex = 4;
    right = new CircularBitSet(6, left);
    assertValues(right, false, true, true, false, false);
  }
Пример #3
0
  public void testCopyBitsToSmallerSet() {
    CircularBitSet left = new CircularBitSet(10, null);
    setBits(left, true, 5);
    setBits(left, false, 5);

    left.nextIndex = 0;
    CircularBitSet right = new CircularBitSet(4, left);
    assertValues(right, false, false, false, false);

    left.nextIndex = 2;
    right = new CircularBitSet(4, left);
    assertValues(right, false, false, true, true);

    left.nextIndex = 7;
    right = new CircularBitSet(4, left);
    assertValues(right, true, true, false, false);
  }
Пример #4
0
  public void testRatios() {
    CircularBitSet bs = new CircularBitSet(100, null);

    for (int i = 0; i < 50; i++) bs.setNext(i % 3 == 0);
    assertEquals(bs.positiveRatio(), .34);
    assertEquals(bs.negativeRatio(), .66);

    for (int i = 0; i < 100; i++) bs.setNext(true);
    assertEquals(bs.positiveRatio(), 1.0);
    assertEquals(bs.negativeRatio(), 0.0);
  }
Пример #5
0
 private void setBits(CircularBitSet bs, boolean value, int count) {
   for (int i = 0; i < count; i++) bs.setNext(value);
 }
Пример #6
0
 private boolean[] valuesFor(CircularBitSet bs) {
   boolean[] values = new boolean[bs.occupiedBits()];
   for (int i = 0; i < values.length; i++) values[i] = bs.bitSet.get(i);
   return values;
 }