Home | History | Annotate | Download | only in math
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Elena Semukhina
     19  */
     20 
     21 package org.apache.harmony.tests.java.math;
     22 
     23 import java.math.BigInteger;
     24 
     25 import junit.framework.TestCase;
     26 
     27 /**
     28  * Class:   java.math.BigInteger
     29  * Method: toString(int radix)
     30  */
     31 public class BigIntegerToStringTest extends TestCase {
     32     /**
     33      * If 36 < radix < 2 it should be set to 10
     34      */
     35     public void testRadixOutOfRange() {
     36         String value = "442429234853876401";
     37         int radix = 10;
     38         BigInteger aNumber = new BigInteger(value, radix);
     39         String result = aNumber.toString(45);
     40         assertTrue(result.equals(value));
     41     }
     42 
     43     /**
     44      * test negative number of radix 2
     45      */
     46     public void testRadix2Neg() {
     47         String value = "-101001100010010001001010101110000101010110001010010101010101010101010101010101010101010101010010101";
     48         int radix = 2;
     49         BigInteger aNumber = new BigInteger(value, radix);
     50         String result = aNumber.toString(radix);
     51         assertTrue(result.equals(value));
     52     }
     53 
     54     /**
     55      * test positive number of radix 2
     56      */
     57     public void testRadix2Pos() {
     58         String value = "101000011111000000110101010101010101010001001010101010101010010101010101010000100010010";
     59         int radix = 2;
     60         BigInteger aNumber = new BigInteger(value, radix);
     61         String result = aNumber.toString(radix);
     62         assertTrue(result.equals(value));
     63     }
     64 
     65     /**
     66      * test negative number of radix 10
     67      */
     68     public void testRadix10Neg() {
     69         String value = "-2489756308572364789878394872984";
     70         int radix = 16;
     71         BigInteger aNumber = new BigInteger(value, radix);
     72         String result = aNumber.toString(radix);
     73         assertTrue(result.equals(value));
     74     }
     75 
     76     /**
     77      * test positive number of radix 10
     78      */
     79     public void testRadix10Pos() {
     80         String value = "2387627892347567398736473476";
     81         int radix = 16;
     82         BigInteger aNumber = new BigInteger(value, radix);
     83         String result = aNumber.toString(radix);
     84         assertTrue(result.equals(value));
     85     }
     86 
     87     /**
     88      * test negative number of radix 16
     89      */
     90     public void testRadix16Neg() {
     91         String value = "-287628a883451b800865c67e8d7ff20";
     92         int radix = 16;
     93         BigInteger aNumber = new BigInteger(value, radix);
     94         String result = aNumber.toString(radix);
     95         assertTrue(result.equals(value));
     96     }
     97 
     98     /**
     99      * test positive number of radix 16
    100      */
    101     public void testRadix16Pos() {
    102         String value = "287628a883451b800865c67e8d7ff20";
    103         int radix = 16;
    104         BigInteger aNumber = new BigInteger(value, radix);
    105         String result = aNumber.toString(radix);
    106         assertTrue(result.equals(value));
    107     }
    108 
    109     /**
    110      * test negative number of radix 24
    111      */
    112     public void testRadix24Neg() {
    113         String value = "-287628a88gmn3451b8ijk00865c67e8d7ff20";
    114         int radix = 24;
    115         BigInteger aNumber = new BigInteger(value, radix);
    116         String result = aNumber.toString(radix);
    117         assertTrue(result.equals(value));
    118     }
    119 
    120     /**
    121      * test positive number of radix 24
    122      */
    123     public void testRadix24Pos() {
    124         String value = "287628a883451bg80ijhk0865c67e8d7ff20";
    125         int radix = 24;
    126         BigInteger aNumber = new BigInteger(value, radix);
    127         String result = aNumber.toString(radix);
    128         assertTrue(result.equals(value));
    129     }
    130 
    131     /**
    132      * test negative number of radix 24
    133      */
    134     public void testRadix36Neg() {
    135         String value = "-uhguweut98iu4h3478tq3985pq98yeiuth33485yq4aiuhalai485yiaehasdkr8tywi5uhslei8";
    136         int radix = 36;
    137         BigInteger aNumber = new BigInteger(value, radix);
    138         String result = aNumber.toString(radix);
    139         assertTrue(result.equals(value));
    140     }
    141 
    142     /**
    143      * test positive number of radix 24
    144      */
    145     public void testRadix36Pos() {
    146         String value = "23895lt45y6vhgliuwhgi45y845htsuerhsi4586ysuerhtsio5y68peruhgsil4568ypeorihtse48y6";
    147         int radix = 36;
    148         BigInteger aNumber = new BigInteger(value, radix);
    149         String result = aNumber.toString(radix);
    150         assertTrue(result.equals(value));
    151     }
    152 }
    153