The Android Open Source Project | b5de22c | 2012-04-01 00:00:00 -0700 | [diff] [blame] | 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 | * @version $Revision$ |
| 20 | */ |
| 21 | |
| 22 | package libcore.java.math; |
| 23 | |
| 24 | import java.math.BigInteger; |
| 25 | import junit.framework.TestCase; |
| 26 | |
| 27 | public class OldBigIntegerConstructorsTest extends TestCase { |
| 28 | |
| 29 | /** |
| 30 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 31 | */ |
| 32 | public void test_ConstrString1() { |
| 33 | String s = "0"; |
| 34 | BigInteger bi_s = new BigInteger(s); |
| 35 | assertTrue("the BigInteger value is not initialized properly", bi_s.intValue() == 0); |
| 36 | assertEquals("the BigInteger value is not initialized properly", bi_s.toString(), s); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 41 | */ |
| 42 | public void test_ConstrString2() { |
| 43 | String s = "-2147483648"; |
| 44 | BigInteger bi_s = new BigInteger(s); |
| 45 | assertTrue("the BigInteger value is not initialized properly", |
| 46 | bi_s.intValue() == Integer.MIN_VALUE); |
| 47 | assertEquals("the BigInteger value is not initialized properly", bi_s.toString(), s); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 52 | */ |
| 53 | public void test_ConstrString3() { |
| 54 | String s = "2147483647"; |
| 55 | BigInteger bi_s = new BigInteger(s); |
| 56 | assertTrue("the BigInteger value is not initialized properly", |
| 57 | bi_s.intValue() == Integer.MAX_VALUE); |
| 58 | assertEquals("the BigInteger value is not initialized properly", bi_s.toString(), s); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 63 | */ |
| 64 | public void test_ConstrStringExc1() { |
| 65 | try { |
| 66 | new BigInteger("01234 56"); |
| 67 | fail("NumberFormatException has not been caught"); |
| 68 | } catch (NumberFormatException e) { |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 74 | */ |
| 75 | public void test_ConstrStringExc2() { |
| 76 | try { |
| 77 | new BigInteger("1234#56"); |
| 78 | fail("NumberFormatException has not been caught"); |
| 79 | } catch (NumberFormatException e) { |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 85 | */ |
| 86 | public void test_ConstrStringExc3() { |
| 87 | try { |
| 88 | new BigInteger("1234.56"); |
| 89 | fail("NumberFormatException has not been caught"); |
| 90 | } catch (NumberFormatException e) { |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * java.math.BigInteger#BigInteger(java.lang.String) |
| 96 | */ |
| 97 | public void test_ConstrStringExc4() { |
| 98 | try { |
| 99 | new BigInteger("1E+1"); |
| 100 | fail("NumberFormatException has not been caught"); |
| 101 | } catch (NumberFormatException e) { |
| 102 | } |
| 103 | } |
| 104 | } |