Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nibix committed Jul 15, 2024
1 parent 3921502 commit 6e70f20
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static final class LongArrayBacked<E> extends BitBackedSetImpl<E> {
private final IndexedImmutableSetImpl<E> elementToIndexMap;
private final int bitArrayOffset;

public LongArrayBacked(
LongArrayBacked(
long[] bits, int size, IndexedImmutableSetImpl<E> elementToIndexMap, int bitArrayOffset) {
this.bits = bits;
this.size = size;
Expand Down Expand Up @@ -82,7 +82,6 @@ int findNext(int arrayIndex, int bitIndex) {
}
}


for (; ; ) {
long bit = 1l << bitIndex;

Expand Down Expand Up @@ -189,7 +188,7 @@ static final class LongBacked<E> extends BitBackedSetImpl<E> {
private final IndexedImmutableSetImpl<E> elementToIndexMap;
private final int bitArrayOffset;

public LongBacked(long bits, int size, IndexedImmutableSetImpl<E> elementToIndexMap, int bitArrayOffset) {
LongBacked(long bits, int size, IndexedImmutableSetImpl<E> elementToIndexMap, int bitArrayOffset) {
this.bits = bits;
this.size = size;
this.elementToIndexMap = elementToIndexMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class BitBackedSetImplTest {
@Test
public void bitArraySize() {
Expand All @@ -44,4 +47,57 @@ public void firstNonZeroIndex() {
Assert.assertEquals(0, BitBackedSetImpl.firstNonZeroIndex(new long[] {1, 2, 3, 0}));
Assert.assertEquals(-1, BitBackedSetImpl.firstNonZeroIndex(new long[] {0, 0, 0, 0}));
}

@Test
public void empty_arrayBacked() {
BitBackedSetImpl.LongArrayBacked<String> subject = new BitBackedSetImpl.LongArrayBacked<>(new long [] {0}, 0, IndexedImmutableSetImpl.of("a"), 0);
Assert.assertTrue(subject.isEmpty());
}

@Test
public void empty_longBacked() {
BitBackedSetImpl.LongBacked<String> subject = new BitBackedSetImpl.LongBacked<>(0, 0, IndexedImmutableSetImpl.of("a"), 0);
Assert.assertTrue(subject.isEmpty());
}

@Test
public void contains_arrayBacked() {
BitBackedSetImpl.LongArrayBacked<String> subject = new BitBackedSetImpl.LongArrayBacked<>(new long [] {1}, 0, IndexedImmutableSetImpl.of("a", "b"), 0);
Assert.assertTrue(subject.contains("a"));
Assert.assertFalse(subject.contains("b"));
Assert.assertFalse(subject.contains("x"));
}

@Test
public void contains_longBacked() {
BitBackedSetImpl.LongBacked<String> subject = new BitBackedSetImpl.LongBacked<>(1, 0, IndexedImmutableSetImpl.of("a", "b"), 0);
Assert.assertTrue(subject.contains("a"));
Assert.assertFalse(subject.contains("b"));
Assert.assertFalse(subject.contains("x"));
}


@Test(expected = NoSuchElementException.class)
public void iterator_exhausted_arrayBacked() {
BitBackedSetImpl.LongArrayBacked<String> subject = new BitBackedSetImpl.LongArrayBacked<>(new long [] {1}, 0, IndexedImmutableSetImpl.of("a", "b"), 0);
Iterator<String> iter = subject.iterator();

while (iter.hasNext()) {
iter.next();
}

iter.next();
}

@Test(expected = NoSuchElementException.class)
public void iterator_exhausted_longBacked() {
BitBackedSetImpl.LongBacked<String> subject = new BitBackedSetImpl.LongBacked<>(1, 0, IndexedImmutableSetImpl.of("a", "b"), 0);
Iterator<String> iter = subject.iterator();

while (iter.hasNext()) {
iter.next();
}

iter.next();
}
}

0 comments on commit 6e70f20

Please sign in to comment.