harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r446491 [18/24] - in /incubator/harmony/enhanced/classlib/trunk/modules: luni-kernel/.settings/ luni-kernel/META-INF/ luni-kernel/make/ luni-kernel/src/main/java/java/lang/ luni-kernel/src/main/java/java/lang/ref/ luni-kernel/src/main/java/...
Date Fri, 15 Sep 2006 03:08:13 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java?view=diff&rev=446491&r1=446490&r2=446491
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java Thu Sep 14 20:08:07 2006
@@ -1,670 +1,670 @@
-/*
- *  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$
- */
-
-package org.apache.harmony.tests.java.math;
-
-import junit.framework.TestCase;
-import java.math.BigInteger;
-
-/**
- * Class:   java.math.BigInteger
- * Methods: divide, remainder, mod, and divideAndRemainder 
- */
-public class BigIntegerDivideTest extends TestCase {
-    /**
-     * Divide by zero
-     */
-    public void testCase1() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
-        byte bBytes[] = {0};
-        int aSign = 1;
-        int bSign = 0;        
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        try {
-            BigInteger result = aNumber.divide(bNumber);
-            fail("ArithmeticException has not been caught");
-        } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
-        }
-    }
-
-    /**
-     * Divide by ZERO
-     */
-    public void testCase2() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
-        int aSign = 1;
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = BigInteger.ZERO;
-        try {
-            BigInteger result = aNumber.divide(bNumber);
-            fail("ArithmeticException has not been caught");
-        } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
-        }
-    }
-
-    /**
-     * Divide two equal positive numbers
-     */
-    public void testCase3() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {1};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide two equal in absolute value numbers of different signes.
-     */
-    public void testCase4() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {-1};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Divide two numbers of different length and different signs.
-     * The second is longer.
-     */
-    public void testCase5() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 1, 2, 3, 4, 5};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * Divide two positive numbers of the same length.
-     * The second is greater.
-     */
-    public void testCase6() {
-        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127};
-        byte bBytes[] = {15, 100, 56, 7, 98, -1, 39, -128, 127};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * Divide two positive numbers.
-     */
-    public void testCase7() {
-        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {23, 115, 11, 78, 35, -11};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide a positive number by a negative one.
-     */
-    public void testCase8() {
-        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-24, -116, -12, -79, -36, 11};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Divide a negative number by a positive one.
-     */
-    public void testCase9() {
-        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {-24, -116, -12, -79, -36, 11};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Divide two negative numbers.
-     */
-    public void testCase10() {
-        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {23, 115, 11, 78, 35, -11};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide zero by a negative number.
-     */
-    public void testCase11() {
-        byte aBytes[] = {0};
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = 0;
-        int bSign = -1;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-    
-    /**
-     * Divide ZERO by a negative number.
-     */
-    public void testCase12() {
-        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int bSign = -1;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = BigInteger.ZERO;
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * Divide a positive number by ONE.
-     */
-    public void testCase13() {
-        byte aBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        int aSign = 1;        
-        byte rBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = BigInteger.ONE;
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide ONE by ONE.
-     */
-    public void testCase14() {
-        byte rBytes[] = {1};
-        BigInteger aNumber = BigInteger.ONE;
-        BigInteger bNumber = BigInteger.ONE;
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-    
-    /**
-     * Verifies the case when borrow != 0 in the private divide method.
-     */
-    public void testDivisionKnuth1() {
-        byte aBytes[] = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
-        byte bBytes[] = {-3, -3, -3, -3};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {0, -5, -12, -33, -96, -36, -105, -56, 92, 15, 48, -109};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Verifies the case when the divisor is already normalized.
-     */
-    public void testDivisionKnuthIsNormalized() {
-        byte aBytes[] = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
-        byte bBytes[] = {-1, -1, -1, -1, -1, -1, -1, -1};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {0, -9, -8, -7, -6, -5, -4, -3};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Verifies the case when the first digits of the dividend
-     * and divisor equal.
-     */
-    public void testDivisionKnuthFirstDigitsEqual() {
-        byte aBytes[] = {2, -3, -4, -5, -1, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
-        byte bBytes[] = {2, -3, -4, -5, -1, -1, -1, -1};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {0, -1, -1, -1, -1, -2, -88, -60, 41};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide the number of one digit by the number of one digit 
-     */
-    public void testDivisionKnuthOneDigitByOneDigit() {
-        byte aBytes[] = {113, -83, 123, -5};
-        byte bBytes[] = {2, -3, -4, -5};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-37};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Divide the number of multi digits by the number of one digit 
-     */
-    public void testDivisionKnuthMultiDigitsByOneDigit() {
-        byte aBytes[] = {113, -83, 123, -5, 18, -34, 67, 39, -29};
-        byte bBytes[] = {2, -3, -4, -5};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-38, 2, 7, 30, 109, -43};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.divide(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Remainder of division by zero
-     */
-    public void testCase15() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
-        byte bBytes[] = {0};
-        int aSign = 1;
-        int bSign = 0;        
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        try {
-            BigInteger result = aNumber.remainder(bNumber);
-            fail("ArithmeticException has not been caught");
-        } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
-        }
-    }
-
-    /**
-     * Remainder of division of equal numbers
-     */
-    public void testCase16() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * Remainder of division of two positive numbers
-     */
-    public void testCase17() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {12, -21, 73, 56, 27};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Remainder of division of two negative numbers
-     */
-    public void testCase18() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {-13, 20, -74, -57, -27};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Remainder of division of two numbers of different signs.
-     * The first is positive.
-     */
-    public void testCase19() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {12, -21, 73, 56, 27};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-    
-    /**
-     * Remainder of division of two numbers of different signs.
-     * The first is negative.
-     */
-    public void testCase20() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {-13, 20, -74, -57, -27};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * Tests the step D6 from the Knuth algorithm
-     */
-    public void testRemainderKnuth1() {
-        byte aBytes[] = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1};
-        byte bBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 7, 18, -89};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide the number of one digit by the number of one digit 
-     */
-    public void testRemainderKnuthOneDigitByOneDigit() {
-        byte aBytes[] = {113, -83, 123, -5};
-        byte bBytes[] = {2, -3, -4, -50};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {2, -9, -14, 53};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * Divide the number of multi digits by the number of one digit 
-     */
-    public void testRemainderKnuthMultiDigitsByOneDigit() {
-        byte aBytes[] = {113, -83, 123, -5, 18, -34, 67, 39, -29};
-        byte bBytes[] = {2, -3, -4, -50};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {2, -37, -60, 59};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.remainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * divideAndRemainder of two numbers of different signs.
-     * The first is negative.
-     */
-    public void testCase21() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[][] = {
-                {-5, 94, -115, -74, -85, 84},
-                {-13, 20, -74, -57, -27}
-        };
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result[] = aNumber.divideAndRemainder(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result[0].toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            if (resBytes[i] != rBytes[0][i]) {
-                fail("Incorrect quotation");
-            }
-        }
-        assertEquals(-1, result[0].signum());
-        resBytes = result[1].toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            if (resBytes[i] != rBytes[1][i]) {
-                fail("Incorrect remainder");
-            }
-            assertEquals(-1, result[1].signum());
-        }
-    }
-    
-    /**
-     * mod when modulus is negative
-     */
-    public void testCase22() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
-        byte bBytes[] = {1, 30, 40, 56, -1, 45};
-        int aSign = 1;
-        int bSign = -1;        
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        try {
-            BigInteger result = aNumber.mod(bNumber);
-            fail("ArithmeticException has not been caught");
-        } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
-        }
-    }
-
-    /**
-     * mod when a divisor is positive
-     */
-    public void testCase23() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {12, -21, 73, 56, 27};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.mod(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * mod when a divisor is negative
-     */
-    public void testCase24() {
-        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
-        byte bBytes[] = {27, -15, 65, 39, 100};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {15, 5, -9, -17, 73};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.mod(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-}
+/*
+ *  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$
+ */
+
+package org.apache.harmony.tests.java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:   java.math.BigInteger
+ * Methods: divide, remainder, mod, and divideAndRemainder 
+ */
+public class BigIntegerDivideTest extends TestCase {
+    /**
+     * Divide by zero
+     */
+    public void testCase1() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {0};
+        int aSign = 1;
+        int bSign = 0;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        try {
+            BigInteger result = aNumber.divide(bNumber);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
+        }
+    }
+
+    /**
+     * Divide by ZERO
+     */
+    public void testCase2() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        try {
+            BigInteger result = aNumber.divide(bNumber);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
+        }
+    }
+
+    /**
+     * Divide two equal positive numbers
+     */
+    public void testCase3() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide two equal in absolute value numbers of different signes.
+     */
+    public void testCase4() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Divide two numbers of different length and different signs.
+     * The second is longer.
+     */
+    public void testCase5() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 1, 2, 3, 4, 5};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * Divide two positive numbers of the same length.
+     * The second is greater.
+     */
+    public void testCase6() {
+        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127};
+        byte bBytes[] = {15, 100, 56, 7, 98, -1, 39, -128, 127};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * Divide two positive numbers.
+     */
+    public void testCase7() {
+        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {23, 115, 11, 78, 35, -11};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide a positive number by a negative one.
+     */
+    public void testCase8() {
+        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-24, -116, -12, -79, -36, 11};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Divide a negative number by a positive one.
+     */
+    public void testCase9() {
+        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-24, -116, -12, -79, -36, 11};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Divide two negative numbers.
+     */
+    public void testCase10() {
+        byte aBytes[] = {1, 100, 56, 7, 98, -1, 39, -128, 127, 5, 6, 7, 8, 9};
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {23, 115, 11, 78, 35, -11};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide zero by a negative number.
+     */
+    public void testCase11() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = 0;
+        int bSign = -1;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+    
+    /**
+     * Divide ZERO by a negative number.
+     */
+    public void testCase12() {
+        byte bBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int bSign = -1;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * Divide a positive number by ONE.
+     */
+    public void testCase13() {
+        byte aBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        int aSign = 1;        
+        byte rBytes[] = {15, 48, -29, 7, 98, -1, 39, -128};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide ONE by ONE.
+     */
+    public void testCase14() {
+        byte rBytes[] = {1};
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+    
+    /**
+     * Verifies the case when borrow != 0 in the private divide method.
+     */
+    public void testDivisionKnuth1() {
+        byte aBytes[] = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {-3, -3, -3, -3};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -5, -12, -33, -96, -36, -105, -56, 92, 15, 48, -109};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Verifies the case when the divisor is already normalized.
+     */
+    public void testDivisionKnuthIsNormalized() {
+        byte aBytes[] = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
+        byte bBytes[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {0, -9, -8, -7, -6, -5, -4, -3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Verifies the case when the first digits of the dividend
+     * and divisor equal.
+     */
+    public void testDivisionKnuthFirstDigitsEqual() {
+        byte aBytes[] = {2, -3, -4, -5, -1, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
+        byte bBytes[] = {2, -3, -4, -5, -1, -1, -1, -1};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {0, -1, -1, -1, -1, -2, -88, -60, 41};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide the number of one digit by the number of one digit 
+     */
+    public void testDivisionKnuthOneDigitByOneDigit() {
+        byte aBytes[] = {113, -83, 123, -5};
+        byte bBytes[] = {2, -3, -4, -5};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Divide the number of multi digits by the number of one digit 
+     */
+    public void testDivisionKnuthMultiDigitsByOneDigit() {
+        byte aBytes[] = {113, -83, 123, -5, 18, -34, 67, 39, -29};
+        byte bBytes[] = {2, -3, -4, -5};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-38, 2, 7, 30, 109, -43};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.divide(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Remainder of division by zero
+     */
+    public void testCase15() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {0};
+        int aSign = 1;
+        int bSign = 0;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        try {
+            BigInteger result = aNumber.remainder(bNumber);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
+        }
+    }
+
+    /**
+     * Remainder of division of equal numbers
+     */
+    public void testCase16() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        byte bBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * Remainder of division of two positive numbers
+     */
+    public void testCase17() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {12, -21, 73, 56, 27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Remainder of division of two negative numbers
+     */
+    public void testCase18() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-13, 20, -74, -57, -27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Remainder of division of two numbers of different signs.
+     * The first is positive.
+     */
+    public void testCase19() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {12, -21, 73, 56, 27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+    
+    /**
+     * Remainder of division of two numbers of different signs.
+     * The first is negative.
+     */
+    public void testCase20() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-13, 20, -74, -57, -27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * Tests the step D6 from the Knuth algorithm
+     */
+    public void testRemainderKnuth1() {
+        byte aBytes[] = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1};
+        byte bBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 7, 18, -89};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide the number of one digit by the number of one digit 
+     */
+    public void testRemainderKnuthOneDigitByOneDigit() {
+        byte aBytes[] = {113, -83, 123, -5};
+        byte bBytes[] = {2, -3, -4, -50};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {2, -9, -14, 53};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * Divide the number of multi digits by the number of one digit 
+     */
+    public void testRemainderKnuthMultiDigitsByOneDigit() {
+        byte aBytes[] = {113, -83, 123, -5, 18, -34, 67, 39, -29};
+        byte bBytes[] = {2, -3, -4, -50};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {2, -37, -60, 59};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.remainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * divideAndRemainder of two numbers of different signs.
+     * The first is negative.
+     */
+    public void testCase21() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[][] = {
+                {-5, 94, -115, -74, -85, 84},
+                {-13, 20, -74, -57, -27}
+        };
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result[] = aNumber.divideAndRemainder(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result[0].toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            if (resBytes[i] != rBytes[0][i]) {
+                fail("Incorrect quotation");
+            }
+        }
+        assertEquals(-1, result[0].signum());
+        resBytes = result[1].toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            if (resBytes[i] != rBytes[1][i]) {
+                fail("Incorrect remainder");
+            }
+            assertEquals(-1, result[1].signum());
+        }
+    }
+    
+    /**
+     * mod when modulus is negative
+     */
+    public void testCase22() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {1, 30, 40, 56, -1, 45};
+        int aSign = 1;
+        int bSign = -1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        try {
+            BigInteger result = aNumber.mod(bNumber);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
+        }
+    }
+
+    /**
+     * mod when a divisor is positive
+     */
+    public void testCase23() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {12, -21, 73, 56, 27};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.mod(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * mod when a divisor is negative
+     */
+    public void testCase24() {
+        byte aBytes[] = {-127, 100, 56, 7, 98, -1, 39, -128, 127, 75};
+        byte bBytes[] = {27, -15, 65, 39, 100};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {15, 5, -9, -17, 73};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.mod(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerHashCodeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerHashCodeTest.java?view=diff&rev=446491&r1=446490&r2=446491
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerHashCodeTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerHashCodeTest.java Thu Sep 14 20:08:07 2006
@@ -1,98 +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$
- */
-
-package org.apache.harmony.tests.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);
-        }
-    }
-}
+/*
+ *  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$
+ */
+
+package org.apache.harmony.tests.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);
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerHashCodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java?view=diff&rev=446491&r1=446490&r2=446491
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java Thu Sep 14 20:08:07 2006
@@ -1,324 +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$
- */
-
-package org.apache.harmony.tests.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) {
-			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
-		}
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-	
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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) {
-			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
-		}
-	}
-	
-	/**
-	 * 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) {
-			assertEquals("Improper exception message", "BigInteger not invertible.", e.getMessage());
-		}
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-	
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-	
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 0, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-
-	/**
-	 * 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]);
-		}
-		assertEquals("incorrect sign", 1, result.signum());
-	}
-}
+/*
+ *  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$
+ */
+
+package org.apache.harmony.tests.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) {
+			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
+		}
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+	
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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) {
+			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
+		}
+	}
+	
+	/**
+	 * 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) {
+			assertEquals("Improper exception message", "BigInteger not invertible.", e.getMessage());
+		}
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+	
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+	
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 0, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+
+	/**
+	 * 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]);
+		}
+		assertEquals("incorrect sign", 1, result.signum());
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message