use of java.util.BitSet in project j2objc by google.
the class BitSetTest method test_getII.
public void test_getII() {
BitSet bitset = new BitSet(30);
bitset.get(3, 3);
BitSet bs, resultbs, correctbs;
bs = new BitSet(512);
bs.set(3, 9);
bs.set(10, 20);
bs.set(60, 75);
bs.set(121);
bs.set(130, 140);
// pos1 and pos2 are in the same bitset element, at index0
resultbs = bs.get(3, 6);
correctbs = new BitSet(3);
correctbs.set(0, 3);
assertEquals("Test1: Returned incorrect BitSet", correctbs, resultbs);
// pos1 and pos2 are in the same bitset element, at index 1
resultbs = bs.get(100, 125);
correctbs = new BitSet(25);
correctbs.set(21);
assertEquals("Test2: Returned incorrect BitSet", correctbs, resultbs);
// pos1 in bitset element at index 0, and pos2 in bitset element at
// index 1
resultbs = bs.get(15, 125);
correctbs = new BitSet(25);
correctbs.set(0, 5);
correctbs.set(45, 60);
correctbs.set(121 - 15);
assertEquals("Test3: Returned incorrect BitSet", correctbs, resultbs);
// pos1 in bitset element at index 1, and pos2 in bitset element at
// index 2
resultbs = bs.get(70, 145);
correctbs = new BitSet(75);
correctbs.set(0, 5);
correctbs.set(51);
correctbs.set(60, 70);
assertEquals("Test4: Returned incorrect BitSet", correctbs, resultbs);
// pos1 in bitset element at index 0, and pos2 in bitset element at
// index 2
resultbs = bs.get(5, 145);
correctbs = new BitSet(140);
correctbs.set(0, 4);
correctbs.set(5, 15);
correctbs.set(55, 70);
correctbs.set(116);
correctbs.set(125, 135);
assertEquals("Test5: Returned incorrect BitSet", correctbs, resultbs);
// pos1 in bitset element at index 0, and pos2 in bitset element at
// index 3
resultbs = bs.get(5, 250);
correctbs = new BitSet(200);
correctbs.set(0, 4);
correctbs.set(5, 15);
correctbs.set(55, 70);
correctbs.set(116);
correctbs.set(125, 135);
assertEquals("Test6: Returned incorrect BitSet", correctbs, resultbs);
assertEquals("equality principle 1 ", bs.get(0, bs.size()), bs);
// more tests
BitSet bs2 = new BitSet(129);
bs2.set(0, 20);
bs2.set(62, 65);
bs2.set(121, 123);
resultbs = bs2.get(1, 124);
correctbs = new BitSet(129);
correctbs.set(0, 19);
correctbs.set(61, 64);
correctbs.set(120, 122);
assertEquals("Test7: Returned incorrect BitSet", correctbs, resultbs);
// equality principle with some boundary conditions
bs2 = new BitSet(128);
bs2.set(2, 20);
bs2.set(62);
bs2.set(121, 123);
bs2.set(127);
resultbs = bs2.get(0, bs2.size());
assertEquals("equality principle 2 ", resultbs, bs2);
bs2 = new BitSet(128);
bs2.set(2, 20);
bs2.set(62);
bs2.set(121, 123);
bs2.set(127);
bs2.flip(0, 128);
resultbs = bs2.get(0, bs.size());
assertEquals("equality principle 3 ", resultbs, bs2);
bs = new BitSet(0);
assertEquals("Test1: Wrong length,", 0, bs.length());
assertEquals("Test1: Wrong size,", 0, bs.size());
bs.get(0, 2);
assertEquals("Test2: Wrong length,", 0, bs.length());
assertEquals("Test2: Wrong size,", 0, bs.size());
bs.get(60, 64);
assertEquals("Test3: Wrong length,", 0, bs.length());
assertEquals("Test3: Wrong size,", 0, bs.size());
bs.get(64, 120);
assertEquals("Test4: Wrong length,", 0, bs.length());
assertEquals("Test4: Wrong size,", 0, bs.size());
bs.set(25);
assertEquals("Test5: Wrong length,", 26, bs.length());
assertEquals("Test5: Wrong size,", 64, bs.size());
bs.get(60, 64);
assertEquals("Test6: Wrong length,", 26, bs.length());
assertEquals("Test6: Wrong size,", 64, bs.size());
bs.get(64, 120);
assertEquals("Test7: Wrong size,", 64, bs.size());
assertEquals("Test7: Wrong length,", 26, bs.length());
bs.get(80);
assertEquals("Test8: Wrong size,", 64, bs.size());
assertEquals("Test8: Wrong length,", 26, bs.length());
bs.get(25);
assertEquals("Test9: Wrong size,", 64, bs.size());
assertEquals("Test9: Wrong length,", 26, bs.length());
try {
bs2.get(-1, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
bs2.get(bs2.size() / 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
bs2.get(bs2.size() / 2, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
}
use of java.util.BitSet in project j2objc by google.
the class BitSetTest method test_flipI.
public void test_flipI() {
BitSet bs = new BitSet();
bs.clear(8);
bs.clear(9);
bs.set(10);
bs.flip(9);
assertFalse("Failed to flip bit", bs.get(8));
assertTrue("Failed to flip bit", bs.get(9));
assertTrue("Failed to flip bit", bs.get(10));
bs.set(8);
bs.set(9);
bs.clear(10);
bs.flip(9);
assertTrue("Failed to flip bit", bs.get(8));
assertFalse("Failed to flip bit", bs.get(9));
assertFalse("Failed to flip bit", bs.get(10));
try {
bs.flip(-1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
// Try setting a bit on a 64 boundary
bs.flip(128);
assertEquals("Failed to grow BitSet", 192, bs.size());
assertTrue("Failed to flip bit", bs.get(128));
bs = new BitSet(64);
for (int i = bs.size(); --i >= 0; ) {
bs.flip(i);
assertTrue("Test1: Incorrectly flipped bit" + i, bs.get(i));
assertEquals("Incorrect length", i + 1, bs.length());
for (int j = bs.size(); --j > i; ) {
assertTrue("Test2: Incorrectly flipped bit" + j, !bs.get(j));
}
for (int j = i; --j >= 0; ) {
assertTrue("Test3: Incorrectly flipped bit" + j, !bs.get(j));
}
bs.flip(i);
}
BitSet bs0 = new BitSet(0);
assertEquals("Test1: Wrong size", 0, bs0.size());
assertEquals("Test1: Wrong length", 0, bs0.length());
bs0.flip(0);
assertEquals("Test2: Wrong size", 64, bs0.size());
assertEquals("Test2: Wrong length", 1, bs0.length());
bs0.flip(63);
assertEquals("Test3: Wrong size", 64, bs0.size());
assertEquals("Test3: Wrong length", 64, bs0.length());
eightbs.flip(7);
assertTrue("Failed to flip bit 7", !eightbs.get(7));
// Check to see all other bits are still set
for (int i = 0; i < 7; i++) {
assertTrue("Flip flipped incorrect bits", eightbs.get(i));
}
eightbs.flip(127);
assertTrue("Failed to flip bit 127", eightbs.get(127));
eightbs.flip(127);
assertTrue("Failed to flip bit 127", !eightbs.get(127));
}
use of java.util.BitSet in project j2objc by google.
the class BitSetTest method test_andLjava_util_BitSet.
public void test_andLjava_util_BitSet() {
BitSet bs = new BitSet(128);
// Initialize the bottom half of the BitSet
for (int i = 64; i < 128; i++) {
bs.set(i);
}
eightbs.and(bs);
assertTrue("AND failed to clear bits", !eightbs.equals(bs));
eightbs.set(3);
bs.set(3);
eightbs.and(bs);
assertTrue("AND failed to maintain set bits", bs.get(3));
bs.and(eightbs);
for (int i = 64; i < 128; i++) {
assertTrue("Failed to clear extra bits in the receiver BitSet", !bs.get(i));
}
}
use of java.util.BitSet in project j2objc by google.
the class BitSetTest method test_hashCode.
public void test_hashCode() {
BitSet bs = (BitSet) eightbs.clone();
bs.clear(2);
bs.clear(6);
assertEquals("BitSet returns wrong hash value", 1129, bs.hashCode());
bs.set(10);
bs.clear(3);
assertEquals("BitSet returns wrong hash value", 97, bs.hashCode());
}
use of java.util.BitSet in project j2objc by google.
the class BitSetTest method test_31036_clear.
// http://code.google.com/p/android/issues/detail?id=31036
public void test_31036_clear() {
BitSet bs = new BitSet(500);
for (int i = 0; i < 500; ++i) {
int nextClear = bs.nextClearBit(0);
assertEquals(i, nextClear);
bs.set(i);
}
}
Aggregations