Home | History | Annotate | Download | only in lang
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package libcore.java.lang;
     18 
     19 import junit.framework.TestCase;
     20 
     21 public class OldFloatTest extends TestCase {
     22 
     23     public void test_ConstructorLjava_lang_String() {
     24         try {
     25             new Float("900.89ff");
     26             fail("NumberFormatException is not thrown.");
     27         } catch(NumberFormatException nfe) {
     28            //expected
     29         }
     30     }
     31 
     32     public void test_ConstructorD() {
     33         Float f = new Float(Double.MAX_VALUE);
     34         assertTrue("Created incorrect float", f.floatValue() == Float.POSITIVE_INFINITY);
     35     }
     36 
     37     public void test_parseFloatLExceptions() {
     38         String [] incorrectStrings = {"", ";", "99999999EE999999", "99999l",
     39                  "0x1.f.ffffep127"};
     40         for(int i = 0; i < incorrectStrings.length; i++) {
     41             try {
     42                 Float.parseFloat(incorrectStrings[i]);
     43                 fail("NumberFormatException is not thrown for string: "
     44                         + incorrectStrings[i]);
     45             } catch(NumberFormatException nfe) {
     46                 //expected
     47             }
     48         }
     49     }
     50 
     51     public void test_floatToIntBitsF() {
     52         assertEquals(0x7f800000, Float.floatToIntBits(Float.POSITIVE_INFINITY));
     53         assertEquals(0xff800000, Float.floatToIntBits(Float.NEGATIVE_INFINITY));
     54         assertEquals(0x7fc00000, Float.floatToIntBits(Float.NaN));
     55     }
     56 
     57     public void test_floatToRawIntBitsF() {
     58         assertEquals(0x7f800000, Float.floatToRawIntBits(Float.POSITIVE_INFINITY));
     59         assertEquals(0xff800000, Float.floatToRawIntBits(Float.NEGATIVE_INFINITY));
     60         assertEquals(0x7fc00000, Float.floatToRawIntBits(Float.NaN));
     61     }
     62 
     63     public void test_hashCode() {
     64         assertTrue(new Float(Float.MAX_VALUE).hashCode() != new Float(Float.MIN_VALUE).hashCode());
     65     }
     66 
     67     public void test_intBitsToFloatI() {
     68         assertEquals(Float.POSITIVE_INFINITY, Float.intBitsToFloat(0x7f800000));
     69         assertEquals(Float.NEGATIVE_INFINITY, Float.intBitsToFloat(0xff800000));
     70 
     71         assertEquals(Float.NaN, Float.intBitsToFloat(0x7f800001));
     72         assertEquals(Float.NaN, Float.intBitsToFloat(0x7fffffff));
     73         assertEquals(Float.NaN, Float.intBitsToFloat(0xff800001));
     74         assertEquals(Float.NaN, Float.intBitsToFloat(0xffffffff));
     75     }
     76 
     77     public void test_intValue() {
     78         assertEquals(Integer.MAX_VALUE, new Float(Float.MAX_VALUE).intValue());
     79         assertEquals(0, new Float(Float.MIN_VALUE).intValue());
     80     }
     81 
     82     public void test_isNaNF() {
     83         assertFalse(Float.isNaN(12.09f));
     84         assertFalse(Float.isNaN(Float.MAX_VALUE));
     85         assertFalse(Float.isNaN(Float.MIN_VALUE));
     86     }
     87 
     88     public void test_longValue() {
     89         assertEquals(Long.MAX_VALUE, new Float(Float.MAX_VALUE).longValue());
     90         assertEquals(0, new Float(Float.MIN_VALUE).longValue());
     91     }
     92 }
     93