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 [21/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/BigIntegerSubtractTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,547 @@
+/*
+ *  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.4.6.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Method: subtract 
+ */
+public class BigIntegerSubtractTest extends TestCase {
+    /**
+     * Subtract two positive numbers of the same length.
+     * The first is greater.
+     */
+    public void testCase1() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {9, 18, 27, 36, 45, 54, 63, 9, 18, 27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract two positive numbers of the same length.
+     * The second is greater.
+     */
+    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[] = {-10, -19, -28, -37, -46, -55, -64, -10, -19, -27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is positive.
+     * The first is greater in absolute value.
+     */
+    public void testCase3() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {11, 22, 33, 44, 55, 66, 77, 11, 22, 33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is positive.
+     * The second is greater in absolute value.
+     */
+    public void testCase4() {
+        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, 22, 33, 44, 55, 66, 77, 11, 22, 33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract two negative numbers of the same length.
+     * The first is greater in absolute value.
+     */
+    public void testCase5() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-10, -19, -28, -37, -46, -55, -64, -10, -19, -27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two negative numbers of the same length.
+     * The second is greater in absolute value.
+     */
+    public void testCase6() {
+        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[] = {9, 18, 27, 36, 45, 54, 63, 9, 18, 27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is negative.
+     * The first is greater in absolute value.
+     */
+    public void testCase7() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-12, -23, -34, -45, -56, -67, -78, -12, -23, -33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is negative.
+     * The second is greater in absolute value.
+     */
+    public void testCase8() {
+        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[] = {-12, -23, -34, -45, -56, -67, -78, -12, -23, -33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+    
+    /**
+     * Subtract two positive numbers of different length.
+     * The first is longer.
+     */
+    public void testCase9() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67, -6, -15, -23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+    
+    /**
+     * Subtract two positive numbers of different length.
+     * The second is longer.
+     */
+    public void testCase10() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two numbers of different length and different signs.
+     * The first is positive.
+     * The first is greater in absolute value.
+     */
+    public void testCase11() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15, 26, 37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is positive.
+     * The second is greater in absolute value.
+     */
+    public void testCase12() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15, 26, 37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+    
+    /**
+     * Subtract two numbers of different length and different signs.
+     * The first is negative.
+     * The first is longer.
+     */
+    public void testCase13() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-2, -3, -4, -5, -16, -27, -38, -42, -53, -64, -75, -16, -27, -37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two numbers of the same length and different signs.
+     * The first is negative.
+     * The second is longer.
+     */
+    public void testCase14() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-2, -3, -4, -5, -16, -27, -38, -42, -53, -64, -75, -16, -27, -37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+
+    /**
+     * Subtract two negative numbers of different length.
+     * The first is longer.
+     */
+    public void testCase15() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+}
+    
+    /**
+     * Subtract two negative numbers of different length.
+     * The second is longer.
+     */
+    public void testCase16() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67, -6, -15, -23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+    
+    /**
+     * Subtract two positive equal in absolute value numbers.
+     */
+    public void testCase17() {
+        byte aBytes[] = {-120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte bBytes[] = {-120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte rBytes[] = {0};
+        int aSign = 1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 0);
+    }
+
+    /**
+     * Subtract zero from a number.
+     * The number is positive.
+     */
+    public void testCase18() {
+        byte aBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte bBytes[] = {0};
+        byte rBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        int aSign = 1;
+        int bSign = 0;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract a number from zero.
+     * The number is negative.
+     */
+    public void testCase19() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte rBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        int aSign = 0;
+        int bSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract zero from zero.
+     */
+    public void testCase20() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {0};
+        byte rBytes[] = {0};
+        int aSign = 0;
+        int bSign = 0;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 0);
+    }
+    
+    /**
+     * Subtract ZERO from a number.
+     * The number is positive.
+     */
+    public void testCase21() {
+        byte aBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte rBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract a number from ZERO.
+     * The number is negative.
+     */
+    public void testCase22() {
+        byte bBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        byte rBytes[] = {120, 34, 78, -23, -111, 45, 127, 23, 45, -3};
+        int bSign = -1;
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 1);
+    }
+
+    /**
+     * Subtract ZERO from ZERO.
+     */
+    public void testCase23() {
+        byte rBytes[] = {0};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 0);
+    }
+
+    /**
+     * Subtract ONE from ONE.
+     */
+    public void testCase24() {
+        byte rBytes[] = {0};
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == 0);
+    }
+
+    /**
+     * Subtract two numbers so that borrow is 1.
+     */
+    public void testCase25() {
+        byte aBytes[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+        byte bBytes[] = {-128, -128, -128, -128, -128, -128, -128, -128, -128};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {-128, 127, 127, 127, 127, 127, 127, 127, 127};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.subtract(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue(result.signum() == -1);
+    }
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerToStringTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerToStringTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerToStringTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerToStringTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,152 @@
+/*
+ *  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: toString(int radix)
+ */
+public class BigIntegerToStringTest extends TestCase {
+    /**
+     * If 36 < radix < 2 it should be set to 10
+     */
+    public void testRadixOutOfRange() {
+        String value = "442429234853876401";
+        int radix = 10;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(45);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test negative number of radix 2
+     */
+    public void testRadix2Neg() {
+        String value = "-101001100010010001001010101110000101010110001010010101010101010101010101010101010101010101010010101";
+        int radix = 2;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test positive number of radix 2
+     */
+    public void testRadix2Pos() {
+        String value = "101000011111000000110101010101010101010001001010101010101010010101010101010000100010010";
+        int radix = 2;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test negative number of radix 10
+     */
+    public void testRadix10Neg() {
+        String value = "-2489756308572364789878394872984";
+        int radix = 16;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test positive number of radix 10
+     */
+    public void testRadix10Pos() {
+        String value = "2387627892347567398736473476";
+        int radix = 16;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test negative number of radix 16
+     */
+    public void testRadix16Neg() {
+        String value = "-287628a883451b800865c67e8d7ff20";
+        int radix = 16;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test positive number of radix 16
+     */
+    public void testRadix16Pos() {
+        String value = "287628a883451b800865c67e8d7ff20";
+        int radix = 16;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test negative number of radix 24
+     */
+    public void testRadix24Neg() {
+        String value = "-287628a88gmn3451b8ijk00865c67e8d7ff20";
+        int radix = 24;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test positive number of radix 24
+     */
+    public void testRadix24Pos() {
+        String value = "287628a883451bg80ijhk0865c67e8d7ff20";
+        int radix = 24;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test negative number of radix 24
+     */
+    public void testRadix36Neg() {
+        String value = "-uhguweut98iu4h3478tq3985pq98yeiuth33485yq4aiuhalai485yiaehasdkr8tywi5uhslei8";
+        int radix = 36;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+
+    /**
+     * test positive number of radix 24
+     */
+    public void testRadix36Pos() {
+        String value = "23895lt45y6vhgliuwhgi45y845htsuerhsi4586ysuerhtsio5y68peruhgsil4568ypeorihtse48y6";
+        int radix = 36;
+        BigInteger aNumber = new BigInteger(value, radix);
+        String result = aNumber.toString(radix);
+        assertTrue(result.equals(value));
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerXorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerXorTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerXorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerXorTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,277 @@
+/*
+ *  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
+ * Method: xor
+ */
+public class BigIntegerXorTest extends TestCase {
+	/**
+     * Xor for zero and a positive number
+     */
+    public void testZeroPos() {
+        String numA = "0";
+        String numB = "27384627835298756289327365";
+        String res = "27384627835298756289327365";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for zero and a negative number
+     */
+    public void testZeroNeg() {
+        String numA = "0";
+        String numB = "-27384627835298756289327365";
+        String res = "-27384627835298756289327365";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for a positive number and zero 
+     */
+    public void testPosZero() {
+        String numA = "27384627835298756289327365";
+        String numB = "0";
+        String res = "27384627835298756289327365";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for a negative number and zero  
+     */
+    public void testNegPos() {
+        String numA = "-27384627835298756289327365";
+        String numB = "0";
+        String res = "-27384627835298756289327365";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for zero and zero
+     */
+    public void testZeroZero() {
+        String numA = "0";
+        String numB = "0";
+        String res = "0";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for zero and one
+     */
+    public void testZeroOne() {
+        String numA = "0";
+        String numB = "1";
+        String res = "1";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for one and one
+     */
+    public void testOneOne() {
+        String numA = "1";
+        String numB = "1";
+        String res = "0";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two positive numbers of the same length
+     */
+    public void testPosPosSameLength() {
+        String numA = "283746278342837476784564875684767";
+        String numB = "293478573489347658763745839457637";
+        String res = "71412358434940908477702819237626";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two positive numbers; the first is longer
+     */
+    public void testPosPosFirstLonger() {
+        String numA = "2837462783428374767845648748973847593874837948575684767";
+        String numB = "293478573489347658763745839457637";
+        String res = "2837462783428374767845615168483972194300564226167553530";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two positive numbers; the first is shorter
+     */
+    public void testPosPosFirstShorter() {
+        String numA = "293478573489347658763745839457637";
+        String numB = "2837462783428374767845648748973847593874837948575684767";
+        String res = "2837462783428374767845615168483972194300564226167553530";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two negative numbers of the same length
+     */
+    public void testNegNegSameLength() {
+        String numA = "-283746278342837476784564875684767";
+        String numB = "-293478573489347658763745839457637";
+        String res = "71412358434940908477702819237626";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two negative numbers; the first is longer
+     */
+    public void testNegNegFirstLonger() {
+        String numA = "-2837462783428374767845648748973847593874837948575684767";
+        String numB = "-293478573489347658763745839457637";
+        String res = "2837462783428374767845615168483972194300564226167553530";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two negative numbers; the first is shorter
+     */
+    public void testNegNegFirstShorter() {
+        String numA = "293478573489347658763745839457637";
+        String numB = "2837462783428374767845648748973847593874837948575684767";
+        String res = "2837462783428374767845615168483972194300564226167553530";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two numbers of different signs and the same length
+     */
+    public void testPosNegSameLength() {
+        String numA = "283746278342837476784564875684767";
+        String numB = "-293478573489347658763745839457637";
+        String res = "-71412358434940908477702819237628";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two numbers of different signs and the same length
+     */
+    public void testNegPosSameLength() {
+        String numA = "-283746278342837476784564875684767";
+        String numB = "293478573489347658763745839457637";
+        String res = "-71412358434940908477702819237628";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for a negative and a positive numbers; the first is longer
+     */
+    public void testNegPosFirstLonger() {
+        String numA = "-2837462783428374767845648748973847593874837948575684767";
+        String numB = "293478573489347658763745839457637";
+        String res = "-2837462783428374767845615168483972194300564226167553532";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for two negative numbers; the first is shorter
+     */
+    public void testNegPosFirstShorter() {
+        String numA = "-293478573489347658763745839457637";
+        String numB = "2837462783428374767845648748973847593874837948575684767";
+        String res = "-2837462783428374767845615168483972194300564226167553532";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for a positive and a negative numbers; the first is longer
+     */
+    public void testPosNegFirstLonger() {
+        String numA = "2837462783428374767845648748973847593874837948575684767";
+        String numB = "-293478573489347658763745839457637";
+        String res = "-2837462783428374767845615168483972194300564226167553532";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+
+    /**
+     * Xor for a positive and a negative number; the first is shorter
+     */
+    public void testPosNegFirstShorter() {
+        String numA = "293478573489347658763745839457637";
+        String numB = "-2837462783428374767845648748973847593874837948575684767";
+        String res = "-2837462783428374767845615168483972194300564226167553532";
+        BigInteger aNumber = new BigInteger(numA);
+        BigInteger bNumber = new BigInteger(numB);
+        BigInteger result = aNumber.xor(bNumber);
+        assertTrue(res.equals(result.toString()));
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/MatcherTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/MatcherTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/MatcherTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/MatcherTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,608 @@
+/*
+ *  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 Nikolay A. Kuznetsov
+ * @version $Revision: 1.10.2.2 $
+ */
+package java.util.regex;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.10.2.2 $
+ */
+public class MatcherTest extends TestCase {
+    String[] testPatterns = {
+        "(a|b)*abb",
+        "(1*2*3*4*)*567",
+        "(a|b|c|d)*aab",
+        "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*",
+        "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*",
+        "(a|b)*(a|b)*A(a|b)*lice.*",
+        "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" +
+        "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do"
+
+    };
+    
+    String[] groupPatterns = {
+        "(a|b)*aabb",
+        "((a)|b)*aabb",
+        "((a|b)*)a(abb)",
+        "(((a)|(b))*)aabb",
+        "(((a)|(b))*)aa(b)b",
+        "(((a)|(b))*)a(a(b)b)"
+    };
+    
+
+    public void testAppendReplacement() {
+        Pattern pat = Pattern.compile("XX");
+        Matcher m = pat.matcher("Today is XX-XX-XX ...");
+        StringBuffer sb = new StringBuffer();
+        
+        for (int i=0; m.find(); i++) {
+            m.appendReplacement(sb, new Integer(i*10 + i).toString());
+        }
+        m.appendTail(sb);
+        assertEquals("Today is 0-11-22 ...", sb.toString());
+    }
+    
+    public void testAppendReplacementRef() {
+        Pattern p = Pattern.compile("xx (rur|\\$)");
+        Matcher m = p.matcher("xx $ equals to xx rur.");
+        StringBuffer sb = new StringBuffer();
+        for (int i=1; m.find(); i*=30) {
+            String rep = new Integer(i).toString() + " $1";
+            m.appendReplacement(sb, rep);
+        }
+        m.appendTail(sb);
+        assertEquals("1 $ equals to 30 rur.", sb.toString());
+    }
+    
+    public void testReplaceAll() {
+        String input = "aabfooaabfooabfoob";
+        String pattern = "a*b";
+        Pattern pat = Pattern.compile(pattern);
+        Matcher mat = pat.matcher(input);
+        
+        assertEquals("-foo-foo-foo-", mat.replaceAll("-"));
+    }
+
+    /*
+     * Class under test for Matcher reset(CharSequence)
+     */
+    public void testResetCharSequence() {}
+
+    public void testAppendSlashes() {
+        Pattern p = Pattern.compile("\\\\");
+        Matcher m = p.matcher("one\\cat\\two\\cats\\in\\the\\yard");
+        StringBuffer sb = new StringBuffer();
+        while (m.find()) {
+            m.appendReplacement(sb, "\\\\");
+        }
+        m.appendTail(sb);
+        assertEquals("one\\cat\\two\\cats\\in\\the\\yard", sb.toString());
+        
+    }
+
+    public void testReplaceFirst() {
+        String input = "zzzdogzzzdogzzz";
+        String pattern = "dog";
+        Pattern pat = Pattern.compile(pattern);
+        Matcher mat = pat.matcher(input);
+        
+        assertEquals("zzzcatzzzdogzzz", mat.replaceFirst("cat"));
+    }
+
+    public void testPattern() {
+        //test object equals
+        for (int i=0; i<testPatterns.length; i++) {
+            Pattern test = Pattern.compile(testPatterns[i]);
+            assertEquals(test, test.matcher("aaa").pattern());
+        }
+        
+        //compare string representation
+        for (int i=0; i<testPatterns.length; i++) {
+            assertEquals(testPatterns[i], 
+                    Pattern.compile(testPatterns[i]).matcher("aaa").pattern().toString());
+        }
+    }
+
+    /*
+     * Class under test for Matcher reset()
+     */
+    public void testReset() {}
+
+    /*
+     * Class under test for String group(int)
+     */
+    public void testGroupint() {
+        String positiveTestString = "ababababbaaabb";
+        String negativeTestString = "gjhfgdsjfhgcbv";
+        
+        
+        //test IndexOutOfBoundsException
+        ////
+        for (int i=0; i<groupPatterns.length; i++) {
+            Pattern test = Pattern.compile(groupPatterns[i]);
+            Matcher mat = test.matcher(positiveTestString);
+            mat.matches();
+            try {
+                //groupPattern <index + 1> equals to number of groups
+                //of the specified pattern
+                ////
+                mat.group(i + 2);
+                fail("IndexOutBoundsException expected");
+                mat.group(i + 100);
+                fail("IndexOutBoundsException expected");
+                mat.group(-1);
+                fail("IndexOutBoundsException expected");
+                mat.group(-100);
+                fail("IndexOutBoundsException expected");
+            } catch (IndexOutOfBoundsException iobe) {}
+        }
+        
+        String[][] groupResults = {
+                {"a"},
+                {"a", "a"},
+                {"ababababba", "a", "abb"},
+                {"ababababba", "a", "a", "b"},
+                {"ababababba", "a", "a", "b", "b"},
+                {"ababababba", "a", "a", "b", "abb", "b"},
+        };
+        
+        for (int i=0; i<groupPatterns.length; i++) {
+            Pattern test = Pattern.compile(groupPatterns[i]);
+            Matcher mat = test.matcher(positiveTestString);
+            mat.matches();
+            for (int j = 0; j<groupResults[i].length; j++) {
+                assertEquals("i: " + i +" j: " +j, groupResults[i][j], mat.group(j+1));
+            }
+            
+        }
+        
+    }
+
+    public void testGroup() {
+        String positiveTestString = "ababababbaaabb";
+        String negativeTestString = "gjhfgdsjfhgcbv";
+        for (int i=0; i<groupPatterns.length; i++) {
+            Pattern test = Pattern.compile(groupPatterns[i]);
+            Matcher mat = test.matcher(positiveTestString);
+            mat.matches();
+            //test result
+            assertEquals(positiveTestString, mat.group());
+            
+            //test equal to group(0) result
+            assertEquals(mat.group(0), mat.group());
+        }
+        
+        for (int i=0; i<groupPatterns.length; i++) {
+            Pattern test = Pattern.compile(groupPatterns[i]);
+            Matcher mat = test.matcher(negativeTestString);
+            mat.matches();
+            try {
+                mat.group();
+                fail("IllegalStateException expected for <false> matches result");
+            } catch (IllegalStateException ise) {}
+        }
+    }
+    
+    public void testGroupPossessive() {
+        Pattern pat = Pattern.compile("((a)|(b))++c");
+        Matcher mat = pat.matcher("aac");
+        
+        mat.matches();
+        assertEquals("a", mat.group(1));
+    }
+
+    /*
+     * Class under test for boolean find(int)
+     */
+    public void testFindint() {}
+
+    /*
+     * Class under test for int start(int)
+     */
+    public void testStartint() {}
+
+    /*
+     * Class under test for int end(int)
+     */
+    public void testEndint() {}
+
+    public void testMatchesMisc() {
+        String[][] posSeq = {
+              {"abb", "ababb", "abababbababb", "abababbababbabababbbbbabb"},
+              {"213567", "12324567", "1234567", "213213567", "21312312312567", "444444567"},
+              {"abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab"},
+              {"213234567", "3458", "0987654", "7689546432", "0398576", "98432", "5"},
+              {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 
+               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +
+               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"},
+              {"ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa", "abbbAbbbliceaaa", "Alice"},
+              {"a123", "bnxnvgds156", "for", "while", "if", "struct"}
+              
+        };
+        
+        for (int i=0; i<testPatterns.length; i++) {
+            Pattern pat = Pattern.compile(testPatterns[i]);
+            for (int j=0; j<posSeq[i].length; j++) {
+                Matcher mat = pat.matcher(posSeq[i][j]);
+                assertTrue("Incorrect match: " + testPatterns[i] + " vs " + posSeq[i][j], mat.matches());
+            }
+        }
+    }
+    
+    public void testMatchesQuantifiers() {
+        String[] testPatternsSingles = {"a{5}", "a{2,4}", "a{3,}"};
+        String[] testPatternsMultiple= {"((a)|(b)){1,2}abb", "((a)|(b)){2,4}", "((a)|(b)){3,}"};
+        
+        String[][] stringSingles = {
+            {"aaaaa", "aaa"},
+            {"aa", "a", "aaa", "aaaaaa", "aaaa", "aaaaa"},
+            {"aaa", "a", "aaaa", "aa"},
+        };
+        
+        String[][] stringMultiples = {
+            {"ababb", "aba"},
+            {"ab", "b", "bab", "ababa", "abba", "abababbb"},
+            {"aba", "b", "abaa", "ba"},
+        };
+        
+        for (int i=0; i<testPatternsSingles.length; i++) {
+            Pattern pat = Pattern.compile(testPatternsSingles[i]);
+            for (int j=0; j<stringSingles.length/2; j++) {
+                assertTrue("Match expected, but failed: " 
+                        + pat.pattern() + " : " + stringSingles[i][j], 
+                        pat.matcher(stringSingles[i][j*2]).matches());
+                assertFalse("Match failure expected, but match succeed: " 
+                        + pat.pattern() + " : " + stringSingles[i][j*2+1], 
+                        pat.matcher(stringSingles[i][j*2+1]).matches());
+            }
+        }
+        
+        for (int i=0; i<testPatternsMultiple.length; i++) {
+            Pattern pat = Pattern.compile(testPatternsMultiple[i]);
+            for (int j=0; j<stringMultiples.length/2; j++) {
+                assertTrue("Match expected, but failed: " 
+                        + pat.pattern() + " : " + stringMultiples[i][j], 
+                        pat.matcher(stringMultiples[i][j*2]).matches());
+                assertFalse("Match failure expected, but match succeed: " 
+                        + pat.pattern() + " : " + stringMultiples[i][j*2+1], 
+                        pat.matcher(stringMultiples[i][j*2+1]).matches());
+            }
+        }
+    }
+    
+    public void testQuantVsGroup() {
+        String patternString = "(d{1,3})((a|c)*)(d{1,3})((a|c)*)(d{1,3})";
+        String testString = "dacaacaacaaddaaacaacaaddd";
+        
+        Pattern pat = Pattern.compile(patternString);
+        Matcher mat = pat.matcher(testString);
+        
+        mat.matches();
+        assertEquals("dacaacaacaaddaaacaacaaddd", mat.group());
+        assertEquals("d", mat.group(1));
+        assertEquals("acaacaacaa", mat.group(2));
+        assertEquals("dd", mat.group(4));
+        assertEquals("aaacaacaa", mat.group(5));
+        assertEquals("ddd", mat.group(7));
+    }
+    
+    public void testLookingAt() {}
+
+    /*
+     * Class under test for boolean find()
+     */
+    public void testFind() {
+        String testPattern = "(abb)";
+        String testString = "cccabbabbabbabbabb";
+        Pattern pat = Pattern.compile(testPattern);
+        Matcher mat = pat.matcher(testString);
+        int start = 3;
+        int end =   6;
+        while(mat.find()) {
+            assertEquals(start, mat.start(1));
+            assertEquals(end, mat.end(1));
+            
+            start = end;
+            end += 3;
+        }
+        
+        testPattern = "(\\d{1,3})";
+        testString  = "aaaa123456789045";
+        
+        Pattern pat2 = Pattern.compile(testPattern);
+        Matcher mat2 = pat2.matcher(testString);
+        start = 4;
+        int length = 3;
+        while(mat2.find()) {
+            assertEquals(testString.substring(start, start+length), mat2.group(1));
+            start += length;
+        }
+    }
+    
+    public void testSEOLsymbols() {
+        Pattern pat = Pattern.compile("^a\\(bb\\[$");
+        Matcher mat = pat.matcher("a(bb[");
+        
+        assertTrue(mat.matches());
+    }
+
+    /*
+     * Class under test for int start()
+     */
+    public void testStart() {}
+
+    public void testGroupCount() {
+        for (int i=0; i<groupPatterns.length; i++) {
+            Pattern test = Pattern.compile(groupPatterns[i]);
+            Matcher mat = test.matcher("ababababbaaabb");
+            mat.matches();
+            assertEquals(i+1, mat.groupCount());
+            
+        }
+    }
+    
+    public void testRelactantQuantifiers() {
+        Pattern pat = Pattern.compile("(ab*)*b");
+        Matcher mat = pat.matcher("abbbb");
+        
+        if (mat.matches()) {
+            assertEquals("abbb", mat.group(1));
+        } else {
+            fail("Match expected: (ab*)*b vs abbbb");
+        }
+    }
+    
+    public void testEnhancedFind() {
+        String input = "foob";
+        String pattern = "a*b";
+        Pattern pat = Pattern.compile(pattern);
+        Matcher mat = pat.matcher(input);
+        
+        
+        mat.find();
+        assertEquals("b", mat.group());
+    }
+    
+    public void _testMatchesURI() {
+        final Pattern pat = Pattern.compile("^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
+        Runnable r1 = new Runnable() {
+            public void run() {
+                Matcher mat = pat.matcher("file:/c:/workspace/api/build.win32/classes/META-INF/" +
+                "services/javax.xml.parsers.DocumentBuilderFactory");
+                int k1=1;
+                while (mat.matches()) {}//System.err.println("1: " + mat.group());
+                System.out.println("1: fail");
+            }
+        };
+        
+        Runnable r2 = new Runnable() {
+            public void run() {
+                Matcher mat = pat.matcher("file:/c:/workspace/" +
+                "services/javax.xml.parsers.DocumentBuilderFactory");
+                int k1=1;
+                while (mat.matches()) {}//System.err.println("2: " + mat.group());
+                System.out.println("2: fail");
+            }
+        };
+        
+        Thread t1 = new Thread(r1);
+        Thread t2 = new Thread(r2);
+        
+        t1.start();
+        t2.start();
+        
+        try {
+            t1.join();
+            t2.join();
+        } catch (Exception e) {}
+        
+    }
+    
+    public void _testUnifiedQuantifiers() {
+        //Pattern pat1 = Pattern.compile("\\s+a");
+        Pattern pat2 = Pattern.compile(" *a");
+        
+        Matcher mat = pat2.matcher("      a");
+        
+        System.out.println("unified: " + mat.find());
+    }
+    
+    public void _testCompositeGroupQuantifiers() {
+        Pattern pat = Pattern.compile("(a|b){0,3}abb");
+        Matcher mat = pat.matcher("ababababababababababaab");
+        
+        System.out.println("composite: " + mat.find());
+    }
+    
+    public void testPosCompositeGroup() {
+        String[] posExamples = {"aabbcc", "aacc", "bbaabbcc"};
+        String[] negExamples = {"aabb", "bb", "bbaabb"};
+        Pattern posPat = Pattern.compile("(aa|bb){1,3}+cc");
+        Pattern negPat = Pattern.compile("(aa|bb){1,3}+bb");
+        
+        Matcher mat;
+        for (int i=0; i<posExamples.length; i++) {
+            mat = posPat.matcher(posExamples[i]);
+            assertTrue(mat.matches());
+        }
+        
+        for (int i=0; i<negExamples.length; i++) {
+            mat = negPat.matcher(negExamples[i]);
+            assertFalse(mat.matches());
+        } 
+        
+        assertTrue(Pattern.matches("(aa|bb){1,3}+bb", "aabbaabb"));
+        
+    }
+    
+    public void testPosAltGroup() {
+        String[] posExamples = {"aacc", "bbcc", "cc"};
+        String[] negExamples = {"bb", "aa"};
+        Pattern posPat = Pattern.compile("(aa|bb)?+cc");
+        Pattern negPat = Pattern.compile("(aa|bb)?+bb");
+        
+        Matcher mat;
+        for (int i=0; i<posExamples.length; i++) {
+            mat = posPat.matcher(posExamples[i]);
+            assertTrue(posPat.toString() + " vs: " + posExamples[i], mat.matches());
+        }
+        
+        for (int i=0; i<negExamples.length; i++) {
+            mat = negPat.matcher(negExamples[i]);
+            assertFalse(mat.matches());
+        } 
+        
+        assertTrue(Pattern.matches("(aa|bb)?+bb", "aabb"));
+    }
+    
+    public void testRelCompGroup() {
+        
+        Matcher mat;
+        Pattern pat;
+        String res = "";
+        for (int i=0; i<4; i++) {
+            pat = Pattern.compile("((aa|bb){" + i + ",3}?).*cc");
+            mat = pat.matcher("aaaaaacc");
+            assertTrue(pat.toString() + " vs: " + "aaaaaacc", mat.matches());
+            assertEquals(res, mat.group(1));
+            res += "aa";
+        }
+    }
+    
+    public void testRelAltGroup() {
+        
+        Matcher mat;
+        Pattern pat;
+        
+        pat = Pattern.compile("((aa|bb)??).*cc");
+        mat = pat.matcher("aacc");
+        assertTrue(pat.toString() + " vs: " + "aacc", mat.matches());
+        assertEquals("", mat.group(1));
+        
+        pat = Pattern.compile("((aa|bb)??)cc");
+        mat = pat.matcher("aacc");
+        assertTrue(pat.toString() + " vs: " + "aacc", mat.matches());
+        assertEquals("aa", mat.group(1));
+    }
+    
+    public void testIgnoreCase() {
+        Pattern pat = Pattern.compile("(aa|bb)*", Pattern.CASE_INSENSITIVE);
+        Matcher mat = pat.matcher("aAbb");
+        
+        assertTrue(mat.matches());
+        
+        pat = Pattern.compile("(a|b|c|d|e)*", Pattern.CASE_INSENSITIVE);
+        mat = pat.matcher("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa");
+        assertTrue(mat.matches());
+        
+        pat = Pattern.compile("[a-e]*", Pattern.CASE_INSENSITIVE);
+        mat = pat.matcher("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa");
+        assertTrue(mat.matches());
+        
+    }
+    
+    public void testQuoteReplacement() {
+        assertEquals("\\\\aaCC\\$1", Matcher.quoteReplacement("\\aaCC$1"));
+    }
+    
+    
+    public void testOverFlow() {
+        Pattern tp = Pattern.compile("(a*)*");
+        Matcher tm = tp.matcher("aaa");
+        assertTrue(tm.matches()); 
+        assertEquals("", tm.group(1));
+        
+        assertTrue(Pattern.matches("(1+)\\1+", "11"));
+        assertTrue(Pattern.matches("(1+)(2*)\\2+", "11"));
+        
+        Pattern pat = Pattern.compile("(1+)\\1*");
+        Matcher mat = pat.matcher("11");
+        
+        assertTrue(mat.matches());
+        assertEquals("11", mat.group(1));
+        
+        pat = Pattern.compile("((1+)|(2+))(\\2+)");
+        mat = pat.matcher("11");
+        
+        assertTrue(mat.matches());
+        assertEquals("1", mat.group(2));
+        assertEquals("1", mat.group(1));
+        assertEquals("1", mat.group(4));
+        assertEquals(null, mat.group(3));
+        
+        
+    }
+    
+    public void testUnicode() {
+              
+        assertTrue(Pattern.matches("\\x61a", "aa"));
+        assertTrue(Pattern.matches("\\u0061a", "aa"));
+        assertTrue(Pattern.matches("\\0141a", "aa"));
+        assertTrue(Pattern.matches("\\0777", "?7"));
+        
+    }
+    
+    public void testUnicodeCategory() {
+        assertTrue(Pattern.matches("\\p{Ll}", "k")); //Unicode lower case
+        assertTrue(Pattern.matches("\\P{Ll}", "K")); //Unicode non-lower case
+        assertTrue(Pattern.matches("\\p{Lu}", "K")); //Unicode upper case
+        assertTrue(Pattern.matches("\\P{Lu}", "k")); //Unicode non-upper case
+        //combinations
+        assertTrue(Pattern.matches("[\\p{L}&&[^\\p{Lu}]]", "k"));
+        assertTrue(Pattern.matches("[\\p{L}&&[^\\p{Ll}]]", "K"));
+        assertFalse(Pattern.matches("[\\p{L}&&[^\\p{Lu}]]", "K"));
+        assertFalse(Pattern.matches("[\\p{L}&&[^\\p{Ll}]]", "k"));
+        
+        //category/character combinations
+        assertFalse(Pattern.matches("[\\p{L}&&[^a-z]]", "k"));
+        assertTrue(Pattern.matches("[\\p{L}&&[^a-z]]", "K"));
+        
+        assertTrue(Pattern.matches("[\\p{Lu}a-z]", "k"));
+        assertTrue(Pattern.matches("[a-z\\p{Lu}]", "k"));
+        
+        assertFalse(Pattern.matches("[\\p{Lu}a-d]", "k"));
+        assertTrue(Pattern.matches("[a-d\\p{Lu}]", "K"));
+        
+        assertTrue(Pattern.matches("[\\p{L}&&[^\\p{Lu}&&[^K]]]", "K"));
+        assertFalse(Pattern.matches("[\\p{L}&&[^\\p{Lu}&&[^G]]]", "K"));
+        
+    }
+	
+	public void testSplitEmpty() {
+		
+		Pattern pat = Pattern.compile("");
+		String[] s = pat.split("", -1);
+		
+		assertEquals(1, s.length);
+		assertEquals("", s[0]);
+	}
+	
+	public void testFindDollar() {
+		Matcher mat = Pattern.compile("a$").matcher("a\n");
+		assertTrue(mat.find());
+		assertEquals("a", mat.group());
+	}
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(MatcherTest.class);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/PatternTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/PatternTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/PatternTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/util/regex/PatternTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,543 @@
+/*
+ *  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 Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+package java.util.regex;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+public class PatternTest extends TestCase {
+    String[] testPatterns = {
+        "(a|b)*abb",
+        "(1*2*3*4*)*567",
+        "(a|b|c|d)*aab",
+        "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*",
+        "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*",
+        "(a|b)*(a|b)*A(a|b)*lice.*",
+        "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" +
+        "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do"
+
+    };
+    
+	/**
+	 * Constructor for PatternTest.
+	 * @param name
+	 */
+	public PatternTest(String name) {
+		super(name);
+	}
+
+	public void testMatcher() {
+	}
+
+	/*
+	 * Class under test for String[] split(CharSequence, int)
+	 */
+	public void testSplitCharSequenceint() {
+	}
+
+	/*
+	 * Class under test for String[] split(CharSequence)
+	 */
+	public void testSplitCharSequence() {
+	}
+
+	public void testPattern() {
+	}
+
+	public void testFlags() {
+	}
+
+	/*
+	 * Class under test for Pattern compile(String, int)
+	 */
+	public void testCompileStringint() {
+	}
+
+	/*
+	 * Class under test for Pattern compile(String)
+	 */
+	public void testQuantCompileNeg() {
+        String[] patterns = {"5{,2}", "{5asd", "{hgdhg", "{5,hjkh", "{,5hdsh", "{5,3shdfkjh}"};
+        for (int i=0; i<patterns.length; i++) { 
+            try {
+                Pattern.compile(patterns[i]);
+                fail("PatternSyntaxException was expected, but compilation succeeds");
+            } catch (PatternSyntaxException pse) {
+                continue;
+            } catch (Throwable e) {
+                fail("PatternSyntaxException was expected, but other one was thrown: " + e);
+            }
+        }
+	}
+    
+    public void testQuantCompilePos() {
+        String[] patterns = {/*"(abc){1,3}",*/ "abc{2,}", "abc{5}"};
+        for (int i=0; i<patterns.length; i++) {
+            Pattern.compile(patterns[i]);
+        }
+    }
+    
+    public void testQuantComposition() {
+        String pattern = "(a{1,3})aab";
+        java.util.regex.Pattern pat = java.util.regex.Pattern.compile(pattern);
+        java.util.regex.Matcher mat = pat.matcher("aaab");
+        mat.matches();
+        mat.start(1);
+        mat.group(1);
+    }
+
+	public void testMatches() {
+        String[][] posSeq = {
+              {"abb", "ababb", "abababbababb", "abababbababbabababbbbbabb"},
+              {"213567", "12324567", "1234567", "213213567", "21312312312567", "444444567"},
+              {"abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab"},
+              {"213234567", "3458", "0987654", "7689546432", "0398576", "98432", "5"},
+              {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 
+               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +
+               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"},
+              {"ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa", "abbbAbbbliceaaa", "Alice"},
+              {"a123", "bnxnvgds156", "for", "while", "if", "struct"}
+              
+        };
+        
+        for (int i=0; i<testPatterns.length; i++) {
+            for (int j=0; j<posSeq[i].length; j++) {
+                assertTrue("Incorrect match: " + testPatterns[i] + " vs " + 
+                        posSeq[i][j], Pattern.matches(testPatterns[i], posSeq[i][j]));
+            }
+        }
+    }
+    
+    public void testTimeZoneIssue() {
+        Pattern p = Pattern.compile("GMT(\\+|\\-)(\\d+)(:(\\d+))?");
+        Matcher m = p.matcher("GMT-9:45");
+        assertTrue(m.matches());
+        assertEquals("-", m.group(1));
+        assertEquals("9", m.group(2));
+        assertEquals(":45", m.group(3));
+        assertEquals("45", m.group(4));
+    }
+    
+    
+    public void testCompileRanges() {
+        String[] correctTestPatterns = {
+            "[^]*abb]*",
+            "[^a-d[^m-p]]*abb",
+            "[a-d\\d]*abb",
+            "[abc]*abb",
+            "[a-e&&[de]]*abb",
+            "[^abc]*abb",
+            "[a-e&&[^de]]*abb",
+            "[a-z&&[^m-p]]*abb",
+            "[a-d[m-p]]*abb",
+            "[a-zA-Z]*abb",
+            "[+*?]*abb",
+            "[^+*?]*abb"
+        };
+            
+        String[] inputSecuence = {
+            "kkkk",
+            "admpabb",
+            "abcabcd124654abb",
+            "abcabccbacababb",
+            "dededededededeedabb",
+            "gfdhfghgdfghabb",
+            "accabacbcbaabb",
+            "acbvfgtyabb",
+            "adbcacdbmopabcoabb",
+            "jhfkjhaSDFGHJkdfhHNJMjkhfabb",
+            "+*??+*abb",
+            "sdfghjkabb"
+        };
+        
+        Pattern pat;
+        
+        for (int i=0; i<correctTestPatterns.length; i++) {
+            assertTrue("pattern: " + correctTestPatterns[i] 
+                     + " input: " + inputSecuence[i], 
+                     Pattern.matches(correctTestPatterns[i], inputSecuence[i]));
+            
+        }
+        
+        String[] wrongInputSecuence = {
+                "]",
+                "admpkk",
+                "abcabcd124k654abb",
+                "abwcabccbacababb",
+                "abababdeababdeabb",
+                "abcabcacbacbabb",
+                "acdcbecbaabb",
+                "acbotyabb",
+                "adbcaecdbmopabcoabb",
+                "jhfkjhaSDFGHJk;dfhHNJMjkhfabb",
+                "+*?a?+*abb",
+                "sdf+ghjkabb"
+            };
+        
+        for (int i=0; i<correctTestPatterns.length; i++) {
+            assertFalse("pattern: " + correctTestPatterns[i] 
+                     + " input: " + wrongInputSecuence[i], 
+                     Pattern.matches(correctTestPatterns[i], wrongInputSecuence[i]));
+            
+        }
+    }
+    
+    public void testRangesSpecialCases() {
+        String neg_patterns[] = {
+             "[a-&&[b-c]]",
+             "[a-\\w]",
+             "[b-a]",
+             "[]"
+        };
+        
+        for (int i=0; i<neg_patterns.length; i++) {
+            try {
+                Pattern.compile(neg_patterns[i]);
+                fail("PatternSyntaxException was expected: " + neg_patterns[i]);
+            } catch (PatternSyntaxException pse) {}
+        }
+        
+        String pos_patterns[] = {
+            "[-]+", "----",
+            "[a-]+", "a-a-a-a-aa--",
+            "[\\w-a]+", "123-2312--aaa-213",
+            "[a-]]+", "-]]]]]]]]]]]]]]]"
+        };
+        
+        for (int i=0; i<pos_patterns.length; i++) {
+            String pat = pos_patterns[i++];
+            String inp = pos_patterns[i];
+            assertTrue("pattern: " + pat + " input: " + inp, Pattern.matches(pat, inp));
+        }
+    }
+    
+    public void testZeroSymbols() {
+        assertTrue(Pattern.matches("[\0]*abb", "\0\0\0\0\0\0abb"));
+    }
+    
+    public void testEscapes() {
+        Pattern pat = Pattern.compile("\\Q{]()*?");
+        Matcher mat = pat.matcher("{]()*?");
+        
+        assertTrue(mat.matches());
+    }
+    
+    public void testBug181() {
+        Pattern.compile("[\\t-\\r]");
+    }
+    
+    public void _testBug187() {
+        Pattern.compile("|(?idmsux-idmsux)|(?idmsux-idmsux)|[^|\\[-\\0274|\\,-\\\\[^|W\\}\\nq\\x65\\002\\xFE\\05\\06\\00\\x66\\x47i\\,\\xF2\\=\\06\\u0EA4\\x9B\\x3C\\f\\|\\{\\xE5\\05\\r\\u944A\\xCA\\e|\\x19\\04\\x07\\04\\u607B\\023\\0073\\x91Tr\\0150\\x83]]?(?idmsux-idmsux:\\p{Alpha}{7}?)||(?<=[^\\uEC47\\01\\02\\u3421\\a\\f\\a\\013q\\035w\\e])(?<=\\p{Punct}{0,}?)(?=^\\p{Lower})(?!\\b{8,14})(?<![|\\00-\\0146[^|\\04\\01\\04\\060\\f\\u224DO\\x1A\\xC4\\00\\02\\0315\\0351\\u84A8\\xCBt\\xCC\\06|\\0141\\00\\=\\e\\f\\x6B\\0026Tb\\040\\x76xJ&&[\\\\-\\]\\05\\07\\02\\u2DAF\\t\\x9C\\e\\0023\\02\\,X\\e|\\u6058flY\\u954C]]]{5}?)(?<=\\p{Sc}{8}+)[^|\\026-\\u89BA|o\\u6277\\t\\07\\x50&&\\p{Punct}]{8,14}+((?<=^\\p{Punct})|(?idmsux-idmsux)||(?>[\\x3E-\\]])|(?idmsux-idmsux:\\p{Punct})|(?<![\\0111\\0371\\xDF\\u6A49\\07\\u2A4D\\00\\0212\\02Xd-\\xED[^\\a-\\0061|\\0257\\04\\f\\[\\0266\\043\\03\\x2D\\042&&[^\\f-\\]&&\\s]]])|(?>[|\\n\\042\\uB09F\\06\\u0F2B\\uC96D\\x89\\uC166\\xAA|\\04-\\][^|\\a\\|\\rx\
 \04\\uA770\\n\\02\\t\\052\\056\\0274\\|\\=\\07\\e|\\00-\\x1D&&[^\\005\\uB15B\\uCDAC\\n\\x74\\0103\\0147\\uD91B\\n\\062G\\u9B4B\\077\\}\\0324&&[^\\0302\\,\\0221\\04\\u6D16\\04xy\\uD193\\[\\061\\06\\045\\x0F|\\e\\xBB\\f\\u1B52\\023\\u3AD2\\033\\007\\022\\}\\x66\\uA63FJ-\\0304]]]]{0,0})||(?<![^|\\0154U\\u0877\\03\\fy\\n\\|\\0147\\07-\\=[|q\\u69BE\\0243\\rp\\053\\02\\x33I\\u5E39\\u9C40\\052-\\xBC[|\\0064-\\?|\\uFC0C\\x30\\0060\\x45\\\\\\02\\?p\\xD8\\0155\\07\\0367\\04\\uF07B\\000J[^|\\0051-\\{|\\u9E4E\\u7328\\]\\u6AB8\\06\\x71\\a\\]\\e\\|KN\\u06AA\\0000\\063\\u2523&&[\\005\\0277\\x41U\\034\\}R\\u14C7\\u4767\\x09\\n\\054Ev\\0144\\<\\f\\,Q-\\xE4]]]]]{3}+)|(?>^+)|(?![^|\\|\\nJ\\t\\<\\04E\\\\\\t\\01\\\\\\02\\|\\=\\}\\xF3\\uBEC2\\032K\\014\\uCC5F\\072q\\|\\0153\\xD9\\0322\\uC6C8[^\\t\\0342\\x34\\x91\\06\\{\\xF1\\a\\u1710\\?\\xE7\\uC106\\02pF\\<&&[^|\\]\\064\\u381D\\u50CF\\eO&&[^|\\06\\x2F\\04\\045\\032\\u8536W\\0377\\0017|\\x06\\uE5FA\\05\\xD4\\020\\04c\\xFC\\02H\\x0A\\r]]]]+?)(?idms
 ux-idmsux)|(?<![|\\r-\\,&&[I\\t\\r\\0201\\xDB\\e&&[^|\\02\\06\\00\\<\\a\\u7952\\064\\051\\073\\x41\\?n\\040\\0053\\031&&[\\x15-\\|]]]]{8,11}?)(?![^|\\<-\\uA74B\\xFA\\u7CD2\\024\\07n\\<\\x6A\\0042\\uE4FF\\r\\u896B\\[\\=\\042Y&&^\\p{ASCII}]++)|(?<![R-\\|&&[\\a\\0120A\\u6145\\<\\050-d[|\\e-\\uA07C|\\016-\\u80D9]]]{1,}+)|(?idmsux-idmsux)|(?idmsux-idmsux)|(?idmsux-idmsux:\\B{6,}?)|(?<=\\D{5,8}?)|(?>[\\{-\\0207|\\06-\\0276\\p{XDigit}])(?idmsux-idmsux:[^|\\x52\\0012\\]u\\xAD\\0051f\\0142\\\\l\\|\\050\\05\\f\\t\\u7B91\\r\\u7763\\{|h\\0104\\a\\f\\0234\\u2D4F&&^\\P{InGreek}]))");
+    }
+    
+    public void testOrphanQuantifiers() {
+        try {
+            Pattern.compile("+++++");
+            fail("PatternSyntaxException expected");
+        } catch (PatternSyntaxException pse) {
+            System.out.println(pse);
+        } catch (Throwable e) {
+            fail("PatternSyntaxException expected other one was thrown: " + e);
+        }
+    }
+    
+    public void testOrphanQuantifiers2() {
+        try {
+            Pattern pat = Pattern.compile("\\d+*");
+            fail("PatternSyntaxException expected");
+        } catch (PatternSyntaxException pse) {
+        } catch (Throwable e) {
+            fail("PatternSyntaxException expected other one was thrown: " + e);
+        }
+    }
+    
+    public void testBug197() {
+        Object[] vals = {":",  new Integer(2),  new String[] {"boo", "and:foo"}, 
+                     ":",  new Integer(5),  new String[] { "boo", "and", "foo" },
+                     ":", new Integer(-2), new  String[] { "boo", "and", "foo" },
+                     ":", new Integer(3), new  String[] { "boo", "and", "foo" },
+                     ":", new Integer(1), new  String[] { "boo:and:foo" },
+                     "o", new Integer(5), new  String[] { "b", "", ":and:f", "", "" }, 
+                     "o", new Integer(4), new  String[] { "b", "", ":and:f", "o"},
+                     "o", new Integer(-2), new  String[] { "b", "", ":and:f", "", "" }, 
+                     "o", new Integer(0), new  String[] { "b", "", ":and:f" }};
+
+        for (int i=0; i<vals.length/3;) {
+            String[] res = Pattern.compile(vals[i++].toString()).split("boo:and:foo", 
+                    ((Integer)vals[i++]).intValue());
+            String[] expectedRes = (String[])vals[i++];
+            
+            assertEquals(expectedRes.length, res.length);
+            
+            for(int j=0; j<expectedRes.length; j++) {
+                assertEquals(expectedRes[j], res[j]);
+            }
+        }
+    }
+    
+    public void testURIPatterns() {
+        String URI_REGEXP_STR    = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?";
+        String SCHEME_REGEXP_STR = "^[a-zA-Z]{1}[\\w+-.]+$";
+        String REL_URI_REGEXP_STR= "^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?";
+        String IPV6_REGEXP_STR     = "^[0-9a-fA-F\\:\\.]+(\\%\\w+)?$";
+        String IPV6_REGEXP_STR2    = "^\\[[0-9a-fA-F\\:\\.]+(\\%\\w+)?\\]$";
+        String IPV4_REGEXP_STR     = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$";
+        String HOSTNAME_REGEXP_STR = "\\w+[\\w\\-\\.]*";
+        
+        Pattern URI_REGEXP      = Pattern.compile(URI_REGEXP_STR); 
+        Pattern REL_URI_REGEXP  = Pattern.compile(REL_URI_REGEXP_STR); 
+        Pattern SCHEME_REGEXP   = Pattern.compile(SCHEME_REGEXP_STR); 
+        Pattern IPV4_REGEXP     = Pattern.compile(IPV4_REGEXP_STR); 
+        Pattern IPV6_REGEXP     = Pattern.compile(IPV6_REGEXP_STR); 
+        Pattern IPV6_REGEXP2    = Pattern.compile(IPV6_REGEXP_STR2); 
+        Pattern HOSTNAME_REGEXP = Pattern.compile(HOSTNAME_REGEXP_STR);
+        
+    }
+    
+    public void testFindBoundaryCases1() {
+        Pattern pat = Pattern.compile(".*\n");
+        Matcher mat = pat.matcher("a\n");
+        
+        mat.find();
+        assertEquals("a\n", mat.group());
+        
+    }
+    
+    public void testFindBoundaryCases2() {
+        Pattern pat = Pattern.compile(".*A");
+        Matcher mat = pat.matcher("aAa");
+        
+        mat.find();
+        assertEquals("aA", mat.group());
+        
+    }
+    
+    public void testFindBoundaryCases3() {
+        Pattern pat = Pattern.compile(".*A");
+        Matcher mat = pat.matcher("a\naA\n");
+        
+        mat.find();
+        assertEquals("aA", mat.group());
+        
+    }
+    
+    public void testFindBoundaryCases4() {
+        Pattern pat = Pattern.compile("A.*");
+        Matcher mat = pat.matcher("A\n");
+        
+        mat.find();
+        assertEquals("A", mat.group());
+        
+    }
+    
+    public void testFindBoundaryCases5() {
+        Pattern pat = Pattern.compile(".*A.*");
+        Matcher mat = pat.matcher("\nA\naaa\nA\naaAaa\naaaA\n");
+        //Matcher mat = pat.matcher("\nA\n");
+        String[] res = {
+                "A",
+                "A",
+                "aaAaa",
+                "aaaA"
+        };
+        int k=0;
+        for(;mat.find(); k++) {
+            assertEquals(res[k], mat.group());
+        }
+    }
+    
+    public void testFindBoundaryCases6() {
+        String[] res = {
+                "",
+                "a",
+                "",
+                ""
+        };
+        Pattern pat = Pattern.compile(".*");
+        Matcher mat = pat.matcher("\na\n");
+        int k=0;        
+        
+        for(;mat.find();k++){
+            assertEquals(res[k], mat.group());
+        }
+    }
+    
+    public void _testFindBoundaryCases7() {
+        String[] res = {
+                "",
+                "a",
+                "",
+                ""
+        };
+        Pattern pat = Pattern.compile(".*");
+        Matcher mat = pat.matcher("\na\n");
+        int k=0;        
+        
+        for(;mat.find();k++){
+            System.out.println(mat.group());
+            System.out.flush();
+        }
+    }
+    
+    public void testBackReferences() {
+        Pattern pat = Pattern.compile("(\\((\\w*):(.*):(\\2)\\))");
+        Matcher mat = pat.matcher("(start1: word :start1)(start2: word :start2)");
+        int k=1;
+        for (;mat.find();k++) {
+            assertEquals("start" + k, mat.group(2));
+            assertEquals(" word ", mat.group(3));
+            assertEquals("start" + k, mat.group(4));
+            
+        }
+        
+        assertEquals(3, k);
+    }
+    
+    public void _testBackReferences1() {
+        Pattern pat = Pattern.compile("(\\((\\w*):(.*):(\\2)\\))");
+        Matcher mat = pat.matcher("(start1: word :start1)(start2: word :start2)");
+        int k=1;
+        for (;mat.find();k++) {
+            System.out.println(mat.group(2));
+            System.out.println(mat.group(3));
+            System.out.println(mat.group(4));
+            
+        }
+        
+        assertEquals(3, k);
+    }
+    
+    public void testNewLine() {
+        Pattern pat = Pattern.compile("(^$)*\n", Pattern.MULTILINE);
+        Matcher mat = pat.matcher("\r\n\n");
+        int counter = 0;
+        while (mat.find()) counter++;
+        assertEquals(2, counter);
+    }
+    
+    public void testFindGreedy() {
+        Pattern pat = Pattern.compile(".*aaa", Pattern.DOTALL);
+        Matcher mat = pat.matcher("aaaa\naaa\naaaaaa");
+        mat.matches();
+        assertEquals(15, mat.end());
+    }
+    
+    public void testSOLQuant() {
+        Pattern pat = Pattern.compile("$*", Pattern.MULTILINE);
+        Matcher mat = pat.matcher("\n\n");
+        int counter = 0;
+        while(mat.find()) counter++;
+        
+        assertEquals(3, counter);
+    }
+    
+    public void testIllegalEscape() {
+        try {
+            Pattern.compile("\\y");
+            fail("PatternSyntaxException expected");
+        } catch (PatternSyntaxException pse) {
+            
+        } catch (Exception t) {
+            fail("PatternSyntaxException was expected" +
+                    "but other one was thrown: " + t);
+        }
+    }
+    
+    public void testEmptyFamily() {
+        Pattern.compile("\\p{Lower}");
+        String a = "*";
+    }
+    
+    public void testNonCaptConstr() {
+        //Flags
+        Pattern pat = Pattern.compile("(?i)b*(?-i)a*");
+        assertTrue(pat.matcher("bBbBaaaa").matches());
+        assertFalse(pat.matcher("bBbBAaAa").matches());
+        
+        //Non-capturing groups
+        pat = Pattern.compile("(?i:b*)a*");
+        assertTrue(pat.matcher("bBbBaaaa").matches());
+        assertFalse(pat.matcher("bBbBAaAa").matches());
+        
+        pat = Pattern
+        //             1                        2               3         4      5        6        7       8                 9                   10        11
+        .compile("(?:-|(-?\\d+\\d\\d\\d))?(?:-|-(\\d\\d))?(?:-|-(\\d\\d))?(T)?(?:(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?)?(?:(?:((?:\\+|\\-)\\d\\d):(\\d\\d))|(Z))?");
+        Matcher mat = pat.matcher("-1234-21-31T41:51:61.789+71:81");
+        assertTrue(mat.matches());
+        assertEquals("-1234", mat.group(1));
+        assertEquals("21", mat.group(2));
+        assertEquals("31", mat.group(3));
+        assertEquals("T", mat.group(4));
+        assertEquals("41", mat.group(5));
+        assertEquals("51", mat.group(6));
+        assertEquals("61", mat.group(7));
+        assertEquals(".789", mat.group(8));
+        assertEquals("+71", mat.group(9));
+        assertEquals("81", mat.group(10));
+        
+        //positive lookahead
+        pat = Pattern.compile(".*\\.(?=log$).*$");
+        assertTrue(pat.matcher("a.b.c.log").matches());
+        assertFalse(pat.matcher("a.b.c.log.").matches());
+        
+        //negative lookahead
+        pat = Pattern.compile(".*\\.(?!log$).*$");
+        assertFalse(pat.matcher("abc.log").matches());
+        assertTrue(pat.matcher("abc.logg").matches());
+        
+        //positive lookbehind
+        pat = Pattern.compile(".*(?<=abc)\\.log$");
+        assertFalse(pat.matcher("cde.log").matches());
+        assertTrue(pat.matcher("abc.log").matches());
+        
+        //negative lookbehind
+        pat = Pattern.compile(".*(?<!abc)\\.log$");
+        assertTrue(pat.matcher("cde.log").matches());
+        assertFalse(pat.matcher("abc.log").matches());
+        
+        //atomic group
+        pat = Pattern.compile("(?>a*)abb");
+        assertFalse(pat.matcher("aaabb").matches());
+        pat = Pattern.compile("(?>a*)bb");
+        assertTrue(pat.matcher("aaabb").matches());
+        
+        pat = Pattern.compile("(?>a|aa)aabb");
+        assertTrue(pat.matcher("aaabb").matches());
+        pat = Pattern.compile("(?>aa|a)aabb");
+        assertFalse(pat.matcher("aaabb").matches());
+        
+        //quantifiers over look aheads
+        pat = Pattern.compile(".*(?<=abc)*\\.log$");
+        assertTrue(pat.matcher("cde.log").matches());
+        pat = Pattern.compile(".*(?<=abc)+\\.log$");
+        assertFalse(pat.matcher("cde.log").matches());
+        
+    }
+    
+    
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(PatternTest.class);
+    }
+}



Re: svn commit: r387239 [21/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...

Posted by Geir Magnusson Jr <ge...@pobox.com>.
yes indeed

Tim Ellison wrote:
> Stefano Mazzocchi wrote:
>> geirm@apache.org wrote:
>>> Added:
>>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>>>
>>> URL:
>>> http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java?rev=387239&view=auto
>>>
>>> ==============================================================================
>>>
>>> ---
>>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>>> (added)
>>> +++
>>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>>> Mon Mar 20 08:31:09 2006
>>> @@ -0,0 +1,547 @@
>>> +/*
>>> + *  Copyright 2005 The Apache Software Foundation or its licensors,
>>> as applicable.
>> Shouldn't this be 2006?
> 
> Depends when that test was written.  If it was last year then the code
> is (c) 2005 Intel Corp.
> 
> Regards,
> Tim
> 

Re: svn commit: r387239 [21/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...

Posted by Tim Ellison <t....@gmail.com>.
Stefano Mazzocchi wrote:
> geirm@apache.org wrote:
>> Added:
>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java?rev=387239&view=auto
>>
>> ==============================================================================
>>
>> ---
>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>> (added)
>> +++
>> incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
>> Mon Mar 20 08:31:09 2006
>> @@ -0,0 +1,547 @@
>> +/*
>> + *  Copyright 2005 The Apache Software Foundation or its licensors,
>> as applicable.
> 
> Shouldn't this be 2006?

Depends when that test was written.  If it was last year then the code
is (c) 2005 Intel Corp.

Regards,
Tim

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

Re: svn commit: r387239 [21/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...

Posted by Stefano Mazzocchi <st...@apache.org>.
geirm@apache.org wrote:
> Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java
> URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java?rev=387239&view=auto
> ==============================================================================
> --- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java (added)
> +++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerSubtractTest.java Mon Mar 20 08:31:09 2006
> @@ -0,0 +1,547 @@
> +/*
> + *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Shouldn't this be 2006?

-- 
Stefano.