commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevencasw...@apache.org
Subject svn commit: r234399 - /jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java
Date Mon, 22 Aug 2005 00:50:00 GMT
Author: stevencaswell
Date: Sun Aug 21 17:49:57 2005
New Revision: 234399

URL: http://svn.apache.org/viewcvs?rev=234399&view=rev
Log:
increase BitField test coverage as reported by clover

Modified:
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java?rev=234399&r1=234398&r2=234399&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/BitFieldTest.java Sun
Aug 21 17:49:57 2005
@@ -42,6 +42,7 @@
 
     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 @@
         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 @@
         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 @@
         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 @@
         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 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 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 @@
             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 @@
             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 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 @@
         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 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 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 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 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 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 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));
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message