001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Elena Semukhina
019: * @version $Revision$
020: */package org.apache.harmony.tests.java.math;
021:
022: import java.math.BigInteger;
023:
024: import junit.framework.TestCase;
025:
026: /**
027: * Class: java.math.BigInteger
028: * Method: toString(int radix)
029: */
030: public class BigIntegerToStringTest extends TestCase {
031: /**
032: * If 36 < radix < 2 it should be set to 10
033: */
034: public void testRadixOutOfRange() {
035: String value = "442429234853876401";
036: int radix = 10;
037: BigInteger aNumber = new BigInteger(value, radix);
038: String result = aNumber.toString(45);
039: assertTrue(result.equals(value));
040: }
041:
042: /**
043: * test negative number of radix 2
044: */
045: public void testRadix2Neg() {
046: String value = "-101001100010010001001010101110000101010110001010010101010101010101010101010101010101010101010010101";
047: int radix = 2;
048: BigInteger aNumber = new BigInteger(value, radix);
049: String result = aNumber.toString(radix);
050: assertTrue(result.equals(value));
051: }
052:
053: /**
054: * test positive number of radix 2
055: */
056: public void testRadix2Pos() {
057: String value = "101000011111000000110101010101010101010001001010101010101010010101010101010000100010010";
058: int radix = 2;
059: BigInteger aNumber = new BigInteger(value, radix);
060: String result = aNumber.toString(radix);
061: assertTrue(result.equals(value));
062: }
063:
064: /**
065: * test negative number of radix 10
066: */
067: public void testRadix10Neg() {
068: String value = "-2489756308572364789878394872984";
069: int radix = 16;
070: BigInteger aNumber = new BigInteger(value, radix);
071: String result = aNumber.toString(radix);
072: assertTrue(result.equals(value));
073: }
074:
075: /**
076: * test positive number of radix 10
077: */
078: public void testRadix10Pos() {
079: String value = "2387627892347567398736473476";
080: int radix = 16;
081: BigInteger aNumber = new BigInteger(value, radix);
082: String result = aNumber.toString(radix);
083: assertTrue(result.equals(value));
084: }
085:
086: /**
087: * test negative number of radix 16
088: */
089: public void testRadix16Neg() {
090: String value = "-287628a883451b800865c67e8d7ff20";
091: int radix = 16;
092: BigInteger aNumber = new BigInteger(value, radix);
093: String result = aNumber.toString(radix);
094: assertTrue(result.equals(value));
095: }
096:
097: /**
098: * test positive number of radix 16
099: */
100: public void testRadix16Pos() {
101: String value = "287628a883451b800865c67e8d7ff20";
102: int radix = 16;
103: BigInteger aNumber = new BigInteger(value, radix);
104: String result = aNumber.toString(radix);
105: assertTrue(result.equals(value));
106: }
107:
108: /**
109: * test negative number of radix 24
110: */
111: public void testRadix24Neg() {
112: String value = "-287628a88gmn3451b8ijk00865c67e8d7ff20";
113: int radix = 24;
114: BigInteger aNumber = new BigInteger(value, radix);
115: String result = aNumber.toString(radix);
116: assertTrue(result.equals(value));
117: }
118:
119: /**
120: * test positive number of radix 24
121: */
122: public void testRadix24Pos() {
123: String value = "287628a883451bg80ijhk0865c67e8d7ff20";
124: int radix = 24;
125: BigInteger aNumber = new BigInteger(value, radix);
126: String result = aNumber.toString(radix);
127: assertTrue(result.equals(value));
128: }
129:
130: /**
131: * test negative number of radix 24
132: */
133: public void testRadix36Neg() {
134: String value = "-uhguweut98iu4h3478tq3985pq98yeiuth33485yq4aiuhalai485yiaehasdkr8tywi5uhslei8";
135: int radix = 36;
136: BigInteger aNumber = new BigInteger(value, radix);
137: String result = aNumber.toString(radix);
138: assertTrue(result.equals(value));
139: }
140:
141: /**
142: * test positive number of radix 24
143: */
144: public void testRadix36Pos() {
145: String value = "23895lt45y6vhgliuwhgi45y845htsuerhsi4586ysuerhtsio5y68peruhgsil4568ypeorihtse48y6";
146: int radix = 36;
147: BigInteger aNumber = new BigInteger(value, radix);
148: String result = aNumber.toString(radix);
149: assertTrue(result.equals(value));
150: }
151: }
|