Skip to content
Browse files

test union against empty sets and large numbers which we have observe…

…d to have caused problems
  • Loading branch information...
1 parent 2fecf5f commit ab9b4ecbac45c5534e6b60089be8565d85d6e429 @d2fn d2fn committed Aug 1, 2012
Showing with 42 additions and 1 deletion.
  1. +42 −1 src/test/java/org/cliffc/high_scale_lib/NonBlockingSetIntTest.java
View
43 src/test/java/org/cliffc/high_scale_lib/NonBlockingSetIntTest.java
@@ -21,6 +21,7 @@ public void testSetOperations() {
// on two others is sized appropriately initially
NonBlockingSetInt a = new NonBlockingSetInt();
NonBlockingSetInt b = new NonBlockingSetInt();
+ NonBlockingSetInt empty = new NonBlockingSetInt();
int max = 10000;
for(int i = 0; i < max; i++) {
@@ -29,8 +30,14 @@ public void testSetOperations() {
assertTrue(t.contains(i));
}
+ int magic = 1213446;
+
+ a.add(magic);
+ NonBlockingSetInt c = a.union(empty);
+ assertTrue(c.contains(magic));
+
// c should contain the empty set since a and b are disjoint
- NonBlockingSetInt c = a.intersect(b);
+ c = a.intersect(b);
NonBlockingSetInt d = b.intersect(a);
for(int i = 0; i < max; i++) {
assertFalse(c.contains(i));
@@ -44,6 +51,40 @@ public void testSetOperations() {
assertTrue(d.contains(i));
}
+ c = a.union(empty);
+ d = empty.union(a);
+
+ IntIterator itr = a.intIterator();
+ while(itr.hasNext()) {
+ int next = itr.next();
+ assertTrue(c.contains(next));
+ assertTrue(d.contains(next));
+ }
+
+ itr = b.intIterator();
+ while(itr.hasNext()) {
+ int next = itr.next();
+ assertFalse(c.contains(next));
+ assertFalse(d.contains(next));
+ }
+
+ c = b.union(empty);
+ d = empty.union(b);
+
+ itr = b.intIterator();
+ while(itr.hasNext()) {
+ int next = itr.next();
+ assertTrue(c.contains(next));
+ assertTrue(d.contains(next));
+ }
+
+ itr = a.intIterator();
+ while(itr.hasNext()) {
+ int next = itr.next();
+ assertFalse(c.contains(next));
+ assertFalse(d.contains(next));
+ }
+
// just make sure the bitset is usable after building out an instance with an ample internal buffer
for(int i = 0; i < max; i++) {
c.add(i);

0 comments on commit ab9b4ec

Please sign in to comment.
Something went wrong with that request. Please try again.