You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/03/20 17:31:33 UTC

svn commit: r387239 [19/21] - in /incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math: ./ Harmony/ doc/ doc/images/ make/ src/ src/common/ src/common/javasrc/ src/common/javasrc/java/ src/common/javasrc/java/applet/ src/common/javasrc/ja...

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerHashCodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerHashCodeTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerHashCodeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerHashCodeTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,98 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.3.6.2 $
+ */
+
+package java.math;
+
+import java.math.BigInteger;
+
+import junit.framework.TestCase;
+
+/**
+ * Class:   java.math.BigInteger
+ * Method: hashCode()
+ */
+public class BigIntegerHashCodeTest extends TestCase {
+    /**
+     * Test hash codes for the same object
+     */
+    public void testSameObject() {
+        String value1 = "12378246728727834290276457386374882976782849";
+        String value2 = "-5634562095872038262928728727834290276457386374882976782849";
+        BigInteger aNumber1 = new BigInteger(value1);
+        BigInteger aNumber2 = new BigInteger(value2);
+        int code1 = aNumber1.hashCode();
+        aNumber1.add(aNumber2).shiftLeft(125);
+        aNumber1.subtract(aNumber2).shiftRight(125);
+        aNumber1.multiply(aNumber2).toByteArray();
+        aNumber1.divide(aNumber2).bitLength();
+        aNumber1.gcd(aNumber2).pow(7);
+        int code2 = aNumber1.hashCode();
+        assertTrue("hash codes for the same object differ", code1 == code2);
+    }
+
+    /**
+     * Test hash codes for equal objects.
+     */
+    public void testEqualObjects() {
+        String value1 = "12378246728727834290276457386374882976782849";
+        String value2 = "12378246728727834290276457386374882976782849";
+        BigInteger aNumber1 = new BigInteger(value1);
+        BigInteger aNumber2 = new BigInteger(value2);
+        int code1 = aNumber1.hashCode();
+        int code2 = aNumber2.hashCode();
+        if (aNumber1.equals(aNumber2)) {
+            assertTrue("hash codes for equal objects are unequal", code1 == code2);
+        }
+    }
+
+    /**
+     * Test hash codes for unequal objects.
+     * The codes are unequal.
+     */
+    public void testUnequalObjectsUnequal() {
+        String value1 = "12378246728727834290276457386374882976782849";
+        String value2 = "-5634562095872038262928728727834290276457386374882976782849";
+        BigInteger aNumber1 = new BigInteger(value1);
+        BigInteger aNumber2 = new BigInteger(value2);
+        int code1 = aNumber1.hashCode();
+        int code2 = aNumber2.hashCode();
+        if (!aNumber1.equals(aNumber2)) {
+            assertTrue("hash codes for unequal objects are equal", code1 != code2);
+        }
+    }
+    
+    /**
+     * Test hash codes for unequal objects.
+     * The codes are equal.
+     */
+    public void testUnequalObjectsEqual() {
+        byte aBytes[] = {56, 100, -2, -76, 98, 54, 19, 3, -15, 45, 89, -111, 69, 103, 8, -9};
+        byte bBytes[] = {56, 100, -2, -76, 89, 45, 91, 3, -15, 45, 89, -111, 69, 103, 8, -9};
+        int aSign = 1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(aSign, bBytes);
+        int code1 = aNumber.hashCode();
+        int code2 = bNumber.hashCode();
+        if (!aNumber.equals(bNumber)) {
+            assertTrue("hash codes for these unequal objects should be equal", code1 == code2);
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerModPowTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerModPowTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerModPowTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerModPowTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,324 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.5.2.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:   java.math.BigInteger
+ * Methods: modPow, modInverse, and gcd 
+ */
+public class BigIntegerModPowTest extends TestCase {
+	/**
+	 * modPow: non-positive modulus
+	 */
+	public void testModPowException() {
+		byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+		byte eBytes[] = {1, 2, 3, 4, 5};
+		byte mBytes[] = {1, 2, 3};
+		int aSign = 1;
+		int eSign = 1;		
+		int mSign = -1;		
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger exp = new BigInteger(eSign, eBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		try {
+			BigInteger result = aNumber.modPow(exp, modulus);
+			fail("ArithmeticException has not been caught");
+		} catch (ArithmeticException e) {
+			assertTrue("Improper exception message", e.getMessage().equals("non-positive modulus"));
+		}
+	}
+
+	/**
+	 * modPow: positive exponent
+	 */
+	public void testModPowPosExp() {
+		byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75, 48, -7};
+		byte eBytes[] = {27, -15, 65, 39};
+		byte mBytes[] = {-128, 2, 3, 4, 5};
+		int aSign = 1;
+		int eSign = 1;		
+		int mSign = 1;		
+		byte rBytes[] = {113, 100, -84, -28, -85};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger exp = 	 new BigInteger(eSign, eBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		BigInteger result = aNumber.modPow(exp, modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+	
+	/**
+	 * modPow: negative exponent
+	 */
+	public void testModPowNegExp() {
+		byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75, 48, -7};
+		byte eBytes[] = {27, -15, 65, 39};
+		byte mBytes[] = {-128, 2, 3, 4, 5};
+		int aSign = 1;
+		int eSign = -1;		
+		int mSign = 1;		
+		byte rBytes[] = {12, 118, 46, 86, 92};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger exp = 	 new BigInteger(eSign, eBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		BigInteger result = aNumber.modPow(exp, modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * modInverse: non-positive modulus
+	 */
+	public void testmodInverseException() {
+		byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+		byte mBytes[] = {1, 2, 3};
+		int aSign = 1;
+		int mSign = -1;		
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		try {
+			BigInteger result = aNumber.modInverse(modulus);
+			fail("ArithmeticException has not been caught");
+		} catch (ArithmeticException e) {
+			assertTrue("Improper exception message", e.getMessage().equals("non-positive modulus"));
+		}
+	}
+	
+	/**
+	 * modInverse: non-invertible number
+	 */
+	public void testmodInverseNonInvertible() {
+		byte aBytes[] = {-15, 24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		byte mBytes[] = {-12, 1, 0, 0, 0, 23, 44, 55, 66};
+		int aSign = 1;
+		int mSign = 1;		
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		try {
+			BigInteger result = aNumber.modInverse(modulus);
+			fail("ArithmeticException has not been caught");
+		} catch (ArithmeticException e) {
+			assertTrue("Improper exception message", e.getMessage().equals("non-invertible BigInteger"));
+		}
+	}
+
+	/**
+	 * modInverse: positive number
+	 */
+	public void testmodInversePos1() {
+		byte aBytes[] = {24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		byte mBytes[] = {122, 45, 36, 100, 122, 45};
+		int aSign = 1;
+		int mSign = 1;		
+		byte rBytes[] = {47, 3, 96, 62, 87, 19};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		BigInteger result = aNumber.modInverse(modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * modInverse: positive number (another case: a < 0)
+	 */
+	public void testmodInversePos2() {
+		byte aBytes[] = {15, 24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		byte mBytes[] = {2, 122, 45, 36, 100};
+		int aSign = 1;
+		int mSign = 1;		
+		byte rBytes[] = {1, -93, 40, 127, 73};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		BigInteger result = aNumber.modInverse(modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * modInverse: negative number
+	 */
+	public void testmodInverseNeg1() {
+		byte aBytes[] = {15, 24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		byte mBytes[] = {2, 122, 45, 36, 100};
+		int aSign = -1;
+		int mSign = 1;		
+		byte rBytes[] = {0, -41, 4, -91, 27};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger modulus = new BigInteger(mSign, mBytes);
+		BigInteger result = aNumber.modInverse(modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * modInverse: negative number (another case: x < 0)
+	 */
+	public void testmodInverseNeg2() {
+		byte aBytes[] = {-15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		byte mBytes[] = {122, 2, 4, 122, 2, 4};
+		byte rBytes[] = {85, 47, 127, 4, -128, 45};
+		BigInteger aNumber = new BigInteger(aBytes);
+		BigInteger modulus = new BigInteger(mBytes);
+		BigInteger result = aNumber.modInverse(modulus);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+	
+	/**
+	 * gcd: the second number is zero
+	 */
+	public void testGcdSecondZero() {
+		byte aBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		byte bBytes[] = {0};
+		int aSign = 1;
+		int bSign = 1;
+		byte rBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger bNumber = new BigInteger(bSign, bBytes);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * gcd: the first number is zero
+	 */
+	public void testGcdFirstZero() {
+		byte aBytes[] = {0};
+		byte bBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		int aSign = 1;
+		int bSign = 1;
+		byte rBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger bNumber = new BigInteger(bSign, bBytes);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+	
+	/**
+	 * gcd: the first number is ZERO
+	 */
+	public void testGcdFirstZERO() {
+		byte bBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		int bSign = 1;
+		byte rBytes[] = {15, 24, 123, 57, -15, 24, 123, 57, -15, 24, 123, 57};
+		BigInteger aNumber = BigInteger.ZERO;
+		BigInteger bNumber = new BigInteger(bSign, bBytes);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * gcd: both numbers are zeros
+	 */
+	public void testGcdBothZeros() {
+		byte rBytes[] = {0};
+		BigInteger aNumber = new BigInteger("0");
+		BigInteger bNumber = BigInteger.valueOf(0L);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 0);
+	}
+
+	/**
+	 * gcd: the first number is longer
+	 */
+	public void testGcdFirstLonger() {
+		byte aBytes[] = {-15, 24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		byte bBytes[] = {-12, 1, 0, 0, 0, 23, 44, 55, 66};
+		int aSign = 1;
+		int bSign = 1;
+		byte rBytes[] = {7};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger bNumber = new BigInteger(bSign, bBytes);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+
+	/**
+	 * gcd: the second number is longer
+	 */
+	public void testGcdSecondLonger() {
+		byte aBytes[] = {-12, 1, 0, 0, 0, 23, 44, 55, 66};
+		byte bBytes[] = {-15, 24, 123, 56, -11, -112, -34, -98, 8, 10, 12, 14, 25, 125, -15, 28, -127};
+		int aSign = 1;
+		int bSign = 1;
+		byte rBytes[] = {7};
+		BigInteger aNumber = new BigInteger(aSign, aBytes);
+		BigInteger bNumber = new BigInteger(bSign, bBytes);
+		BigInteger result = aNumber.gcd(bNumber);
+		byte resBytes[] = new byte[rBytes.length];
+		resBytes = result.toByteArray();
+		for(int i = 0; i < resBytes.length; i++) {
+			assertTrue(resBytes[i] == rBytes[i]);
+		}
+		assertTrue("incorrect sign", result.signum() == 1);
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerMultiplyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerMultiplyTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerMultiplyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerMultiplyTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,389 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.6.2.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Method: multiply 
+ */
+public class BigIntegerMultiplyTest extends TestCase {
+    /**
+     * Multiply two negative numbers of the same length
+     */
+    public void testCase1() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 105, 4, 28, -86, -117, -52, 100, 120, 90};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two numbers of the same length and different signs.
+     * The first is negative.
+     */
+    public void testCase2() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -106, -5, -29, 85, 116, 51, -101, -121, -90};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply two positive numbers of different length.
+     * The first is longer.
+     */
+    public void testCase3() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
+                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two positive numbers of different length.
+     * The second is longer.
+     */
+    public void testCase4() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
+                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two numbers of different length and different signs.
+     * The first is positive.
+     * The first is longer.
+     */
+    public void testCase5() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
+                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply two numbers of different length and different signs.
+     * The first is positive.
+     * The second is longer.
+     */
+    public void testCase6() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
+                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply a number by zero.
+     */
+    public void testCase7() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {0};
+        int aSign = 1;
+        int bSign = 0;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * Multiply a number by ZERO.
+     */
+    public void testCase8() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * Multiply a positive number by ONE.
+     */
+    public void testCase9() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply a negative number by ONE.
+     */
+    public void testCase10() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = -1;
+        byte rBytes[] = {-2, -3, -4, -5, -6, -7, -8, -2, -3, -4, -2, -3, -4, -5, -5};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+    
+    /**
+     * Multiply two numbers of 4 bytes length.
+     */
+    public void testIntbyInt1() {
+        byte aBytes[] = {10, 20, 30, 40};
+        byte bBytes[] = {1, 2, 3, 4};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 55, 5, 15, 96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+    
+    /**
+     * Multiply two numbers of 4 bytes length.
+     */
+    public void testIntbyInt2() {
+        byte aBytes[] = {-1, -1, -1, -1};
+        byte bBytes[] = {-1, -1, -1, -1};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -1, -1, -1, -2, 0, 0, 0, 1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+    
+    /**
+     * Negative exponent.
+     */
+    public void testPowException() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int exp = -5;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            BigInteger result = aNumber.pow(exp);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("exponent is negative"));
+        }
+    }
+
+    /**
+     * Exponentiation of a negative number to an odd exponent.
+     */
+    public void testPowNegativeNumToOddExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 5;
+        byte rBytes[] = {-21, -94, -42, -15, -127, 113, -50, -88, 115, -35, 3,
+            59, -92, 111, -75, 103, -42, 41, 34, -114, 99, -32, 105, -59, 127,
+            45, 108, 74, -93, 105, 33, 12, -5, -20, 17, -21, -119, -127, -115,
+            27, -122, 26, -67, 109, -125, 16, 91, -70, 109};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Exponentiation of a negative number to an even exponent.
+     */
+    public void testPowNegativeNumToEvenExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 4;
+        byte rBytes[] = {102, 107, -122, -43, -52, -20, -27, 25, -9, 88, -13,
+            75, 78, 81, -33, -77, 39, 27, -37, 106, 121, -73, 108, -47, -101,
+            80, -25, 71, 13, 94, -7, -33, 1, -17, -65, -70, -61, -3, -47};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a negative number to zero exponent.
+     */
+    public void testPowNegativeNumToZeroExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a positive number.
+     */
+    public void testPowPositiveNum() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = 1;
+        int exp = 5;
+        byte rBytes[] = {20, 93, 41, 14, 126, -114, 49, 87, -116, 34, -4, -60,
+            91, -112, 74, -104, 41, -42, -35, 113, -100, 31, -106, 58, -128,
+            -46, -109, -75, 92, -106, -34, -13, 4, 19, -18, 20, 118, 126, 114,
+            -28, 121, -27, 66, -110, 124, -17, -92, 69, -109};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a negative number to zero exponent.
+     */
+    public void testPowPositiveNumToZeroExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = 1;
+        int exp = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerNotTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerNotTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerNotTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerNotTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,192 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.3.6.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Methods: and, andNot
+ */
+public class BigIntegerNotTest extends TestCase {
+    /**
+     * andNot for two positive numbers; the first is longer
+     */
+    public void testAndNotPosPosFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82, -31, -96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for two positive numbers; the first is shorter
+     */
+    public void testAndNotPosPosFirstShorter() {
+        byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        byte bBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for two negative numbers; the first is longer
+     */
+    public void testAndNotNegNegFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for a negative and a positive numbers; the first is longer
+     */
+    public void testNegPosFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23, 87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-1, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68, -88, -88, 16, 72};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for ZERO 
+     */
+    public void testNotZero() {
+        byte rBytes[] = {-1};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for ONE
+     */
+    public void testNotOne() {
+        byte rBytes[] = {-2};
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for a positive number
+     */
+    public void testNotPos() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        int aSign = 1;
+        byte rBytes[] = {-1, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -27, 116};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for a negative number
+     */
+    public void testNotNeg() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        int aSign = -1;
+        byte rBytes[] = {0, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -118};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Not for a negative number
+     */
+
+    public void testNotSpecialCase() {
+        byte aBytes[] = {-1, -1, -1, -1};
+        int aSign = 1;
+        byte rBytes[] = {-1, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+}
\ No newline at end of file