Search in sources :

Example 31 with BitSet

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) {
    }
}
Also used : BitSet(java.util.BitSet)

Example 32 with BitSet

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));
}
Also used : BitSet(java.util.BitSet)

Example 33 with BitSet

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));
    }
}
Also used : BitSet(java.util.BitSet)

Example 34 with BitSet

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());
}
Also used : BitSet(java.util.BitSet)

Example 35 with BitSet

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);
    }
}
Also used : BitSet(java.util.BitSet)

Aggregations

BitSet (java.util.BitSet)1018 Test (org.junit.Test)129 ArrayList (java.util.ArrayList)112 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)45 List (java.util.List)38 Map (java.util.Map)33 HashMap (java.util.HashMap)30 HashSet (java.util.HashSet)29 IOException (java.io.IOException)24 Random (java.util.Random)24 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)22 Cursor (android.database.Cursor)20 MatrixCursor (android.database.MatrixCursor)20 MergeCursor (android.database.MergeCursor)20 DirectoryResult (com.android.documentsui.DirectoryResult)20 LinkedList (java.util.LinkedList)20 Iterator (java.util.Iterator)14 File (java.io.File)13 BlockNode (jadx.core.dex.nodes.BlockNode)12 BitSetGroup (org.apache.carbondata.core.util.BitSetGroup)12