Source Code Cross Referenced for FloatTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
0002:         * contributor license agreements.  See the NOTICE file distributed with
0003:         * this work for additional information regarding copyright ownership.
0004:         * The ASF licenses this file to You under the Apache License, Version 2.0
0005:         * (the "License"); you may not use this file except in compliance with
0006:         * the License.  You may obtain a copy of the License at
0007:         * 
0008:         *     http://www.apache.org/licenses/LICENSE-2.0
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.apache.harmony.luni.tests.java.lang;
0018:
0019:        import junit.framework.TestCase;
0020:
0021:        public class FloatTest extends TestCase {
0022:
0023:            private static final int rawBitsFor3_4eN38To38[] = { 0x1394470,
0024:                    0x2e7958c, 0x490bd77, 0x634ecd5, 0x7e2280b, 0x98d5907,
0025:                    0xb30af48, 0xcdcdb1a, 0xe8a08f0, 0x102c8b2d, 0x11d7adf8,
0026:                    0x1386ccbb, 0x15287fe9, 0x16d29fe4, 0x1883a3ee, 0x1a248cea,
0027:                    0x1bcdb025, 0x1d808e17, 0x1f20b19d, 0x20c8de04, 0x227b1585,
0028:                    0x241ced73, 0x25c428d0, 0x27753303, 0x29193fe2, 0x2abf8fdb,
0029:                    0x2c6f73d1, 0x2e15a863, 0x2fbb127c, 0x3169d71a, 0x33122671,
0030:                    0x34b6b00d, 0x36645c10, 0x380eb98a, 0x39b267ec, 0x3b5f01e8,
0031:                    0x3d0b6131, 0x3eae397d, 0x4059c7dc, 0x42081cea, 0x43aa2424,
0032:                    0x4554ad2d, 0x4704ec3c, 0x48a6274b, 0x4a4fb11e, 0x4c01ceb3,
0033:                    0x4da2425f, 0x4f4ad2f7, 0x50fd87b5, 0x529e74d1, 0x54461205,
0034:                    0x55f79687, 0x579abe14, 0x59416d99, 0x5af1c900, 0x5c971da0,
0035:                    0x5e3ce508, 0x5fec1e4a, 0x619392ee, 0x633877a9, 0x64e69594,
0036:                    0x66901d7c, 0x683424dc, 0x69e12e12, 0x6b8cbccb, 0x6d2febfe,
0037:                    0x6edbe6fe, 0x7089705f, 0x722bcc76, 0x73d6bf94, 0x758637bc,
0038:                    0x7727c5ac, 0x78d1b717, 0x7a83126e, 0x7c23d70a, 0x7dcccccc,
0039:                    0x7f7fffff };
0040:
0041:            private static final String expectedStringFor3_4eN38To38[] = {
0042:                    "3.4028235E-38", "3.4028235E-37", "3.4028233E-36",
0043:                    "3.4028234E-35", "3.4028236E-34", "3.4028236E-33",
0044:                    "3.4028234E-32", "3.4028234E-31", "3.4028233E-30",
0045:                    "3.4028236E-29", "3.4028235E-28", "3.4028235E-27",
0046:                    "3.4028233E-26", "3.4028235E-25", "3.4028233E-24",
0047:                    "3.4028235E-23", "3.4028236E-22", "3.4028235E-21",
0048:                    "3.4028236E-20", "3.4028236E-19", "3.4028236E-18",
0049:                    "3.4028235E-17", "3.4028236E-16", "3.4028234E-15",
0050:                    "3.4028234E-14", "3.4028235E-13", "3.4028234E-12",
0051:                    "3.4028235E-11", "3.4028236E-10", "3.4028234E-9",
0052:                    "3.4028236E-8", "3.4028236E-7", "3.4028235E-6",
0053:                    "3.4028235E-5", "3.4028233E-4", "0.0034028236",
0054:                    "0.034028236", "0.34028235", "3.4028234", "34.028236",
0055:                    "340.28235", "3402.8235", "34028.234", "340282.34",
0056:                    "3402823.5", "3.4028236E7", "3.40282336E8", "3.40282342E9",
0057:                    "3.40282348E10", "3.40282343E11", "3.40282337E12",
0058:                    "3.40282353E13", "3.4028234E14", "3.4028234E15",
0059:                    "3.40282356E16", "3.40282356E17", "3.40282356E18",
0060:                    "3.4028236E19", "3.4028235E20", "3.4028233E21",
0061:                    "3.4028235E22", "3.4028233E23", "3.4028236E24",
0062:                    "3.4028234E25", "3.4028233E26", "3.4028234E27",
0063:                    "3.4028235E28", "3.4028236E29", "3.4028233E30",
0064:                    "3.4028235E31", "3.4028233E32", "3.4028236E33",
0065:                    "3.4028236E34", "3.4028234E35", "3.4028236E36",
0066:                    "3.4028235E37", "3.4028235E38" };
0067:
0068:            private static final int rawBitsFor1_17eN38To38[] = { 0x80800000,
0069:                    0x82200000, 0x83c80000, 0x857a0000, 0x871c4000, 0x88c35000,
0070:                    0x8a742400, 0x8c189680, 0x8dbebc20, 0x8f6e6b28, 0x911502f9,
0071:                    0x92ba43b7, 0x9468d4a5, 0x961184e7, 0x97b5e621, 0x99635fa9,
0072:                    0x9b0e1bca, 0x9cb1a2bc, 0x9e5e0b6b, 0xa00ac723, 0xa1ad78ec,
0073:                    0xa358d727, 0xa5078678, 0xa6a96816, 0xa853c21c, 0xaa045951,
0074:                    0xaba56fa6, 0xad4ecb8f, 0xaf013f39, 0xb0a18f08, 0xb249f2ca,
0075:                    0xb3fc6f7c, 0xb59dc5ae, 0xb7453719, 0xb8f684df, 0xba9a130c,
0076:                    0xbc4097ce, 0xbdf0bdc2, 0xbf967699, 0xc13c1440, 0xc2eb1950,
0077:                    0xc492efd2, 0xc637abc6, 0xc7e596b8, 0xc98f7e33, 0xcb335dc0,
0078:                    0xcce0352f, 0xce8c213e, 0xd02f298d, 0xd1daf3f0, 0xd388d876,
0079:                    0xd52b0e94, 0xd6d5d239, 0xd885a363, 0xda270c3c, 0xdbd0cf4b,
0080:                    0xdd82818f, 0xdf2321f3, 0xe0cbea70, 0xe27ee50b, 0xe41f4f27,
0081:                    0xe5c722f1, 0xe778ebad, 0xe91b934c, 0xeac2781f, 0xec731627,
0082:                    0xee17edd8, 0xefbde94f, 0xf16d63a2, 0xf3145e45, 0xf4b975d7,
0083:                    0xf667d34c, 0xf810e410, 0xf9b51d14, 0xfb626459, 0xfd0d7eb7,
0084:                    0xfeb0de65 };
0085:
0086:            private static final String expectedStringFor1_17eN38To38[] = {
0087:                    "-1.17549435E-38", "-1.1754944E-37", "-1.17549435E-36",
0088:                    "-1.17549435E-35", "-1.1754944E-34", "-1.17549435E-33",
0089:                    "-1.17549435E-32", "-1.1754944E-31", "-1.17549435E-30",
0090:                    "-1.17549435E-29", "-1.1754944E-28", "-1.1754943E-27",
0091:                    "-1.17549435E-26", "-1.1754943E-25", "-1.1754944E-24",
0092:                    "-1.1754943E-23", "-1.1754944E-22", "-1.1754943E-21",
0093:                    "-1.1754943E-20", "-1.1754943E-19", "-1.1754944E-18",
0094:                    "-1.1754944E-17", "-1.1754943E-16", "-1.1754943E-15",
0095:                    "-1.1754944E-14", "-1.1754943E-13", "-1.1754944E-12",
0096:                    "-1.1754943E-11", "-1.1754943E-10", "-1.1754944E-9",
0097:                    "-1.1754944E-8", "-1.1754943E-7", "-1.1754944E-6",
0098:                    "-1.1754943E-5", "-1.1754943E-4", "-0.0011754944",
0099:                    "-0.011754943", "-0.117549434", "-1.1754943", "-11.754944",
0100:                    "-117.54944", "-1175.4944", "-11754.943", "-117549.44",
0101:                    "-1175494.4", "-1.1754944E7", "-1.17549432E8",
0102:                    "-1.1754944E9", "-1.17549435E10", "-1.17549433E11",
0103:                    "-1.17549433E12", "-1.17549438E13", "-1.17549438E14",
0104:                    "-1.1754943E15", "-1.17549432E16", "-1.17549432E17",
0105:                    "-1.17549434E18", "-1.1754944E19", "-1.1754944E20",
0106:                    "-1.1754943E21", "-1.1754943E22", "-1.1754944E23",
0107:                    "-1.17549434E24", "-1.1754943E25", "-1.1754943E26",
0108:                    "-1.17549434E27", "-1.1754943E28", "-1.1754944E29",
0109:                    "-1.1754943E30", "-1.1754943E31", "-1.1754944E32",
0110:                    "-1.1754943E33", "-1.1754944E34", "-1.1754944E35",
0111:                    "-1.1754944E36", "-1.1754943E37", "-1.1754943E38" };
0112:
0113:            private void doTestCompareRawBits(String originalFloatString,
0114:                    int expectedRawBits, String expectedString) {
0115:                int rawBits;
0116:                float result = Float.parseFloat(originalFloatString);
0117:                rawBits = Float.floatToIntBits(result);
0118:                assertEquals("Original float(" + originalFloatString
0119:                        + ") Converted float(" + result + ") Expecting:"
0120:                        + Integer.toHexString(expectedRawBits) + " Got: "
0121:                        + Integer.toHexString(rawBits), expectedRawBits,
0122:                        rawBits);
0123:            }
0124:
0125:            /**
0126:             * @tests java.lang.Float#Float(float)
0127:             */
0128:            public void test_ConstructorF() {
0129:                // Test for method java.lang.Float(float)
0130:
0131:                Float f = new Float(900.89f);
0132:                assertTrue("Created incorrect float", f.floatValue() == 900.89f);
0133:            }
0134:
0135:            /**
0136:             * @tests java.lang.Float#Float(java.lang.String)
0137:             */
0138:            public void test_ConstructorLjava_lang_String() {
0139:                // Test for method java.lang.Float(java.lang.String)
0140:
0141:                Float f = new Float("900.89");
0142:                assertTrue("Created incorrect Float", f.floatValue() == 900.89f);
0143:            }
0144:
0145:            /**
0146:             * @tests java.lang.Float#byteValue()
0147:             */
0148:            public void test_byteValue() {
0149:                // Test for method byte java.lang.Float.byteValue()
0150:                Float f = new Float(0.46874f);
0151:                Float f2 = new Float(90.8f);
0152:                assertTrue("Returned incorrect byte value", f.byteValue() == 0
0153:                        && f2.byteValue() == 90);
0154:            }
0155:
0156:            /**
0157:             * @tests java.lang.Float#compareTo(java.lang.Float)
0158:             * @tests java.lang.Float#compare(float, float)
0159:             */
0160:            public void test_compare() {
0161:                float[] values = new float[] { Float.NEGATIVE_INFINITY,
0162:                        -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
0163:                        Float.MIN_VALUE, 2f, Float.MAX_VALUE,
0164:                        Float.POSITIVE_INFINITY, Float.NaN };
0165:                for (int i = 0; i < values.length; i++) {
0166:                    float f1 = values[i];
0167:                    assertTrue("compare() should be equal: " + f1, Float
0168:                            .compare(f1, f1) == 0);
0169:                    Float F1 = new Float(f1);
0170:                    assertTrue("compareTo() should be equal: " + f1, F1
0171:                            .compareTo(F1) == 0);
0172:                    for (int j = i + 1; j < values.length; j++) {
0173:                        float f2 = values[j];
0174:                        assertTrue("compare() " + f1 + " should be less " + f2,
0175:                                Float.compare(f1, f2) == -1);
0176:                        assertTrue("compare() " + f2 + " should be greater "
0177:                                + f1, Float.compare(f2, f1) == 1);
0178:                        Float F2 = new Float(f2);
0179:                        assertTrue("compareTo() " + f1 + " should be less "
0180:                                + f2, F1.compareTo(F2) == -1);
0181:                        assertTrue("compareTo() " + f2 + " should be greater "
0182:                                + f1, F2.compareTo(F1) == 1);
0183:                    }
0184:                }
0185:
0186:                try {
0187:                    new Float(0.0F).compareTo(null);
0188:                    fail("No NPE");
0189:                } catch (NullPointerException e) {
0190:                }
0191:            }
0192:
0193:            /**
0194:             * @tests java.lang.Float#doubleValue()
0195:             */
0196:            public void test_doubleValue() {
0197:                // Test for method double java.lang.Float.doubleValue()
0198:                assertTrue(
0199:                        "Incorrect double value returned",
0200:                        Math
0201:                                .abs(new Float(999999.999f).doubleValue() - 999999.999d) < 1);
0202:            }
0203:
0204:            /**
0205:             * @tests java.lang.Float#floatToIntBits(float)
0206:             */
0207:            public void test_floatToIntBitsF() {
0208:                float f = 9876.2345f;
0209:                int bits = Float.floatToIntBits(f);
0210:                float r = Float.intBitsToFloat(bits);
0211:                assertTrue("Incorrect intBits returned", f == r);
0212:            }
0213:
0214:            /**
0215:             * @tests java.lang.Float#floatToRawIntBits(float)
0216:             */
0217:            public void test_floatToRawIntBitsF() {
0218:                int i = 0x7fc004d2;
0219:                float f = Float.intBitsToFloat(i);
0220:                assertTrue("Wrong raw bits", Float.floatToRawIntBits(f) == i);
0221:            }
0222:
0223:            /**
0224:             * @tests java.lang.Float#floatValue()
0225:             */
0226:            public void test_floatValue() {
0227:                // Test for method float java.lang.Float.floatValue()
0228:                Float f = new Float(87.657f);
0229:                Float f2 = new Float(-0.876f);
0230:                assertTrue("Returned incorrect floatValue",
0231:                        f.floatValue() == 87.657f
0232:                                && (f2.floatValue() == -0.876f));
0233:
0234:            }
0235:
0236:            /**
0237:             * @tests java.lang.Float#hashCode()
0238:             */
0239:            public void test_hashCode() {
0240:                // Test for method int java.lang.Float.hashCode()
0241:                Float f = new Float(1908.8786f);
0242:                assertTrue("Returned invalid hash code for 1908.8786f", f
0243:                        .hashCode() == Float.floatToIntBits(1908.8786f));
0244:
0245:                f = new Float(-1.112f);
0246:                assertTrue("Returned invalid hash code for -1.112", f
0247:                        .hashCode() == Float.floatToIntBits(-1.112f));
0248:
0249:                f = new Float(0f);
0250:                assertTrue("Returned invalid hash code for 0",
0251:                        f.hashCode() == Float.floatToIntBits(0f));
0252:
0253:            }
0254:
0255:            /**
0256:             * @tests java.lang.Float#intBitsToFloat(int)
0257:             */
0258:            public void test_intBitsToFloatI() {
0259:                float f = 9876.2345f;
0260:                int bits = Float.floatToIntBits(f);
0261:                float r = Float.intBitsToFloat(bits);
0262:                assertEquals("Incorrect intBits returned", f, r, 0F);
0263:            }
0264:
0265:            /**
0266:             * @tests java.lang.Float#intValue()
0267:             */
0268:            public void test_intValue() {
0269:                // Test for method int java.lang.Float.intValue()
0270:                Float f = new Float(0.46874f);
0271:                Float f2 = new Float(90.8f);
0272:                assertTrue("Returned incorrect int value", f.intValue() == 0
0273:                        && f2.intValue() == 90);
0274:            }
0275:
0276:            /**
0277:             * @tests java.lang.Float#isInfinite()
0278:             */
0279:            public void test_isInfinite() {
0280:                // Test for method boolean java.lang.Float.isInfinite()
0281:                assertTrue("Infinity check failed", (new Float(
0282:                        Float.POSITIVE_INFINITY).isInfinite() && new Float(
0283:                        Float.NEGATIVE_INFINITY).isInfinite())
0284:                        && !(new Float(0.13131414f).isInfinite()));
0285:            }
0286:
0287:            /**
0288:             * @tests java.lang.Float#isInfinite(float)
0289:             */
0290:            public void test_isInfiniteF() {
0291:                // Test for method boolean java.lang.Float.isInfinite(float)
0292:
0293:                assertTrue("Infinity check failed", Float
0294:                        .isInfinite(Float.POSITIVE_INFINITY)
0295:                        && (Float.isInfinite(Float.NEGATIVE_INFINITY))
0296:                        && !(Float.isInfinite(1.0f)));
0297:            }
0298:
0299:            /**
0300:             * @tests java.lang.Float#isNaN()
0301:             */
0302:            public void test_isNaN() {
0303:                // Test for method boolean java.lang.Float.isNaN()
0304:                assertTrue("NAN check failed", new Float(Float.NaN).isNaN()
0305:                        && !(new Float(1.0f).isNaN()));
0306:            }
0307:
0308:            /**
0309:             * @tests java.lang.Float#isNaN(float)
0310:             */
0311:            public void test_isNaNF() {
0312:                // Test for method boolean java.lang.Float.isNaN(float)
0313:                assertTrue("NaN check failed", Float.isNaN(Float.NaN)
0314:                        && !(Float.isNaN(12.09f)));
0315:            }
0316:
0317:            /**
0318:             * @tests java.lang.Float#longValue()
0319:             */
0320:            public void test_longValue() {
0321:                // Test for method long java.lang.Float.longValue()
0322:                Float f = new Float(0.46874f);
0323:                Float f2 = new Float(90.8f);
0324:                assertTrue("Returned incorrect long value", f.longValue() == 0
0325:                        && f2.longValue() == 90);
0326:            }
0327:
0328:            /**
0329:             * @tests java.lang.Float#parseFloat(java.lang.String)
0330:             */
0331:            public void test_parseFloatLjava_lang_String() {
0332:                assertEquals(
0333:                        "Incorrect float returned, expected zero.",
0334:                        0.0,
0335:                        Float
0336:                                .parseFloat("7.0064923216240853546186479164495e-46"),
0337:                        0.0);
0338:                assertEquals(
0339:                        "Incorrect float returned, expected minimum float.",
0340:                        Float.MIN_VALUE,
0341:                        Float
0342:                                .parseFloat("7.0064923216240853546186479164496e-46"),
0343:                        0.0);
0344:
0345:                doTestCompareRawBits(
0346:                        "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
0347:                        0x800000, "1.17549435E-38");
0348:                doTestCompareRawBits(
0349:                        "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
0350:                        0x7fffff, "1.1754942E-38");
0351:
0352:                /* Test a set of regular floats with exponents from -38 to +38 */
0353:                for (int i = 38; i > 3; i--) {
0354:                    String testString;
0355:                    testString = "3.4028234663852886e-" + i;
0356:                    doTestCompareRawBits(testString,
0357:                            rawBitsFor3_4eN38To38[38 - i],
0358:                            expectedStringFor3_4eN38To38[38 - i]);
0359:                }
0360:                doTestCompareRawBits("3.4028234663852886e-3",
0361:                        rawBitsFor3_4eN38To38[38 - 3],
0362:                        expectedStringFor3_4eN38To38[38 - 3]);
0363:                doTestCompareRawBits("3.4028234663852886e-2",
0364:                        rawBitsFor3_4eN38To38[38 - 2],
0365:                        expectedStringFor3_4eN38To38[38 - 2]);
0366:                doTestCompareRawBits("3.4028234663852886e-1",
0367:                        rawBitsFor3_4eN38To38[38 - 1],
0368:                        expectedStringFor3_4eN38To38[38 - 1]);
0369:                doTestCompareRawBits("3.4028234663852886e-0",
0370:                        rawBitsFor3_4eN38To38[38 - 0],
0371:                        expectedStringFor3_4eN38To38[38 - 0]);
0372:                doTestCompareRawBits("3.4028234663852886e+1",
0373:                        rawBitsFor3_4eN38To38[38 + 1],
0374:                        expectedStringFor3_4eN38To38[38 + 1]);
0375:                doTestCompareRawBits("3.4028234663852886e+2",
0376:                        rawBitsFor3_4eN38To38[38 + 2],
0377:                        expectedStringFor3_4eN38To38[38 + 2]);
0378:                doTestCompareRawBits("3.4028234663852886e+3",
0379:                        rawBitsFor3_4eN38To38[38 + 3],
0380:                        expectedStringFor3_4eN38To38[38 + 3]);
0381:                doTestCompareRawBits("3.4028234663852886e+4",
0382:                        rawBitsFor3_4eN38To38[38 + 4],
0383:                        expectedStringFor3_4eN38To38[38 + 4]);
0384:                doTestCompareRawBits("3.4028234663852886e+5",
0385:                        rawBitsFor3_4eN38To38[38 + 5],
0386:                        expectedStringFor3_4eN38To38[38 + 5]);
0387:                doTestCompareRawBits("3.4028234663852886e+6",
0388:                        rawBitsFor3_4eN38To38[38 + 6],
0389:                        expectedStringFor3_4eN38To38[38 + 6]);
0390:
0391:                for (int i = 7; i < 39; i++) {
0392:                    String testString;
0393:                    testString = "3.4028234663852886e+" + i;
0394:                    doTestCompareRawBits(testString,
0395:                            rawBitsFor3_4eN38To38[38 + i],
0396:                            expectedStringFor3_4eN38To38[38 + i]);
0397:                }
0398:
0399:                /* Test another set of regular floats with exponents from -38 to +38 */
0400:                for (int i = 38; i > 3; i--) {
0401:                    String testString;
0402:                    testString = "-1.1754943508222875e-" + i;
0403:                    doTestCompareRawBits(testString,
0404:                            rawBitsFor1_17eN38To38[38 - i],
0405:                            expectedStringFor1_17eN38To38[38 - i]);
0406:                }
0407:                doTestCompareRawBits("-1.1754943508222875e-3",
0408:                        rawBitsFor1_17eN38To38[38 - 3],
0409:                        expectedStringFor1_17eN38To38[38 - 3]);
0410:                doTestCompareRawBits("-1.1754943508222875e-2",
0411:                        rawBitsFor1_17eN38To38[38 - 2],
0412:                        expectedStringFor1_17eN38To38[38 - 2]);
0413:                doTestCompareRawBits("-1.1754943508222875e-1",
0414:                        rawBitsFor1_17eN38To38[38 - 1],
0415:                        expectedStringFor1_17eN38To38[38 - 1]);
0416:                doTestCompareRawBits("-1.1754943508222875e-0",
0417:                        rawBitsFor1_17eN38To38[38 - 0],
0418:                        expectedStringFor1_17eN38To38[38 - 0]);
0419:                doTestCompareRawBits("-1.1754943508222875e+1",
0420:                        rawBitsFor1_17eN38To38[38 + 1],
0421:                        expectedStringFor1_17eN38To38[38 + 1]);
0422:                doTestCompareRawBits("-1.1754943508222875e+2",
0423:                        rawBitsFor1_17eN38To38[38 + 2],
0424:                        expectedStringFor1_17eN38To38[38 + 2]);
0425:                doTestCompareRawBits("-1.1754943508222875e+3",
0426:                        rawBitsFor1_17eN38To38[38 + 3],
0427:                        expectedStringFor1_17eN38To38[38 + 3]);
0428:                doTestCompareRawBits("-1.1754943508222875e+4",
0429:                        rawBitsFor1_17eN38To38[38 + 4],
0430:                        expectedStringFor1_17eN38To38[38 + 4]);
0431:                doTestCompareRawBits("-1.1754943508222875e+5",
0432:                        rawBitsFor1_17eN38To38[38 + 5],
0433:                        expectedStringFor1_17eN38To38[38 + 5]);
0434:                doTestCompareRawBits("-1.1754943508222875e+6",
0435:                        rawBitsFor1_17eN38To38[38 + 6],
0436:                        expectedStringFor1_17eN38To38[38 + 6]);
0437:
0438:                for (int i = 7; i < 39; i++) {
0439:                    String testString;
0440:                    testString = "-1.1754943508222875e+" + i;
0441:                    doTestCompareRawBits(testString,
0442:                            rawBitsFor1_17eN38To38[38 + i],
0443:                            expectedStringFor1_17eN38To38[38 + i]);
0444:                }
0445:
0446:                /* Test denormalized floats (floats with exponents <= -38 */
0447:                doTestCompareRawBits("1.1012984643248170E-45", 1, "1.4E-45");
0448:                doTestCompareRawBits("-1.1012984643248170E-45", 0x80000001,
0449:                        "-1.4E-45");
0450:                doTestCompareRawBits("1.0E-45", 1, "1.4E-45");
0451:                doTestCompareRawBits("-1.0E-45", 0x80000001, "-1.4E-45");
0452:                doTestCompareRawBits("0.9E-45", 1, "1.4E-45");
0453:                doTestCompareRawBits("-0.9E-45", 0x80000001, "-1.4E-45");
0454:                doTestCompareRawBits("4.203895392974451e-45", 3, "4.2E-45");
0455:                doTestCompareRawBits("-4.203895392974451e-45", 0x80000003,
0456:                        "-4.2E-45");
0457:                doTestCompareRawBits("0.004E-45", 0, "0.0");
0458:                doTestCompareRawBits("-0.004E-45", 0x80000000, "-0.0");
0459:
0460:                /*
0461:                 * Test for large floats close to and greater than 3.4028235E38 and
0462:                 * -3.4028235E38
0463:                 */
0464:                doTestCompareRawBits("1.2E+38", 0x7eb48e52, "1.2E38");
0465:                doTestCompareRawBits("-1.2E+38", 0xfeb48e52, "-1.2E38");
0466:                doTestCompareRawBits("3.2E+38", 0x7f70bdc2, "3.2E38");
0467:                doTestCompareRawBits("-3.2E+38", 0xff70bdc2, "-3.2E38");
0468:                doTestCompareRawBits("3.4E+38", 0x7f7fc99e, "3.4E38");
0469:                doTestCompareRawBits("-3.4E+38", 0xff7fc99e, "-3.4E38");
0470:                doTestCompareRawBits("3.4028234663852886E+38", 0x7f7fffff,
0471:                        "3.4028235E38");
0472:                doTestCompareRawBits("-3.4028234663852886E+38", 0xff7fffff,
0473:                        "-3.4028235E38");
0474:                doTestCompareRawBits("3.405E+38", 0x7f800000, "Infinity");
0475:                doTestCompareRawBits("-3.405E+38", 0xff800000, "-Infinity");
0476:                doTestCompareRawBits("3.41E+38", 0x7f800000, "Infinity");
0477:                doTestCompareRawBits("-3.41E+38", 0xff800000, "-Infinity");
0478:                doTestCompareRawBits("3.42E+38", 0x7f800000, "Infinity");
0479:                doTestCompareRawBits("-3.42E+38", 0xff800000, "-Infinity");
0480:                doTestCompareRawBits("1.0E+39", 0x7f800000, "Infinity");
0481:                doTestCompareRawBits("-1.0E+39", 0xff800000, "-Infinity");
0482:            }
0483:
0484:            /**
0485:             * @tests java.lang.Float#parseFloat(java.lang.String)
0486:             */
0487:            public void test_parseFloat_LString_Unusual() {
0488:                float actual;
0489:
0490:                actual = Float
0491:                        .parseFloat("0x00000000000000000000000000000000000000000.0000000000000000000000000000000000000p0000000000000000000000000000000000");
0492:                assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
0493:
0494:                actual = Float
0495:                        .parseFloat("+0Xfffff.fffffffffffffffffffffffffffffffp+99F");
0496:                assertEquals("Returned incorrect value", 6.64614E35f, actual,
0497:                        0.0F);
0498:
0499:                actual = Float.parseFloat("-0X.123456789abcdefp+99f");
0500:                assertEquals("Returned incorrect value", -4.5072022E28f,
0501:                        actual, 0.0F);
0502:
0503:                actual = Float.parseFloat("-0X123456789abcdef.p+1f");
0504:                assertEquals("Returned incorrect value", -1.63971062E17f,
0505:                        actual, 0.0F);
0506:
0507:                actual = Float
0508:                        .parseFloat("-0X000000000000000000000000000001abcdef.0000000000000000000000000001abefp00000000000000000000000000000000000000000004f");
0509:                assertEquals("Returned incorrect value", -4.48585472E8f,
0510:                        actual, 0.0F);
0511:
0512:                actual = Float
0513:                        .parseFloat("0X0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234p600f");
0514:                assertEquals("Returned incorrect value", 5.907252E33f, actual,
0515:                        0.0F);
0516:
0517:                actual = Float.parseFloat("0x1.p9223372036854775807");
0518:                assertEquals("Returned incorrect value",
0519:                        Float.POSITIVE_INFINITY, actual, 0.0F);
0520:
0521:                actual = Float.parseFloat("0x1.p9223372036854775808");
0522:                assertEquals("Returned incorrect value",
0523:                        Float.POSITIVE_INFINITY, actual, 0.0F);
0524:
0525:                actual = Float.parseFloat("0x10.p9223372036854775808");
0526:                assertEquals("Returned incorrect value",
0527:                        Float.POSITIVE_INFINITY, actual, 0.0F);
0528:
0529:                actual = Float.parseFloat("0xabcd.ffffffffp+2000");
0530:                assertEquals("Returned incorrect value",
0531:                        Float.POSITIVE_INFINITY, actual, 0.0F);
0532:
0533:                actual = Float.parseFloat("0x1.p-9223372036854775808");
0534:                assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
0535:
0536:                actual = Float.parseFloat("0x1.p-9223372036854775809");
0537:                assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
0538:
0539:                actual = Float.parseFloat("0x.1p-9223372036854775809");
0540:                assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
0541:            }
0542:
0543:            /**
0544:             * @tests java.lang.Float#parseFloat(java.lang.String)
0545:             */
0546:            public void test_parseFloat_LString_NormalPositiveExponent() {
0547:                int[] expecteds = { 0x3991a2b4, 0x43cc0247, 0x47909009,
0548:                        0x4ac0c009, 0x4e109005, 0x5140c005, 0x5458d805,
0549:                        0x57848402, 0x5a909002, 0x5da8a802, 0x60c0c002,
0550:                        0x63cccc02, 0x66e4e402, 0x69f0f002, 0x6d048401,
0551:                        0x70109001, 0x73169601, 0x76810810, 0x79840840,
0552:                        0x7c8a08a0, 0x7f800000, 0x7f800000, 0x7f800000,
0553:                        0x7f800000, 0x7f800000, };
0554:
0555:                for (int i = 0; i < expecteds.length; i++) {
0556:                    int part = i * 6;
0557:                    String inputString = "0x" + part + "." + part
0558:                            + "0123456789abcdefp" + part;
0559:
0560:                    float actual = Float.parseFloat(inputString);
0561:                    float expected = Float.intBitsToFloat(expecteds[i]);
0562:
0563:                    String expectedString = Integer.toHexString(Float
0564:                            .floatToIntBits(expected));
0565:                    String actualString = Integer.toHexString(Float
0566:                            .floatToIntBits(actual));
0567:                    String errorMsg = i + "th input string is:<" + inputString
0568:                            + ">.The expected result should be:<"
0569:                            + expectedString + ">, but was: <" + actualString
0570:                            + ">. ";
0571:
0572:                    assertEquals(errorMsg, expected, actual, 0.0F);
0573:                }
0574:            }
0575:
0576:            /**
0577:             * @tests java.lang.Float#parseFloat(java.lang.String)
0578:             */
0579:            public void test_parseFloat_LString_NormalNegativeExponent() {
0580:                int[] expecteds = { 0x3991a2b4, 0x3d6e0247, 0x3aa0a009,
0581:                        0x37848405, 0x3420a005, 0x30d4d405, 0x2d848402,
0582:                        0x2a129202, 0x26acac02, 0x2346c602, 0x1fe0e002,
0583:                        0x1c6eee02, 0x19048401, 0x15919101, 0x12189801,
0584:                        0xf028828, 0xb890890, 0x80c88c8, 0x4930930, 0x1198998,
0585:                        0x28028, 0x51c, 0xb, 0x0, 0x0, };
0586:
0587:                for (int i = 0; i < expecteds.length; i++) {
0588:                    int part = i * 7;
0589:                    String inputString = "0x" + part + "." + part
0590:                            + "0123456789abcdefp-" + part;
0591:
0592:                    float actual = Float.parseFloat(inputString);
0593:                    float expected = Float.intBitsToFloat(expecteds[i]);
0594:
0595:                    String expectedString = Integer.toHexString(Float
0596:                            .floatToIntBits(expected));
0597:                    String actualString = Integer.toHexString(Float
0598:                            .floatToIntBits(actual));
0599:                    String errorMsg = i + "th input string is:<" + inputString
0600:                            + ">.The expected result should be:<"
0601:                            + expectedString + ">, but was: <" + actualString
0602:                            + ">. ";
0603:
0604:                    assertEquals(errorMsg, expected, actual, 0.0F);
0605:                }
0606:            }
0607:
0608:            /**
0609:             * @tests java.lang.Float#parseFloat(java.lang.String)
0610:             */
0611:            public void test_parseFloat_LString_MaxNormalBoundary() {
0612:                int[] expecteds = { 0x7f7fffff, 0x7f7fffff, 0x7f7fffff,
0613:                        0x7f800000, 0x7f800000, 0x7f800000,
0614:
0615:                        0xff7fffff, 0xff7fffff, 0xff7fffff, 0xff800000,
0616:                        0xff800000, 0xff800000, };
0617:
0618:                String[] inputs = {
0619:                        "0x1.fffffep127",
0620:                        "0x1.fffffe000000000000000000000000000000000000000000000001p127",
0621:                        "0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
0622:                        "0x1.ffffffp127",
0623:                        "0x1.ffffff000000000000000000000000000000000000000000000001p127",
0624:                        "0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
0625:
0626:                        "-0x1.fffffep127",
0627:                        "-0x1.fffffe000000000000000000000000000000000000000000000001p127",
0628:                        "-0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
0629:                        "-0x1.ffffffp127",
0630:                        "-0x1.ffffff000000000000000000000000000000000000000000000001p127",
0631:                        "-0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127", };
0632:
0633:                for (int i = 0; i < inputs.length; i++) {
0634:                    float actual = Float.parseFloat(inputs[i]);
0635:                    float expected = Float.intBitsToFloat(expecteds[i]);
0636:
0637:                    String expectedString = Integer.toHexString(Float
0638:                            .floatToIntBits(expected));
0639:                    String actualString = Integer.toHexString(Float
0640:                            .floatToIntBits(actual));
0641:                    String errorMsg = i + "th input string is:<" + inputs[i]
0642:                            + ">.The expected result should be:<"
0643:                            + expectedString + ">, but was: <" + actualString
0644:                            + ">. ";
0645:
0646:                    assertEquals(errorMsg, expected, actual, 0.0F);
0647:                }
0648:            }
0649:
0650:            /**
0651:             * @tests java.lang.Float#parseFloat(java.lang.String)
0652:             */
0653:            public void test_parseFloat_LString_MinNormalBoundary() {
0654:                int expecteds[] = { 0x800000, 0x800000, 0x800000, 0x800000,
0655:                        0x800001, 0x800001,
0656:
0657:                        0x80800000, 0x80800000, 0x80800000, 0x80800000,
0658:                        0x80800001, 0x80800001, };
0659:
0660:                String inputs[] = {
0661:                        "0x1.0p-126",
0662:                        "0x1.00000000000000000000000000000000000000000000001p-126",
0663:                        "0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0664:                        "0x1.000001p-126",
0665:                        "0x1.000001000000000000000000000000000000000000000001p-126",
0666:                        "0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0667:
0668:                        "-0x1.0p-126",
0669:                        "-0x1.00000000000000000000000000000000000000000000001p-126",
0670:                        "-0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0671:                        "-0x1.000001p-126",
0672:                        "-0x1.000001000000000000000000000000000000000000000001p-126",
0673:                        "-0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126", };
0674:
0675:                for (int i = 0; i < inputs.length; i++) {
0676:                    float actual = Float.parseFloat(inputs[i]);
0677:                    float expected = Float.intBitsToFloat(expecteds[i]);
0678:
0679:                    String expectedString = Integer.toHexString(Float
0680:                            .floatToIntBits(expected));
0681:                    String actualString = Integer.toHexString(Float
0682:                            .floatToIntBits(actual));
0683:                    String errorMsg = i + "th input string is:<" + inputs[i]
0684:                            + ">.The expected result should be:<"
0685:                            + expectedString + ">, but was: <" + actualString
0686:                            + ">. ";
0687:
0688:                    assertEquals(errorMsg, expected, actual, 0.0F);
0689:                }
0690:            }
0691:
0692:            /**
0693:             * @tests java.lang.Float#parseFloat(java.lang.String)
0694:             */
0695:            public void test_parseFloat_LString_MaxSubNormalBoundary() {
0696:                int expecteds[] = { 0x7fffff, 0x7fffff, 0x7fffff, 0x800000,
0697:                        0x800000, 0x800000,
0698:
0699:                        0x807fffff, 0x807fffff, 0x807fffff, 0x80800000,
0700:                        0x80800000, 0x80800000, };
0701:
0702:                String inputs[] = {
0703:                        "0x0.fffffep-126",
0704:                        "0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
0705:                        "0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0706:                        "0x0.ffffffp-126",
0707:                        "0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
0708:                        "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0709:
0710:                        "-0x0.fffffep-126",
0711:                        "-0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
0712:                        "-0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0713:                        "-0x0.ffffffp-126",
0714:                        "-0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
0715:                        "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126", };
0716:
0717:                for (int i = 0; i < inputs.length; i++) {
0718:                    float actual = Float.parseFloat(inputs[i]);
0719:                    float expected = Float.intBitsToFloat(expecteds[i]);
0720:
0721:                    String expectedString = Integer.toHexString(Float
0722:                            .floatToIntBits(expected));
0723:                    String actualString = Integer.toHexString(Float
0724:                            .floatToIntBits(actual));
0725:                    String errorMsg = i + "th input string is:<" + inputs[i]
0726:                            + ">.The expected result should be:<"
0727:                            + expectedString + ">, but was: <" + actualString
0728:                            + ">. ";
0729:
0730:                    assertEquals(errorMsg, expected, actual, 0.0F);
0731:                }
0732:            }
0733:
0734:            /**
0735:             * @tests java.lang.Float#parseFloat(java.lang.String)
0736:             */
0737:            public void test_parseFloat_LString_MinSubNormalBoundary() {
0738:                int expecteds[] = { 0x1, 0x1, 0x1, 0x2, 0x2, 0x2,
0739:
0740:                0x80000001, 0x80000001, 0x80000001, 0x80000002, 0x80000002,
0741:                        0x80000002, };
0742:
0743:                String inputs[] = {
0744:                        "0x0.000002p-126",
0745:                        "0x0.00000200000000000000000000000000000000000001p-126",
0746:                        "0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0747:                        "0x0.000003p-126",
0748:                        "0x0.000003000000000000000000000000000000000000001p-126",
0749:                        "0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0750:
0751:                        "-0x0.000002p-126",
0752:                        "-0x0.00000200000000000000000000000000000000000001p-126",
0753:                        "-0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0754:                        "-0x0.000003p-126",
0755:                        "-0x0.000003000000000000000000000000000000000000001p-126",
0756:                        "-0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126", };
0757:
0758:                for (int i = 0; i < inputs.length; i++) {
0759:                    float actual = Float.parseFloat(inputs[i]);
0760:                    float expected = Float.intBitsToFloat(expecteds[i]);
0761:
0762:                    String expectedString = Integer.toHexString(Float
0763:                            .floatToIntBits(expected));
0764:                    String actualString = Integer.toHexString(Float
0765:                            .floatToIntBits(actual));
0766:                    String errorMsg = i + "th input string is:<" + inputs[i]
0767:                            + ">.The expected result should be:<"
0768:                            + expectedString + ">, but was: <" + actualString
0769:                            + ">. ";
0770:
0771:                    assertEquals(errorMsg, expected, actual, 0.0F);
0772:                }
0773:            }
0774:
0775:            /**
0776:             * @tests java.lang.Float#parseFloat(java.lang.String)
0777:             */
0778:            public void test_parseFloat_LString_ZeroBoundary() {
0779:                int expecteds[] = { 0x0, 0x0, 0x0, 0x0, 0x1, 0x1,
0780:
0781:                0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000001,
0782:                        0x80000001, };
0783:
0784:                String inputs[] = {
0785:                        "0x0.000000000000000p-126",
0786:                        "0x0.000000000000000000000000000000000000000000000001p-126",
0787:                        "0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0788:                        "0x0.000001p-126",
0789:                        "0x0.000001000000000000000000000000000000000000000001p-126",
0790:                        "0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0791:
0792:                        "-0x0.000000000000000p-126",
0793:                        "-0x0.000000000000000000000000000000000000000000000001p-126",
0794:                        "-0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
0795:                        "-0x0.000001p-126",
0796:                        "-0x0.000001000000000000000000000000000000000000000001p-126",
0797:                        "-0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126", };
0798:
0799:                for (int i = 0; i < inputs.length; i++) {
0800:                    float actual = Float.parseFloat(inputs[i]);
0801:                    float expected = Float.intBitsToFloat(expecteds[i]);
0802:
0803:                    String expectedString = Integer.toHexString(Float
0804:                            .floatToIntBits(expected));
0805:                    String actualString = Integer.toHexString(Float
0806:                            .floatToIntBits(actual));
0807:                    String errorMsg = i + "th input string is:<" + inputs[i]
0808:                            + ">.The expected result should be:<"
0809:                            + expectedString + ">, but was: <" + actualString
0810:                            + ">. ";
0811:
0812:                    assertEquals(errorMsg, expected, actual, 0.0F);
0813:                }
0814:            }
0815:
0816:            /**
0817:             * @tests java.lang.Float#shortValue()
0818:             */
0819:            public void test_shortValue() {
0820:                // Test for method short java.lang.Float.shortValue()
0821:                Float f = new Float(0.46874f);
0822:                Float f2 = new Float(90.8f);
0823:                assertTrue("Returned incorrect short value",
0824:                        f.shortValue() == 0 && f2.shortValue() == 90);
0825:            }
0826:
0827:            /**
0828:             * @tests java.lang.Float#toString()
0829:             */
0830:            public void test_toString() {
0831:                // Test for method java.lang.String java.lang.Float.toString()
0832:
0833:                test_toString(12.90898f, "12.90898");
0834:
0835:                test_toString(1.7014118346046924e+38F, "1.7014118E38");
0836:            }
0837:
0838:            /**
0839:             * @tests java.lang.Float#toString(float)
0840:             */
0841:            public void test_toStringF() {
0842:                // Test for method java.lang.String java.lang.Float.toString(float)
0843:
0844:                float ff;
0845:                String answer;
0846:
0847:                ff = 12.90898f;
0848:                answer = "12.90898";
0849:                assertTrue("Incorrect String representation want " + answer
0850:                        + ", got " + Float.toString(ff), Float.toString(ff)
0851:                        .equals(answer));
0852:
0853:                ff = Float.MAX_VALUE;
0854:                answer = "3.4028235E38";
0855:                assertTrue("Incorrect String representation want " + answer
0856:                        + ", got " + Float.toString(ff), Float.toString(ff)
0857:                        .equals(answer));
0858:            }
0859:
0860:            /**
0861:             * @tests java.lang.Float#valueOf(java.lang.String)
0862:             */
0863:            public void test_valueOfLjava_lang_String() {
0864:                // Test for method java.lang.Float
0865:                // java.lang.Float.valueOf(java.lang.String)
0866:
0867:                Float wanted = new Float(432.1235f);
0868:                Float got = Float.valueOf("432.1235");
0869:                assertTrue("Incorrect float returned--wanted: " + wanted
0870:                        + " but got: " + got, got.equals(wanted));
0871:
0872:                wanted = new Float(0f);
0873:                got = Float.valueOf("0");
0874:                assertTrue("Incorrect float returned--wanted: " + wanted
0875:                        + " but got: " + got, got.equals(wanted));
0876:
0877:                wanted = new Float(-1212.3232f);
0878:                got = Float.valueOf("-1212.3232");
0879:                assertTrue("Incorrect float returned--wanted: " + wanted
0880:                        + " but got: " + got, got.equals(wanted));
0881:
0882:                try {
0883:                    Float.valueOf(null);
0884:                    fail("Expected Float.valueOf(null) to throw NPE.");
0885:                } catch (NullPointerException ex) {
0886:                    // expected
0887:                }
0888:
0889:                try {
0890:                    Float.valueOf("");
0891:                    fail("Expected Float.valueOf(\"\") to throw NFE");
0892:                } catch (NumberFormatException e) {
0893:                    // expected
0894:                }
0895:
0896:                Float posZero = Float.valueOf("+0.0");
0897:                Float negZero = Float.valueOf("-0.0");
0898:                assertFalse("Floattest0", posZero.equals(negZero));
0899:                assertTrue("Floattest1", 0.0f == -0.0f);
0900:
0901:                // Tests for float values by name.
0902:                Float expectedNaN = new Float(Float.NaN);
0903:
0904:                Float posNaN = Float.valueOf("NaN");
0905:                assertTrue("Floattest2", posNaN.equals(expectedNaN));
0906:
0907:                Float posNaNSigned = Float.valueOf("+NaN");
0908:                assertTrue("Floattest3", posNaNSigned.equals(expectedNaN));
0909:
0910:                Float negNaNSigned = Float.valueOf("-NaN");
0911:                assertTrue("Floattest4", negNaNSigned.equals(expectedNaN));
0912:
0913:                Float posInfinite = Float.valueOf("Infinity");
0914:                assertTrue("Floattest5", posInfinite.equals(new Float(
0915:                        Float.POSITIVE_INFINITY)));
0916:
0917:                Float posInfiniteSigned = Float.valueOf("+Infinity");
0918:                assertTrue("Floattest6", posInfiniteSigned.equals(new Float(
0919:                        Float.POSITIVE_INFINITY)));
0920:
0921:                Float negInfiniteSigned = Float.valueOf("-Infinity");
0922:                assertTrue("Floattest7", negInfiniteSigned.equals(new Float(
0923:                        Float.NEGATIVE_INFINITY)));
0924:            }
0925:
0926:            private void test_toString(float ff, String answer) {
0927:                // Test for method java.lang.String java.lang.Double.toString(double)
0928:                assertTrue("Incorrect String representation want " + answer
0929:                        + ", got (" + Float.toString(ff) + ")", Float.toString(
0930:                        ff).equals(answer));
0931:                Float f = new Float(ff);
0932:                assertTrue("Incorrect String representation want " + answer
0933:                        + ", got (" + Float.toString(f.floatValue()) + ")",
0934:                        Float.toString(f.floatValue()).equals(answer));
0935:                assertTrue("Incorrect String representation want " + answer
0936:                        + ", got (" + f.toString() + ")", f.toString().equals(
0937:                        answer));
0938:            }
0939:
0940:            /**
0941:             * @tests java.lang.Float#compareTo(java.lang.Float)
0942:             * @tests java.lang.Float#compare(float, float)
0943:             */
0944:            public void test_compareToLjava_lang_Float() {
0945:                // A selection of float values in ascending order.
0946:                float[] values = new float[] { Float.NEGATIVE_INFINITY,
0947:                        -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
0948:                        Float.MIN_VALUE, 2f, Float.MAX_VALUE,
0949:                        Float.POSITIVE_INFINITY, Float.NaN };
0950:
0951:                for (int i = 0; i < values.length; i++) {
0952:                    float f1 = values[i];
0953:
0954:                    // Test that each value compares equal to itself; and each object is
0955:                    // equal to another object
0956:                    // like itself
0957:                    assertTrue("Assert 0: compare() should be equal: " + f1,
0958:                            Float.compare(f1, f1) == 0);
0959:                    Float objFloat = new Float(f1);
0960:                    assertTrue("Assert 1: compareTo() should be equal: "
0961:                            + objFloat, objFloat.compareTo(objFloat) == 0);
0962:
0963:                    // Test that the Float-defined order is respected
0964:                    for (int j = i + 1; j < values.length; j++) {
0965:                        float f2 = values[j];
0966:                        assertTrue("Assert 2: compare() " + f1
0967:                                + " should be less " + f2, Float
0968:                                .compare(f1, f2) == -1);
0969:                        assertTrue("Assert 3: compare() " + f2
0970:                                + " should be greater " + f1, Float.compare(f2,
0971:                                f1) == 1);
0972:
0973:                        Float F2 = new Float(f2);
0974:                        assertTrue("Assert 4: compareTo() " + f1
0975:                                + " should be less " + f2, objFloat
0976:                                .compareTo(F2) == -1);
0977:                        assertTrue("Assert 5: compareTo() " + f2
0978:                                + " should be greater " + f1, F2
0979:                                .compareTo(objFloat) == 1);
0980:                    }
0981:                }
0982:            }
0983:
0984:            /**
0985:             * @tests java.lang.Float#equals(java.lang.Object)
0986:             */
0987:            public void test_equalsLjava_lang_Object() {
0988:                Float f1 = new Float(8765.4321f);
0989:                Float f2 = new Float(8765.4321f);
0990:                Float f3 = new Float(-1.0f);
0991:                assertTrue("Assert 0: Equality test failed", f1.equals(f2)
0992:                        && !(f1.equals(f3)));
0993:
0994:                assertTrue("Assert 1: NaN should not be == Nan",
0995:                        Float.NaN != Float.NaN);
0996:                assertTrue("Assert 2: NaN should not be == Nan", new Float(
0997:                        Float.NaN).equals(new Float(Float.NaN)));
0998:                assertTrue("Assert 3: -0f should be == 0f", 0f == -0f);
0999:                assertTrue("Assert 4: -0f should not be equals() 0f",
1000:                        !new Float(0f).equals(new Float(-0f)));
1001:
1002:                f1 = new Float(1098.576f);
1003:                f2 = new Float(1098.576f);
1004:                f3 = new Float(1.0f);
1005:                assertTrue("Equality test failed", f1.equals(f2)
1006:                        && !(f1.equals(f3)));
1007:
1008:                assertTrue("NaN should not be == Nan", Float.NaN != Float.NaN);
1009:                assertTrue("NaN should not be == Nan", new Float(Float.NaN)
1010:                        .equals(new Float(Float.NaN)));
1011:                assertTrue("-0f should be == 0f", 0f == -0f);
1012:                assertTrue("-0f should not be equals() 0f", !new Float(0f)
1013:                        .equals(new Float(-0f)));
1014:            }
1015:
1016:            /**
1017:             * @tests java.lang.Float#toHexString(float)
1018:             */
1019:            public void test_toHexStringF() {
1020:                // the follow values comes from the Float Javadoc/Spec
1021:                assertEquals("0x0.0p0", Float.toHexString(0.0F));
1022:                assertEquals("-0x0.0p0", Float.toHexString(-0.0F));
1023:                assertEquals("0x1.0p0", Float.toHexString(1.0F));
1024:                assertEquals("-0x1.0p0", Float.toHexString(-1.0F));
1025:                assertEquals("0x1.0p1", Float.toHexString(2.0F));
1026:                assertEquals("0x1.8p1", Float.toHexString(3.0F));
1027:                assertEquals("0x1.0p-1", Float.toHexString(0.5F));
1028:                assertEquals("0x1.0p-2", Float.toHexString(0.25F));
1029:                assertEquals("0x1.fffffep127", Float
1030:                        .toHexString(Float.MAX_VALUE));
1031:                assertEquals("0x0.000002p-126", Float
1032:                        .toHexString(Float.MIN_VALUE));
1033:
1034:                // test edge cases
1035:                assertEquals("NaN", Float.toHexString(Float.NaN));
1036:                assertEquals("-Infinity", Float
1037:                        .toHexString(Float.NEGATIVE_INFINITY));
1038:                assertEquals("Infinity", Float
1039:                        .toHexString(Float.POSITIVE_INFINITY));
1040:
1041:                // test various numbers
1042:                assertEquals("-0x1.da8p6", Float.toHexString(-118.625F));
1043:                assertEquals("0x1.295788p23", Float.toHexString(9743299.65F));
1044:                assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
1045:                assertEquals("0x1.295788p23", Float
1046:                        .toHexString(9743299.650001234F));
1047:                assertEquals("0x1.700d1p33", Float
1048:                        .toHexString(12349743299.65000F));
1049:
1050:                // test HARMONY-2132
1051:                assertEquals("0x1.01p10", Float.toHexString(0x1.01p10f));
1052:            }
1053:
1054:            /**
1055:             * @tests java.lang.Float#valueOf(float)
1056:             */
1057:            public void test_valueOfF() {
1058:                assertEquals(new Float(Float.MIN_VALUE), Float
1059:                        .valueOf(Float.MIN_VALUE));
1060:                assertEquals(new Float(Float.MAX_VALUE), Float
1061:                        .valueOf(Float.MAX_VALUE));
1062:                assertEquals(new Float(0), Float.valueOf(0));
1063:
1064:                int s = -128;
1065:                while (s < 128) {
1066:                    assertEquals(new Float(s), Float.valueOf(s));
1067:                    assertEquals(new Float(s + 0.1F), Float.valueOf(s + 0.1F));
1068:                    assertEquals(Float.valueOf(s + 0.1F), Float
1069:                            .valueOf(s + 0.1F));
1070:                    s++;
1071:                }
1072:            }
1073:        }
ww__w___.__j___a_v__a_2___s.c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.