Source Code Cross Referenced for StrictMathTest.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) 


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:        package org.apache.harmony.luni.tests.java.lang;
019:
020:        public class StrictMathTest extends junit.framework.TestCase {
021:
022:            double HYP = StrictMath.sqrt(2.0);
023:
024:            double OPP = 1.0;
025:
026:            double ADJ = 1.0;
027:
028:            /* Required to make previous preprocessor flags work - do not remove */
029:            int unused = 0;
030:
031:            /**
032:             * @tests java.lang.StrictMath#abs(double)
033:             */
034:            public void test_absD() {
035:                // Test for method double java.lang.StrictMath.abs(double)
036:
037:                assertTrue("Incorrect double abs value", (StrictMath
038:                        .abs(-1908.8976) == 1908.8976));
039:                assertTrue("Incorrect double abs value", (StrictMath
040:                        .abs(1908.8976) == 1908.8976));
041:            }
042:
043:            /**
044:             * @tests java.lang.StrictMath#abs(float)
045:             */
046:            public void test_absF() {
047:                // Test for method float java.lang.StrictMath.abs(float)
048:                assertTrue("Incorrect float abs value", (StrictMath
049:                        .abs(-1908.8976f) == 1908.8976f));
050:                assertTrue("Incorrect float abs value", (StrictMath
051:                        .abs(1908.8976f) == 1908.8976f));
052:            }
053:
054:            /**
055:             * @tests java.lang.StrictMath#abs(int)
056:             */
057:            public void test_absI() {
058:                // Test for method int java.lang.StrictMath.abs(int)
059:                assertTrue("Incorrect int abs value",
060:                        (StrictMath.abs(-1908897) == 1908897));
061:                assertTrue("Incorrect int abs value",
062:                        (StrictMath.abs(1908897) == 1908897));
063:            }
064:
065:            /**
066:             * @tests java.lang.StrictMath#abs(long)
067:             */
068:            public void test_absJ() {
069:                // Test for method long java.lang.StrictMath.abs(long)
070:                assertTrue("Incorrect long abs value", (StrictMath
071:                        .abs(-19088976000089L) == 19088976000089L));
072:                assertTrue("Incorrect long abs value", (StrictMath
073:                        .abs(19088976000089L) == 19088976000089L));
074:            }
075:
076:            /**
077:             * @tests java.lang.StrictMath#acos(double)
078:             */
079:            public void test_acosD() {
080:                // Test for method double java.lang.StrictMath.acos(double)
081:                assertTrue("Returned incorrect arc cosine", StrictMath
082:                        .cos(StrictMath.acos(ADJ / HYP)) == ADJ / HYP);
083:            }
084:
085:            /**
086:             * @tests java.lang.StrictMath#asin(double)
087:             */
088:            public void test_asinD() {
089:                // Test for method double java.lang.StrictMath.asin(double)
090:                assertTrue("Returned incorrect arc sine", StrictMath
091:                        .sin(StrictMath.asin(OPP / HYP)) == OPP / HYP);
092:            }
093:
094:            /**
095:             * @tests java.lang.StrictMath#atan(double)
096:             */
097:            public void test_atanD() {
098:                // Test for method double java.lang.StrictMath.atan(double)
099:                double answer = StrictMath.tan(StrictMath.atan(1.0));
100:                assertTrue("Returned incorrect arc tangent: " + answer,
101:                        answer <= 1.0 && answer >= 9.9999999999999983E-1);
102:            }
103:
104:            /**
105:             * @tests java.lang.StrictMath#atan2(double, double)
106:             */
107:            public void test_atan2DD() {
108:                // Test for method double java.lang.StrictMath.atan2(double, double)
109:                double answer = StrictMath.atan(StrictMath.tan(1.0));
110:                assertTrue("Returned incorrect arc tangent: " + answer,
111:                        answer <= 1.0 && answer >= 9.9999999999999983E-1);
112:            }
113:
114:            /**
115:             * @tests java.lang.StrictMath#cbrt(double)
116:             */
117:            @SuppressWarnings("boxing")
118:            public void test_cbrt_D() {
119:                // Test for special situations
120:                assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
121:                        .cbrt(Double.NaN)));
122:                assertEquals("Should return Double.POSITIVE_INFINITY",
123:                        Double.POSITIVE_INFINITY, StrictMath
124:                                .cbrt(Double.POSITIVE_INFINITY));
125:                assertEquals("Should return Double.NEGATIVE_INFINITY",
126:                        Double.NEGATIVE_INFINITY, StrictMath
127:                                .cbrt(Double.NEGATIVE_INFINITY));
128:                assertEquals(Double.doubleToLongBits(0.0), Double
129:                        .doubleToLongBits(StrictMath.cbrt(0.0)));
130:                assertEquals(Double.doubleToLongBits(+0.0), Double
131:                        .doubleToLongBits(StrictMath.cbrt(+0.0)));
132:                assertEquals(Double.doubleToLongBits(-0.0), Double
133:                        .doubleToLongBits(StrictMath.cbrt(-0.0)));
134:
135:                assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0));
136:                assertEquals("Should return 23.111993172558684",
137:                        23.111993172558684, StrictMath.cbrt(12345.6));
138:                assertEquals("Should return 5.643803094122362E102",
139:                        5.643803094122362E102, StrictMath
140:                                .cbrt(Double.MAX_VALUE));
141:                assertEquals("Should return 0.01", 0.01, StrictMath
142:                        .cbrt(0.000001));
143:
144:                assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0));
145:                assertEquals("Should return -23.111993172558684",
146:                        -23.111993172558684, StrictMath.cbrt(-12345.6));
147:                assertEquals("Should return 1.7031839360032603E-108",
148:                        1.7031839360032603E-108, StrictMath
149:                                .cbrt(Double.MIN_VALUE));
150:                assertEquals("Should return -0.01", -0.01, StrictMath
151:                        .cbrt(-0.000001));
152:
153:                try {
154:                    StrictMath.cbrt((Double) null);
155:                    fail("Should throw NullPointerException");
156:                } catch (NullPointerException e) {
157:                    //expected
158:                }
159:            }
160:
161:            /**
162:             * @tests java.lang.StrictMath#ceil(double)
163:             */
164:            public void test_ceilD() {
165:                // Test for method double java.lang.StrictMath.ceil(double)
166:                assertEquals("Incorrect ceiling for double", 79, StrictMath
167:                        .ceil(78.89), 0.0);
168:                assertEquals("Incorrect ceiling for double", -78, StrictMath
169:                        .ceil(-78.89), 0.0);
170:            }
171:
172:            /**
173:             * @tests java.lang.StrictMath#cos(double)
174:             */
175:            public void test_cosD() {
176:                // Test for method double java.lang.StrictMath.cos(double)
177:
178:                assertTrue("Returned incorrect cosine", StrictMath
179:                        .cos(StrictMath.acos(ADJ / HYP)) == ADJ / HYP);
180:            }
181:
182:            /**
183:             * @tests java.lang.StrictMath#cosh(double)
184:             */
185:            @SuppressWarnings("boxing")
186:            public void test_cosh_D() {
187:                // Test for special situations        
188:                assertTrue("Should return NaN", Double.isNaN(StrictMath
189:                        .cosh(Double.NaN)));
190:                assertEquals("Should return POSITIVE_INFINITY",
191:                        Double.POSITIVE_INFINITY, StrictMath
192:                                .cosh(Double.POSITIVE_INFINITY));
193:                assertEquals("Should return POSITIVE_INFINITY",
194:                        Double.POSITIVE_INFINITY, StrictMath
195:                                .cosh(Double.NEGATIVE_INFINITY));
196:                assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0));
197:                assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0));
198:
199:                assertEquals("Should return POSITIVE_INFINITY",
200:                        Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56));
201:                assertEquals("Should return POSITIVE_INFINITY",
202:                        Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56));
203:                assertEquals("Should return 1.0000000000005", 1.0000000000005,
204:                        StrictMath.cosh(0.000001));
205:                assertEquals("Should return 1.0000000000005", 1.0000000000005,
206:                        StrictMath.cosh(-0.000001));
207:                assertEquals("Should return 5.212214351945598",
208:                        5.212214351945598, StrictMath.cosh(2.33482));
209:
210:                assertEquals("Should return POSITIVE_INFINITY",
211:                        Double.POSITIVE_INFINITY, StrictMath
212:                                .cosh(Double.MAX_VALUE));
213:                assertEquals("Should return 1.0", 1.0, StrictMath
214:                        .cosh(Double.MIN_VALUE));
215:            }
216:
217:            /**
218:             * @tests java.lang.StrictMath#exp(double)
219:             */
220:            public void test_expD() {
221:                // Test for method double java.lang.StrictMath.exp(double)
222:                assertTrue(
223:                        "Incorrect answer returned for simple power",
224:                        StrictMath.abs(StrictMath.exp(4D) - StrictMath.E
225:                                * StrictMath.E * StrictMath.E * StrictMath.E) < 0.1D);
226:                assertTrue(
227:                        "Incorrect answer returned for larger power",
228:                        StrictMath
229:                                .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
230:            }
231:
232:            /**
233:             * @tests java.lang.StrictMath#expm1(double)
234:             */
235:            @SuppressWarnings("boxing")
236:            public void test_expm1_D() {
237:                //Test for special cases        
238:                assertTrue("Should return NaN", Double.isNaN(StrictMath
239:                        .expm1(Double.NaN)));
240:                assertEquals("Should return POSITIVE_INFINITY",
241:                        Double.POSITIVE_INFINITY, StrictMath
242:                                .expm1(Double.POSITIVE_INFINITY));
243:                assertEquals("Should return -1.0", -1.0, StrictMath
244:                        .expm1(Double.NEGATIVE_INFINITY));
245:                assertEquals(Double.doubleToLongBits(0.0), Double
246:                        .doubleToLongBits(StrictMath.expm1(0.0)));
247:                assertEquals(Double.doubleToLongBits(+0.0), Double
248:                        .doubleToLongBits(StrictMath.expm1(+0.0)));
249:                assertEquals(Double.doubleToLongBits(-0.0), Double
250:                        .doubleToLongBits(StrictMath.expm1(-0.0)));
251:
252:                assertEquals("Should return -9.999950000166666E-6",
253:                        -9.999950000166666E-6, StrictMath.expm1(-0.00001));
254:                assertEquals("Should return 1.0145103074469635E60",
255:                        1.0145103074469635E60, StrictMath.expm1(138.16951162));
256:                assertEquals("Should return POSITIVE_INFINITY",
257:                        Double.POSITIVE_INFINITY, StrictMath
258:                                .expm1(123456789123456789123456789.4521584223));
259:                assertEquals("Should return POSITIVE_INFINITY",
260:                        Double.POSITIVE_INFINITY, StrictMath
261:                                .expm1(Double.MAX_VALUE));
262:                assertEquals("Should return MIN_VALUE", Double.MIN_VALUE,
263:                        StrictMath.expm1(Double.MIN_VALUE));
264:
265:            }
266:
267:            /**
268:             * @tests java.lang.StrictMath#floor(double)
269:             */
270:            public void test_floorD() {
271:                // Test for method double java.lang.StrictMath.floor(double)
272:                assertEquals("Incorrect floor for double", 78, StrictMath
273:                        .floor(78.89), 0.0);
274:                assertEquals("Incorrect floor for double", -79, StrictMath
275:                        .floor(-78.89), 0.0);
276:            }
277:
278:            /**
279:             * @tests java.lang.StrictMath#hypot(double, double)
280:             */
281:            @SuppressWarnings("boxing")
282:            public void test_hypot_DD() {
283:                // Test for special cases
284:                assertEquals("Should return POSITIVE_INFINITY",
285:                        Double.POSITIVE_INFINITY, StrictMath.hypot(
286:                                Double.POSITIVE_INFINITY, 1.0));
287:                assertEquals("Should return POSITIVE_INFINITY",
288:                        Double.POSITIVE_INFINITY, StrictMath.hypot(
289:                                Double.NEGATIVE_INFINITY, 123.324));
290:                assertEquals("Should return POSITIVE_INFINITY",
291:                        Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587,
292:                                Double.POSITIVE_INFINITY));
293:                assertEquals("Should return POSITIVE_INFINITY",
294:                        Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21,
295:                                Double.NEGATIVE_INFINITY));
296:                assertEquals("Should return POSITIVE_INFINITY",
297:                        Double.POSITIVE_INFINITY, StrictMath.hypot(
298:                                Double.POSITIVE_INFINITY,
299:                                Double.NEGATIVE_INFINITY));
300:                assertEquals("Should return POSITIVE_INFINITY",
301:                        Double.POSITIVE_INFINITY, StrictMath.hypot(
302:                                Double.NEGATIVE_INFINITY,
303:                                Double.POSITIVE_INFINITY));
304:                assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(
305:                        Double.NaN, 2342301.89843)));
306:                assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(
307:                        -345.2680, Double.NaN)));
308:
309:                assertEquals("Should return 2396424.905416697",
310:                        2396424.905416697, StrictMath.hypot(12322.12,
311:                                -2396393.2258));
312:                assertEquals("Should return 138.16958070558556",
313:                        138.16958070558556, StrictMath.hypot(-138.16951162,
314:                                0.13817035864));
315:                assertEquals("Should return 1.7976931348623157E308",
316:                        1.7976931348623157E308, StrictMath.hypot(
317:                                Double.MAX_VALUE, 211370.35));
318:                assertEquals("Should return 5413.7185", 5413.7185, StrictMath
319:                        .hypot(-5413.7185, Double.MIN_VALUE));
320:
321:            }
322:
323:            /**
324:             * @tests java.lang.StrictMath#IEEEremainder(double, double)
325:             */
326:            public void test_IEEEremainderDD() {
327:                // Test for method double java.lang.StrictMath.IEEEremainder(double,
328:                // double)
329:                assertEquals("Incorrect remainder returned", 0.0, StrictMath
330:                        .IEEEremainder(1.0, 1.0), 0.0);
331:                assertTrue(
332:                        "Incorrect remainder returned",
333:                        StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
334:                                || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
335:            }
336:
337:            /**
338:             * @tests java.lang.StrictMath#log(double)
339:             */
340:            public void test_logD() {
341:                // Test for method double java.lang.StrictMath.log(double)
342:                for (double d = 10; d >= -10; d -= 0.5) {
343:                    double answer = StrictMath.log(StrictMath.exp(d));
344:                    assertTrue("Answer does not equal expected answer for d = "
345:                            + d + " answer = " + answer, StrictMath.abs(answer
346:                            - d) <= StrictMath.abs(d * 0.00000001));
347:                }
348:            }
349:
350:            /**
351:             * @tests java.lang.StrictMath#log10(double)
352:             */
353:            @SuppressWarnings("boxing")
354:            public void test_log10_D() {
355:                // Test for special cases        
356:                assertTrue("Should return NaN", Double.isNaN(StrictMath
357:                        .log10(Double.NaN)));
358:                assertTrue("Should return NaN", Double.isNaN(StrictMath
359:                        .log10(-2541.05745687234187532)));
360:                assertEquals("Should return POSITIVE_INFINITY",
361:                        Double.POSITIVE_INFINITY, StrictMath
362:                                .log10(Double.POSITIVE_INFINITY));
363:                assertEquals("Should return NEGATIVE_INFINITY",
364:                        Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
365:                assertEquals("Should return NEGATIVE_INFINITY",
366:                        Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0));
367:                assertEquals("Should return NEGATIVE_INFINITY",
368:                        Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0));
369:                assertEquals("Should return 14.0", 14.0, StrictMath
370:                        .log10(StrictMath.pow(10, 14)));
371:
372:                assertEquals("Should return 3.7389561269540406",
373:                        3.7389561269540406, StrictMath.log10(5482.2158));
374:                assertEquals("Should return 14.661551142893833",
375:                        14.661551142893833, StrictMath
376:                                .log10(458723662312872.125782332587));
377:                assertEquals("Should return -0.9083828622192334",
378:                        -0.9083828622192334, StrictMath.log10(0.12348583358871));
379:                assertEquals("Should return 308.25471555991675",
380:                        308.25471555991675, StrictMath.log10(Double.MAX_VALUE));
381:                assertEquals("Should return -323.3062153431158",
382:                        -323.3062153431158, StrictMath.log10(Double.MIN_VALUE));
383:            }
384:
385:            /**
386:             * @tests java.lang.StrictMath#log1p(double)
387:             */
388:            @SuppressWarnings("boxing")
389:            public void test_log1p_D() {
390:                // Test for special cases
391:                assertTrue("Should return NaN", Double.isNaN(StrictMath
392:                        .log1p(Double.NaN)));
393:                assertTrue("Should return NaN", Double.isNaN(StrictMath
394:                        .log1p(-32.0482175)));
395:                assertEquals("Should return POSITIVE_INFINITY",
396:                        Double.POSITIVE_INFINITY, StrictMath
397:                                .log1p(Double.POSITIVE_INFINITY));
398:                assertEquals(Double.doubleToLongBits(0.0), Double
399:                        .doubleToLongBits(StrictMath.log1p(0.0)));
400:                assertEquals(Double.doubleToLongBits(+0.0), Double
401:                        .doubleToLongBits(StrictMath.log1p(+0.0)));
402:                assertEquals(Double.doubleToLongBits(-0.0), Double
403:                        .doubleToLongBits(StrictMath.log1p(-0.0)));
404:
405:                assertEquals("Should return -0.2941782295312541",
406:                        -0.2941782295312541, StrictMath.log1p(-0.254856327));
407:                assertEquals("Should return 7.368050685564151",
408:                        7.368050685564151, StrictMath.log1p(1583.542));
409:                assertEquals("Should return 0.4633708685409921",
410:                        0.4633708685409921, StrictMath.log1p(0.5894227));
411:                assertEquals("Should return 709.782712893384",
412:                        709.782712893384, StrictMath.log1p(Double.MAX_VALUE));
413:                assertEquals("Should return Double.MIN_VALUE",
414:                        Double.MIN_VALUE, StrictMath.log1p(Double.MIN_VALUE));
415:            }
416:
417:            /**
418:             * @tests java.lang.StrictMath#max(double, double)
419:             */
420:            public void test_maxDD() {
421:                // Test for method double java.lang.StrictMath.max(double, double)
422:                assertEquals("Incorrect double max value", 1908897.6000089,
423:                        StrictMath.max(-1908897.6000089, 1908897.6000089), 0D);
424:                assertEquals("Incorrect double max value", 1908897.6000089,
425:                        StrictMath.max(2.0, 1908897.6000089), 0D);
426:                assertEquals("Incorrect double max value", -2.0, StrictMath
427:                        .max(-2.0, -1908897.6000089), 0D);
428:
429:            }
430:
431:            /**
432:             * @tests java.lang.StrictMath#max(float, float)
433:             */
434:            public void test_maxFF() {
435:                // Test for method float java.lang.StrictMath.max(float, float)
436:                assertTrue("Incorrect float max value", StrictMath.max(
437:                        -1908897.600f, 1908897.600f) == 1908897.600f);
438:                assertTrue("Incorrect float max value", StrictMath.max(2.0f,
439:                        1908897.600f) == 1908897.600f);
440:                assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
441:                        -1908897.600f) == -2.0f);
442:            }
443:
444:            /**
445:             * @tests java.lang.StrictMath#max(int, int)
446:             */
447:            public void test_maxII() {
448:                // Test for method int java.lang.StrictMath.max(int, int)
449:                assertEquals("Incorrect int max value", 19088976, StrictMath
450:                        .max(-19088976, 19088976));
451:                assertEquals("Incorrect int max value", 19088976, StrictMath
452:                        .max(20, 19088976));
453:                assertEquals("Incorrect int max value", -20, StrictMath.max(
454:                        -20, -19088976));
455:            }
456:
457:            /**
458:             * @tests java.lang.StrictMath#max(long, long)
459:             */
460:            public void test_maxJJ() {
461:                // Test for method long java.lang.StrictMath.max(long, long)
462:                assertEquals("Incorrect long max value", 19088976000089L,
463:                        StrictMath.max(-19088976000089L, 19088976000089L));
464:                assertEquals("Incorrect long max value", 19088976000089L,
465:                        StrictMath.max(20, 19088976000089L));
466:                assertEquals("Incorrect long max value", -20, StrictMath.max(
467:                        -20, -19088976000089L));
468:            }
469:
470:            /**
471:             * @tests java.lang.StrictMath#min(double, double)
472:             */
473:            public void test_minDD() {
474:                // Test for method double java.lang.StrictMath.min(double, double)
475:                assertEquals("Incorrect double min value", -1908897.6000089,
476:                        StrictMath.min(-1908897.6000089, 1908897.6000089), 0D);
477:                assertEquals("Incorrect double min value", 2.0, StrictMath.min(
478:                        2.0, 1908897.6000089), 0D);
479:                assertEquals("Incorrect double min value", -1908897.6000089,
480:                        StrictMath.min(-2.0, -1908897.6000089), 0D);
481:            }
482:
483:            /**
484:             * @tests java.lang.StrictMath#min(float, float)
485:             */
486:            public void test_minFF() {
487:                // Test for method float java.lang.StrictMath.min(float, float)
488:                assertTrue("Incorrect float min value", StrictMath.min(
489:                        -1908897.600f, 1908897.600f) == -1908897.600f);
490:                assertTrue("Incorrect float min value", StrictMath.min(2.0f,
491:                        1908897.600f) == 2.0f);
492:                assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
493:                        -1908897.600f) == -1908897.600f);
494:            }
495:
496:            /**
497:             * @tests java.lang.StrictMath#min(int, int)
498:             */
499:            public void test_minII() {
500:                // Test for method int java.lang.StrictMath.min(int, int)
501:                assertEquals("Incorrect int min value", -19088976, StrictMath
502:                        .min(-19088976, 19088976));
503:                assertEquals("Incorrect int min value", 20, StrictMath.min(20,
504:                        19088976));
505:                assertEquals("Incorrect int min value", -19088976, StrictMath
506:                        .min(-20, -19088976));
507:
508:            }
509:
510:            /**
511:             * @tests java.lang.StrictMath#min(long, long)
512:             */
513:            public void test_minJJ() {
514:                // Test for method long java.lang.StrictMath.min(long, long)
515:                assertEquals("Incorrect long min value", -19088976000089L,
516:                        StrictMath.min(-19088976000089L, 19088976000089L));
517:                assertEquals("Incorrect long min value", 20, StrictMath.min(20,
518:                        19088976000089L));
519:                assertEquals("Incorrect long min value", -19088976000089L,
520:                        StrictMath.min(-20, -19088976000089L));
521:            }
522:
523:            /**
524:             * @tests java.lang.StrictMath#pow(double, double)
525:             */
526:            public void test_powDD() {
527:                // Test for method double java.lang.StrictMath.pow(double, double)
528:                assertTrue("pow returned incorrect value", (long) StrictMath
529:                        .pow(2, 8) == 256l);
530:                assertTrue("pow returned incorrect value", StrictMath
531:                        .pow(2, -8) == 0.00390625d);
532:            }
533:
534:            /**
535:             * @tests java.lang.StrictMath#rint(double)
536:             */
537:            public void test_rintD() {
538:                // Test for method double java.lang.StrictMath.rint(double)
539:                assertEquals("Failed to round properly - up to odd", 3.0,
540:                        StrictMath.rint(2.9), 0D);
541:                assertTrue("Failed to round properly - NaN", Double
542:                        .isNaN(StrictMath.rint(Double.NaN)));
543:                assertEquals("Failed to round properly down  to even", 2.0,
544:                        StrictMath.rint(2.1), 0D);
545:                assertTrue("Failed to round properly " + 2.5 + " to even",
546:                        StrictMath.rint(2.5) == 2.0);
547:            }
548:
549:            /**
550:             * @tests java.lang.StrictMath#round(double)
551:             */
552:            public void test_roundD() {
553:                // Test for method long java.lang.StrictMath.round(double)
554:                assertEquals("Incorrect rounding of a float", -91, StrictMath
555:                        .round(-90.89d));
556:            }
557:
558:            /**
559:             * @tests java.lang.StrictMath#round(float)
560:             */
561:            public void test_roundF() {
562:                // Test for method int java.lang.StrictMath.round(float)
563:                assertEquals("Incorrect rounding of a float", -91, StrictMath
564:                        .round(-90.89f));
565:            }
566:
567:            /**
568:             * @tests java.lang.StrictMath#signum(double)
569:             */
570:            public void test_signum_D() {
571:                assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
572:                assertEquals(Double.doubleToLongBits(0.0), Double
573:                        .doubleToLongBits(StrictMath.signum(0.0)));
574:                assertEquals(Double.doubleToLongBits(+0.0), Double
575:                        .doubleToLongBits(StrictMath.signum(+0.0)));
576:                assertEquals(Double.doubleToLongBits(-0.0), Double
577:                        .doubleToLongBits(StrictMath.signum(-0.0)));
578:
579:                assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
580:                assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
581:                assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
582:                assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
583:
584:                assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
585:                assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
586:                assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
587:                assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
588:                assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY),
589:                        0D);
590:                assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY),
591:                        0D);
592:
593:            }
594:
595:            /**
596:             * @tests java.lang.StrictMath#signum(float)
597:             */
598:            public void test_signum_F() {
599:                assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
600:                assertEquals(Float.floatToIntBits(0.0f), Float
601:                        .floatToIntBits(StrictMath.signum(0.0f)));
602:                assertEquals(Float.floatToIntBits(+0.0f), Float
603:                        .floatToIntBits(StrictMath.signum(+0.0f)));
604:                assertEquals(Float.floatToIntBits(-0.0f), Float
605:                        .floatToIntBits(StrictMath.signum(-0.0f)));
606:
607:                assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
608:                assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
609:                assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
610:                assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
611:
612:                assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
613:                assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
614:                assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
615:                assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
616:                assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY),
617:                        0f);
618:                assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY),
619:                        0f);
620:            }
621:
622:            /**
623:             * @tests java.lang.StrictMath#sin(double)
624:             */
625:            public void test_sinD() {
626:                // Test for method double java.lang.StrictMath.sin(double)
627:                assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
628:                        .asin(OPP / HYP)) == OPP / HYP);
629:            }
630:
631:            /**
632:             * @tests java.lang.StrictMath#sinh(double)
633:             */
634:            public void test_sinh_D() {
635:                // Test for special situations
636:                assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN)));
637:                assertEquals("Should return POSITIVE_INFINITY",
638:                        Double.POSITIVE_INFINITY, StrictMath
639:                                .sinh(Double.POSITIVE_INFINITY), 0D);
640:                assertEquals("Should return NEGATIVE_INFINITY",
641:                        Double.NEGATIVE_INFINITY, StrictMath
642:                                .sinh(Double.NEGATIVE_INFINITY), 0D);
643:                assertEquals(Double.doubleToLongBits(0.0), Double
644:                        .doubleToLongBits(StrictMath.sinh(0.0)));
645:                assertEquals(Double.doubleToLongBits(+0.0), Double
646:                        .doubleToLongBits(StrictMath.sinh(+0.0)));
647:                assertEquals(Double.doubleToLongBits(-0.0), Double
648:                        .doubleToLongBits(StrictMath.sinh(-0.0)));
649:
650:                assertEquals("Should return POSITIVE_INFINITY",
651:                        Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D);
652:                assertEquals("Should return NEGATIVE_INFINITY",
653:                        Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D);
654:                assertEquals("Should return 1.0000000000001666E-6",
655:                        1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D);
656:                assertEquals("Should return -1.0000000000001666E-6",
657:                        -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D);
658:                assertEquals("Should return 5.115386441963859",
659:                        5.115386441963859, StrictMath.sinh(2.33482), 0D);
660:                assertEquals("Should return POSITIVE_INFINITY",
661:                        Double.POSITIVE_INFINITY, StrictMath
662:                                .sinh(Double.MAX_VALUE), 0D);
663:                assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
664:                        .sinh(Double.MIN_VALUE), 0D);
665:            }
666:
667:            /**
668:             * @tests java.lang.StrictMath#sqrt(double)
669:             */
670:            public void test_sqrtD() {
671:                // Test for method double java.lang.StrictMath.sqrt(double)
672:                assertEquals("Incorrect root returned1", 2, StrictMath
673:                        .sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
674:                assertEquals("Incorrect root returned2", 7,
675:                        StrictMath.sqrt(49), 0.0);
676:            }
677:
678:            /**
679:             * @tests java.lang.StrictMath#tan(double)
680:             */
681:            public void test_tanD() {
682:                // Test for method double java.lang.StrictMath.tan(double)
683:                assertTrue(
684:                        "Returned incorrect tangent: ",
685:                        StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
686:                                || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
687:            }
688:
689:            /**
690:             * @tests java.lang.StrictMath#tanh(double)
691:             */
692:            public void test_tanh_D() {
693:                // Test for special situations
694:                assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN)));
695:                assertEquals("Should return +1.0", +1.0, StrictMath
696:                        .tanh(Double.POSITIVE_INFINITY), 0D);
697:                assertEquals("Should return -1.0", -1.0, StrictMath
698:                        .tanh(Double.NEGATIVE_INFINITY), 0D);
699:                assertEquals(Double.doubleToLongBits(0.0), Double
700:                        .doubleToLongBits(StrictMath.tanh(0.0)));
701:                assertEquals(Double.doubleToLongBits(+0.0), Double
702:                        .doubleToLongBits(StrictMath.tanh(+0.0)));
703:                assertEquals(Double.doubleToLongBits(-0.0), Double
704:                        .doubleToLongBits(StrictMath.tanh(-0.0)));
705:
706:                assertEquals("Should return 1.0", 1.0,
707:                        StrictMath.tanh(1234.56), 0D);
708:                assertEquals("Should return -1.0", -1.0, StrictMath
709:                        .tanh(-1234.56), 0D);
710:                assertEquals("Should return 9.999999999996666E-7",
711:                        9.999999999996666E-7, StrictMath.tanh(0.000001), 0D);
712:                assertEquals("Should return 0.981422884124941",
713:                        0.981422884124941, StrictMath.tanh(2.33482), 0D);
714:                assertEquals("Should return 1.0", 1.0, StrictMath
715:                        .tanh(Double.MAX_VALUE), 0D);
716:                assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
717:                        .tanh(Double.MIN_VALUE), 0D);
718:            }
719:
720:            /**
721:             * @tests java.lang.StrictMath#random()
722:             */
723:            public void test_random() {
724:                // There isn't a place for these tests so just stick them here
725:                assertEquals("Wrong value E", 4613303445314885481L, Double
726:                        .doubleToLongBits(StrictMath.E));
727:                assertEquals("Wrong value PI", 4614256656552045848L, Double
728:                        .doubleToLongBits(StrictMath.PI));
729:
730:                for (int i = 500; i >= 0; i--) {
731:                    double d = StrictMath.random();
732:                    assertTrue("Generated number is out of range: " + d,
733:                            d >= 0.0 && d < 1.0);
734:                }
735:            }
736:
737:            /**
738:             * @tests java.lang.StrictMath#toRadians(double)
739:             */
740:            public void test_toRadiansD() {
741:                for (double d = 500; d >= 0; d -= 1.0) {
742:                    double converted = StrictMath.toDegrees(StrictMath
743:                            .toRadians(d));
744:                    assertTrue("Converted number not equal to original. d = "
745:                            + d, converted >= d * 0.99999999
746:                            && converted <= d * 1.00000001);
747:                }
748:            }
749:
750:            /**
751:             * @tests java.lang.StrictMath#toDegrees(double)
752:             */
753:            public void test_toDegreesD() {
754:                for (double d = 500; d >= 0; d -= 1.0) {
755:                    double converted = StrictMath.toRadians(StrictMath
756:                            .toDegrees(d));
757:                    assertTrue("Converted number not equal to original. d = "
758:                            + d, converted >= d * 0.99999999
759:                            && converted <= d * 1.00000001);
760:                }
761:            }
762:
763:            /**
764:             * @tests java.lang.StrictMath#ulp(double)
765:             */
766:            @SuppressWarnings("boxing")
767:            public void test_ulp_D() {
768:                // Test for special cases
769:                assertTrue("Should return NaN", Double.isNaN(StrictMath
770:                        .ulp(Double.NaN)));
771:                assertEquals("Returned incorrect value",
772:                        Double.POSITIVE_INFINITY, StrictMath
773:                                .ulp(Double.POSITIVE_INFINITY), 0D);
774:                assertEquals("Returned incorrect value",
775:                        Double.POSITIVE_INFINITY, StrictMath
776:                                .ulp(Double.NEGATIVE_INFINITY), 0D);
777:                assertEquals("Returned incorrect value", Double.MIN_VALUE,
778:                        StrictMath.ulp(0.0), 0D);
779:                assertEquals("Returned incorrect value", Double.MIN_VALUE,
780:                        StrictMath.ulp(+0.0), 0D);
781:                assertEquals("Returned incorrect value", Double.MIN_VALUE,
782:                        StrictMath.ulp(-0.0), 0D);
783:                assertEquals("Returned incorrect value",
784:                        StrictMath.pow(2, 971), StrictMath
785:                                .ulp(Double.MAX_VALUE), 0D);
786:                assertEquals("Returned incorrect value",
787:                        StrictMath.pow(2, 971), StrictMath
788:                                .ulp(-Double.MAX_VALUE), 0D);
789:
790:                assertEquals("Returned incorrect value", Double.MIN_VALUE,
791:                        StrictMath.ulp(Double.MIN_VALUE), 0D);
792:                assertEquals("Returned incorrect value", Double.MIN_VALUE,
793:                        StrictMath.ulp(-Double.MIN_VALUE), 0D);
794:
795:                assertEquals("Returned incorrect value", 2.220446049250313E-16,
796:                        StrictMath.ulp(1.0), 0D);
797:                assertEquals("Returned incorrect value", 2.220446049250313E-16,
798:                        StrictMath.ulp(-1.0), 0D);
799:                assertEquals("Returned incorrect value",
800:                        2.2737367544323206E-13, StrictMath.ulp(1153.0), 0D);
801:            }
802:
803:            /**
804:             * @tests java.lang.StrictMath#ulp(float)
805:             */
806:            @SuppressWarnings("boxing")
807:            public void test_ulp_f() {
808:                // Test for special cases
809:                assertTrue("Should return NaN", Float.isNaN(StrictMath
810:                        .ulp(Float.NaN)));
811:                assertEquals("Returned incorrect value",
812:                        Float.POSITIVE_INFINITY, StrictMath
813:                                .ulp(Float.POSITIVE_INFINITY), 0f);
814:                assertEquals("Returned incorrect value",
815:                        Float.POSITIVE_INFINITY, StrictMath
816:                                .ulp(Float.NEGATIVE_INFINITY), 0f);
817:                assertEquals("Returned incorrect value", Float.MIN_VALUE,
818:                        StrictMath.ulp(0.0f), 0f);
819:                assertEquals("Returned incorrect value", Float.MIN_VALUE,
820:                        StrictMath.ulp(+0.0f), 0f);
821:                assertEquals("Returned incorrect value", Float.MIN_VALUE,
822:                        StrictMath.ulp(-0.0f), 0f);
823:                assertEquals("Returned incorrect value", 2.028241E31f,
824:                        StrictMath.ulp(Float.MAX_VALUE), 0f);
825:                assertEquals("Returned incorrect value", 2.028241E31f,
826:                        StrictMath.ulp(-Float.MAX_VALUE), 0f);
827:
828:                assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
829:                        .ulp(Float.MIN_VALUE), 0f);
830:                assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
831:                        .ulp(-Float.MIN_VALUE), 0f);
832:
833:                assertEquals("Returned incorrect value", 1.1920929E-7f,
834:                        StrictMath.ulp(1.0f), 0f);
835:                assertEquals("Returned incorrect value", 1.1920929E-7f,
836:                        StrictMath.ulp(-1.0f), 0f);
837:                assertEquals("Returned incorrect value", 1.2207031E-4f,
838:                        StrictMath.ulp(1153.0f), 0f);
839:                assertEquals("Returned incorrect value", 5.6E-45f, Math
840:                        .ulp(9.403954E-38f), 0f);
841:            }
842:        }
w___w_w_.__ja_v___a___2___s__._co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.