increase BitField test coverage as reported by clover
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@234399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
890501b707
commit
2390bb5c40
|
@ -42,6 +42,7 @@ public class BitFieldTest extends TestCase {
|
|||
|
||||
private static BitField bf_multi = new BitField(0x3F80);
|
||||
private static BitField bf_single = new BitField(0x4000);
|
||||
private static BitField bf_zero = new BitField(0);
|
||||
|
||||
/**
|
||||
* Constructor BitFieldTest
|
||||
|
@ -60,6 +61,8 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getValue(0), 0);
|
||||
assertEquals(bf_single.getValue(-1), 1);
|
||||
assertEquals(bf_single.getValue(0), 0);
|
||||
assertEquals(bf_zero.getValue(-1), 0);
|
||||
assertEquals(bf_zero.getValue(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,6 +73,8 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getShortValue((short) 0), (short) 0);
|
||||
assertEquals(bf_single.getShortValue((short) - 1), (short) 1);
|
||||
assertEquals(bf_single.getShortValue((short) 0), (short) 0);
|
||||
assertEquals(bf_zero.getShortValue((short) -1), (short) 0);
|
||||
assertEquals(bf_zero.getShortValue((short) 0), (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,6 +85,8 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getRawValue(0), 0);
|
||||
assertEquals(bf_single.getRawValue(-1), 0x4000);
|
||||
assertEquals(bf_single.getRawValue(0), 0);
|
||||
assertEquals(bf_zero.getRawValue(-1), 0);
|
||||
assertEquals(bf_zero.getRawValue(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,6 +97,8 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getShortRawValue((short) 0), (short) 0);
|
||||
assertEquals(bf_single.getShortRawValue((short) - 1), (short) 0x4000);
|
||||
assertEquals(bf_single.getShortRawValue((short) 0), (short) 0);
|
||||
assertEquals(bf_zero.getShortRawValue((short) -1), (short) 0);
|
||||
assertEquals(bf_zero.getShortRawValue((short) 0), (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,9 +106,13 @@ public class BitFieldTest extends TestCase {
|
|||
*/
|
||||
public void testIsSet() {
|
||||
assertTrue(!bf_multi.isSet(0));
|
||||
assertTrue(!bf_zero.isSet(0));
|
||||
for (int j = 0x80; j <= 0x3F80; j += 0x80) {
|
||||
assertTrue(bf_multi.isSet(j));
|
||||
}
|
||||
for (int j = 0x80; j <= 0x3F80; j += 0x80) {
|
||||
assertTrue(!bf_zero.isSet(j));
|
||||
}
|
||||
assertTrue(!bf_single.isSet(0));
|
||||
assertTrue(bf_single.isSet(0x4000));
|
||||
}
|
||||
|
@ -110,6 +123,7 @@ public class BitFieldTest extends TestCase {
|
|||
public void testIsAllSet() {
|
||||
for (int j = 0; j < 0x3F80; j += 0x80) {
|
||||
assertTrue(!bf_multi.isAllSet(j));
|
||||
assertTrue(!bf_zero.isAllSet(j));
|
||||
}
|
||||
assertTrue(bf_multi.isAllSet(0x3F80));
|
||||
assertTrue(!bf_single.isAllSet(0));
|
||||
|
@ -124,6 +138,10 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getValue(bf_multi.setValue(0, j)), j);
|
||||
assertEquals(bf_multi.setValue(0, j), j << 7);
|
||||
}
|
||||
for (int j = 0; j < 128; j++) {
|
||||
assertEquals(bf_zero.getValue(bf_zero.setValue(0, j)), 0);
|
||||
assertEquals(bf_zero.setValue(0, j), 0);
|
||||
}
|
||||
|
||||
// verify that excess bits are stripped off
|
||||
assertEquals(bf_multi.setValue(0x3f80, 128), 0);
|
||||
|
@ -144,6 +162,10 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(bf_multi.getShortValue(bf_multi.setShortValue((short) 0, (short) j)), (short) j);
|
||||
assertEquals(bf_multi.setShortValue((short) 0, (short) j), (short) (j << 7));
|
||||
}
|
||||
for (int j = 0; j < 128; j++) {
|
||||
assertEquals(bf_zero.getShortValue(bf_zero.setShortValue((short) 0, (short) j)), (short) 0);
|
||||
assertEquals(bf_zero.setShortValue((short) 0, (short) j), (short) (0));
|
||||
}
|
||||
|
||||
// verify that excess bits are stripped off
|
||||
assertEquals(bf_multi.setShortValue((short) 0x3f80, (short) 128), (short) 0);
|
||||
|
@ -157,6 +179,7 @@ public class BitFieldTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testByte() {
|
||||
assertEquals(0, new BitField(0).setByteBoolean((byte) 0, true));
|
||||
assertEquals(1, new BitField(1).setByteBoolean((byte) 0, true));
|
||||
assertEquals(2, new BitField(2).setByteBoolean((byte) 0, true));
|
||||
assertEquals(4, new BitField(4).setByteBoolean((byte) 0, true));
|
||||
|
@ -165,6 +188,7 @@ public class BitFieldTest extends TestCase {
|
|||
assertEquals(32, new BitField(32).setByteBoolean((byte) 0, true));
|
||||
assertEquals(64, new BitField(64).setByteBoolean((byte) 0, true));
|
||||
assertEquals(-128, new BitField(128).setByteBoolean((byte) 0, true));
|
||||
assertEquals(1, new BitField(0).setByteBoolean((byte) 1, false));
|
||||
assertEquals(0, new BitField(1).setByteBoolean((byte) 1, false));
|
||||
assertEquals(0, new BitField(2).setByteBoolean((byte) 2, false));
|
||||
assertEquals(0, new BitField(4).setByteBoolean((byte) 4, false));
|
||||
|
@ -185,6 +209,7 @@ public class BitFieldTest extends TestCase {
|
|||
public void testClear() {
|
||||
assertEquals(bf_multi.clear(-1), 0xFFFFC07F);
|
||||
assertEquals(bf_single.clear(-1), 0xFFFFBFFF);
|
||||
assertEquals(bf_zero.clear(-1), 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,6 +218,7 @@ public class BitFieldTest extends TestCase {
|
|||
public void testClearShort() {
|
||||
assertEquals(bf_multi.clearShort((short) - 1), (short) 0xC07F);
|
||||
assertEquals(bf_single.clearShort((short) - 1), (short) 0xBFFF);
|
||||
assertEquals(bf_zero.clearShort((short) -1), (short) 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,6 +227,7 @@ public class BitFieldTest extends TestCase {
|
|||
public void testSet() {
|
||||
assertEquals(bf_multi.set(0), 0x3F80);
|
||||
assertEquals(bf_single.set(0), 0x4000);
|
||||
assertEquals(bf_zero.set(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,6 +236,7 @@ public class BitFieldTest extends TestCase {
|
|||
public void testSetShort() {
|
||||
assertEquals(bf_multi.setShort((short) 0), (short) 0x3F80);
|
||||
assertEquals(bf_single.setShort((short) 0), (short) 0x4000);
|
||||
assertEquals(bf_zero.setShort((short) 0), (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,8 +245,10 @@ public class BitFieldTest extends TestCase {
|
|||
public void testSetBoolean() {
|
||||
assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true));
|
||||
assertEquals(bf_single.set(0), bf_single.setBoolean(0, true));
|
||||
assertEquals(bf_zero.set(0), bf_zero.setBoolean(0, true));
|
||||
assertEquals(bf_multi.clear(-1), bf_multi.setBoolean(-1, false));
|
||||
assertEquals(bf_single.clear(-1), bf_single.setBoolean(-1, false));
|
||||
assertEquals(bf_zero.clear(-1), bf_zero.setBoolean(-1, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,8 +257,10 @@ public class BitFieldTest extends TestCase {
|
|||
public void testSetShortBoolean() {
|
||||
assertEquals(bf_multi.setShort((short) 0), bf_multi.setShortBoolean((short) 0, true));
|
||||
assertEquals(bf_single.setShort((short) 0), bf_single.setShortBoolean((short) 0, true));
|
||||
assertEquals(bf_zero.setShort((short) 0), bf_zero.setShortBoolean((short) 0, true));
|
||||
assertEquals(bf_multi.clearShort((short) - 1), bf_multi.setShortBoolean((short) - 1, false));
|
||||
assertEquals(bf_single.clearShort((short) - 1), bf_single.setShortBoolean((short) - 1, false));
|
||||
assertEquals(bf_zero.clearShort((short) -1), bf_zero.setShortBoolean((short) -1, false));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue