Search in sources :

Example 36 with BitSet

use of java.util.BitSet in project j2objc by google.

the class BitSetTest method test_xorLjava_util_BitSet.

public void test_xorLjava_util_BitSet() {
    BitSet bs = (BitSet) eightbs.clone();
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR failed to clear bit " + i + bs, !bs.get(i));
    }
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR failed to set bit " + i + bs, bs.get(i));
    }
    bs = new BitSet(0);
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR(0) failed to set bit " + i + bs, bs.get(i));
    }
    bs = new BitSet();
    bs.set(63);
    assertEquals("{63}", bs.toString());
}
Also used : BitSet(java.util.BitSet)

Example 37 with BitSet

use of java.util.BitSet in project j2objc by google.

the class BitSetTest method test_setII.

public void test_setII() {
    BitSet bitset = new BitSet(30);
    bitset.set(29, 29);
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    bs.set(5);
    bs.set(15);
    bs.set(7, 11);
    assertEquals("{5, 7, 8, 9, 10, 15}", bs.toString());
    for (int i = 16; i < bs.size(); i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    bs.set(7, 64);
    assertEquals("Failed to grow BitSet", 64, bs.size());
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 7; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    // more boundary testing
    bs = new BitSet(32);
    bs.set(0, 64);
    for (int i = 0; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    bs = new BitSet(32);
    bs.set(0, 65);
    for (int i = 0; i < 65; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 65", bs.get(65));
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    bs.set(7);
    bs.set(110);
    bs.set(9, 74);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 74; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    for (int i = 74; i < bs.size(); i++) {
        if (i == 110) {
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(7);
    bs.set(255);
    bs.set(9, 219);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertTrue("Shouldn't have set flipped " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 219; i++) {
        assertTrue("failed to set bit " + i, bs.get(i));
    }
    for (int i = 219; i < 255; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 255", bs.get(255));
    // test illegal args
    bs = new BitSet(10);
    try {
        bs.set(-1, 3);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.set(2, -1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    bs.set(2, 2);
    assertFalse("Bit got set incorrectly ", bs.get(2));
    try {
        bs.set(4, 2);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : BitSet(java.util.BitSet)

Example 38 with BitSet

use of java.util.BitSet in project j2objc by google.

the class BitSetTest method test_ConstructorI.

public void test_ConstructorI() {
    BitSet bs = new BitSet(128);
    // Default size for a BitSet should be 64 elements;
    assertEquals("Created BitSet of incorrect size", 128, bs.size());
    assertTrue("New BitSet had invalid string representation: " + bs.toString(), bs.toString().equals("{}"));
    // All BitSets are created with elements of multiples of 64
    bs = new BitSet(89);
    assertEquals("Failed to round BitSet element size", 128, bs.size());
    try {
        bs = new BitSet(-9);
        fail();
    } catch (NegativeArraySizeException expected) {
    }
}
Also used : BitSet(java.util.BitSet)

Example 39 with BitSet

use of java.util.BitSet in project j2objc by google.

the class BitSetTest method test_andNotLjava_util_BitSet.

public void test_andNotLjava_util_BitSet() {
    BitSet bs = (BitSet) eightbs.clone();
    bs.clear(5);
    BitSet bs2 = new BitSet();
    bs2.set(2);
    bs2.set(3);
    bs.andNot(bs2);
    assertEquals("Incorrect bitset after andNot", "{0, 1, 4, 6, 7}", bs.toString());
    bs = new BitSet(0);
    bs.andNot(bs2);
    assertEquals("Incorrect size", 0, bs.size());
}
Also used : BitSet(java.util.BitSet)

Example 40 with BitSet

use of java.util.BitSet in project j2objc by google.

the class BitSetTest method test_clearI.

public void test_clearI() {
    eightbs.clear(7);
    assertFalse("Failed to clear bit", eightbs.get(7));
    // Check to see all other bits are still set
    for (int i = 0; i < 7; i++) assertTrue("Clear cleared incorrect bits", eightbs.get(i));
    eightbs.clear(165);
    assertFalse("Failed to clear bit", eightbs.get(165));
    // Try out of range
    try {
        eightbs.clear(-1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    BitSet bs = new BitSet(0);
    assertEquals("Test1: Wrong length,", 0, bs.length());
    assertEquals("Test1: Wrong size,", 0, bs.size());
    bs.clear(0);
    assertEquals("Test2: Wrong length,", 0, bs.length());
    assertEquals("Test2: Wrong size,", 0, bs.size());
    bs.clear(60);
    assertEquals("Test3: Wrong length,", 0, bs.length());
    assertEquals("Test3: Wrong size,", 0, bs.size());
    bs.clear(120);
    assertEquals("Test4: Wrong size,", 0, bs.size());
    assertEquals("Test4: Wrong length,", 0, bs.length());
    bs.set(25);
    assertEquals("Test5: Wrong size,", 64, bs.size());
    assertEquals("Test5: Wrong length,", 26, bs.length());
    bs.clear(80);
    assertEquals("Test6: Wrong size,", 64, bs.size());
    assertEquals("Test6: Wrong length,", 26, bs.length());
    bs.clear(25);
    assertEquals("Test7: Wrong size,", 64, bs.size());
    assertEquals("Test7: Wrong length,", 0, bs.length());
}
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