1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package android.core;
19
20import junit.framework.TestCase;
21import android.test.suitebuilder.annotation.SmallTest;
22import android.test.suitebuilder.annotation.MediumTest;
23
24public class StrictMathTest extends TestCase {
25
26    private final double HYP = StrictMath.sqrt(2.0);
27
28    private final double OPP = 1.0;
29
30    private final double ADJ = 1.0;
31
32    /* Required to make previous preprocessor flags work - do not remove */
33    int unused = 0;
34
35    /**
36     * @tests java.lang.StrictMath#abs(double)
37     */
38    @SmallTest
39    public void testAbsD() {
40        // Test for method double java.lang.StrictMath.abs(double)
41
42        assertTrue("Incorrect double abs value",
43                (StrictMath.abs(-1908.8976) == 1908.8976));
44        assertTrue("Incorrect double abs value",
45                (StrictMath.abs(1908.8976) == 1908.8976));
46    }
47
48    /**
49     * @tests java.lang.StrictMath#abs(float)
50     */
51    @SmallTest
52    public void testAbsF() {
53        // Test for method float java.lang.StrictMath.abs(float)
54        assertTrue("Incorrect float abs value",
55                (StrictMath.abs(-1908.8976f) == 1908.8976f));
56        assertTrue("Incorrect float abs value",
57                (StrictMath.abs(1908.8976f) == 1908.8976f));
58    }
59
60    /**
61     * @tests java.lang.StrictMath#abs(int)
62     */
63    @SmallTest
64    public void testAbsI() {
65        // Test for method int java.lang.StrictMath.abs(int)
66        assertTrue("Incorrect int abs value",
67                (StrictMath.abs(-1908897) == 1908897));
68        assertTrue("Incorrect int abs value",
69                (StrictMath.abs(1908897) == 1908897));
70    }
71
72    /**
73     * @tests java.lang.StrictMath#abs(long)
74     */
75    @SmallTest
76    public void testAbsJ() {
77        // Test for method long java.lang.StrictMath.abs(long)
78        assertTrue("Incorrect long abs value", (StrictMath
79                .abs(-19088976000089L) == 19088976000089L));
80        assertTrue("Incorrect long abs value",
81                (StrictMath.abs(19088976000089L) == 19088976000089L));
82    }
83
84    /**
85     * @tests java.lang.StrictMath#acos(double)
86     */
87    @SmallTest
88    public void testAcosD() {
89        // Test for method double java.lang.StrictMath.acos(double)
90        assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
91                .acos(ADJ / HYP)) == ADJ / HYP);
92    }
93
94    /**
95     * @tests java.lang.StrictMath#asin(double)
96     */
97    @SmallTest
98    public void testAsinD() {
99        // Test for method double java.lang.StrictMath.asin(double)
100        assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
101                .asin(OPP / HYP)) == OPP / HYP);
102    }
103
104    /**
105     * @tests java.lang.StrictMath#atan(double)
106     */
107    @SmallTest
108    public void testAtanD() {
109        // Test for method double java.lang.StrictMath.atan(double)
110        double answer = StrictMath.tan(StrictMath.atan(1.0));
111        assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
112                && answer >= 9.9999999999999983E-1);
113    }
114
115    /**
116     * @tests java.lang.StrictMath#atan2(double,double)
117     */
118    @SmallTest
119    public void testAtan2DD() {
120        // Test for method double java.lang.StrictMath.atan2(double, double)
121        double answer = StrictMath.atan(StrictMath.tan(1.0));
122        assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
123                && answer >= 9.9999999999999983E-1);
124    }
125
126    /**
127     * @tests java.lang.StrictMath#cbrt(double)
128     */
129    @SuppressWarnings("boxing")
130    @SmallTest
131    public void testCbrtD() {
132        // Test for special situations
133        assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
134                .cbrt(Double.NaN)));
135        assertEquals("Should return Double.POSITIVE_INFINITY",
136                Double.POSITIVE_INFINITY, StrictMath
137                .cbrt(Double.POSITIVE_INFINITY));
138        assertEquals("Should return Double.NEGATIVE_INFINITY",
139                Double.NEGATIVE_INFINITY, StrictMath
140                .cbrt(Double.NEGATIVE_INFINITY));
141        assertEquals(Double.doubleToLongBits(0.0), Double
142                .doubleToLongBits(StrictMath.cbrt(0.0)));
143        assertEquals(Double.doubleToLongBits(+0.0), Double
144                .doubleToLongBits(StrictMath.cbrt(+0.0)));
145        assertEquals(Double.doubleToLongBits(-0.0), Double
146                .doubleToLongBits(StrictMath.cbrt(-0.0)));
147
148        assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0));
149        assertEquals("Should return 23.111993172558684", 23.111993172558684,
150                StrictMath.cbrt(12345.6));
151        assertEquals("Should return 5.643803094122362E102",
152                5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE));
153        assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001));
154
155        assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0));
156        assertEquals("Should return -23.111993172558684", -23.111993172558684,
157                StrictMath.cbrt(-12345.6));
158        assertEquals("Should return 1.7031839360032603E-108",
159                1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE));
160        assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001));
161
162        try {
163            StrictMath.cbrt((Double) null);
164            fail("Should throw NullPointerException");
165        } catch (NullPointerException e) {
166            //expected
167        }
168    }
169
170    /**
171     * @tests java.lang.StrictMath#ceil(double)
172     */
173    @SmallTest
174    public void testCeilD() {
175        // Test for method double java.lang.StrictMath.ceil(double)
176        assertEquals("Incorrect ceiling for double",
177                79, StrictMath.ceil(78.89), 0.0);
178        assertEquals("Incorrect ceiling for double",
179                -78, StrictMath.ceil(-78.89), 0.0);
180    }
181
182    /**
183     * @tests java.lang.StrictMath#cos(double)
184     */
185    @SmallTest
186    public void testCosD() {
187        // Test for method double java.lang.StrictMath.cos(double)
188
189        assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
190                .acos(ADJ / HYP)) == ADJ / HYP);
191    }
192
193    /**
194     * @tests java.lang.StrictMath#cosh(double)
195     */
196    @SuppressWarnings("boxing")
197    @SmallTest
198    public void testCosh_D() {
199        // Test for special situations
200        assertTrue("Should return NaN", Double.isNaN(StrictMath
201                .cosh(Double.NaN)));
202        assertEquals("Should return POSITIVE_INFINITY",
203                Double.POSITIVE_INFINITY, StrictMath
204                .cosh(Double.POSITIVE_INFINITY));
205        assertEquals("Should return POSITIVE_INFINITY",
206                Double.POSITIVE_INFINITY, StrictMath
207                .cosh(Double.NEGATIVE_INFINITY));
208        assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0));
209        assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0));
210
211        assertEquals("Should return POSITIVE_INFINITY",
212                Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56));
213        assertEquals("Should return POSITIVE_INFINITY",
214                Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56));
215        assertEquals("Should return 1.0000000000005", 1.0000000000005,
216                StrictMath.cosh(0.000001));
217        assertEquals("Should return 1.0000000000005", 1.0000000000005,
218                StrictMath.cosh(-0.000001));
219        assertEquals("Should return 5.212214351945598", 5.212214351945598,
220                StrictMath.cosh(2.33482));
221
222        assertEquals("Should return POSITIVE_INFINITY",
223                Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE));
224        assertEquals("Should return 1.0", 1.0, StrictMath
225                .cosh(Double.MIN_VALUE));
226    }
227
228    /**
229     * @tests java.lang.StrictMath#exp(double)
230     */
231    @SmallTest
232    public void testExpD() {
233        // Test for method double java.lang.StrictMath.exp(double)
234        assertTrue("Incorrect answer returned for simple power", StrictMath
235                .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
236                        * StrictMath.E * StrictMath.E) < 0.1D);
237        assertTrue("Incorrect answer returned for larger power", StrictMath
238                .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
239    }
240
241    /**
242     * @tests java.lang.StrictMath#expm1(double)
243     */
244    @SuppressWarnings("boxing")
245    @SmallTest
246    public void testExpm1D() {
247        //Test for special cases
248        assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN)));
249        assertEquals("Should return POSITIVE_INFINITY",
250                Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY));
251        assertEquals("Should return -1.0", -1.0, StrictMath
252                .expm1(Double.NEGATIVE_INFINITY));
253        assertEquals(Double.doubleToLongBits(0.0), Double
254                .doubleToLongBits(StrictMath.expm1(0.0)));
255        assertEquals(Double.doubleToLongBits(+0.0), Double
256                .doubleToLongBits(StrictMath.expm1(+0.0)));
257        assertEquals(Double.doubleToLongBits(-0.0), Double
258                .doubleToLongBits(StrictMath.expm1(-0.0)));
259
260        assertEquals("Should return -9.999950000166666E-6",
261                -9.999950000166666E-6, StrictMath.expm1(-0.00001));
262        assertEquals("Should return 1.0145103074469635E60",
263                1.0145103074469635E60, StrictMath.expm1(138.16951162));
264        assertEquals("Should return POSITIVE_INFINITY",
265                Double.POSITIVE_INFINITY, StrictMath
266                .expm1(123456789123456789123456789.4521584223));
267        assertEquals("Should return POSITIVE_INFINITY",
268                Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE));
269        assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath
270                .expm1(Double.MIN_VALUE));
271
272    }
273
274    /**
275     * @tests java.lang.StrictMath#floor(double)
276     */
277    @SmallTest
278    public void testFloorD() {
279        // Test for method double java.lang.StrictMath.floor(double)
280        assertEquals("Incorrect floor for double",
281                78, StrictMath.floor(78.89), 0.0);
282        assertEquals("Incorrect floor for double",
283                -79, StrictMath.floor(-78.89), 0.0);
284    }
285
286    /**
287     * @tests java.lang.StrictMath#hypot(double,double)
288     */
289    @SuppressWarnings("boxing")
290    @SmallTest
291    public void testHypotDD() {
292        // Test for special cases
293        assertEquals("Should return POSITIVE_INFINITY",
294                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
295                1.0));
296        assertEquals("Should return POSITIVE_INFINITY",
297                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
298                123.324));
299        assertEquals("Should return POSITIVE_INFINITY",
300                Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587,
301                Double.POSITIVE_INFINITY));
302        assertEquals("Should return POSITIVE_INFINITY",
303                Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21,
304                Double.NEGATIVE_INFINITY));
305        assertEquals("Should return POSITIVE_INFINITY",
306                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
307                Double.NEGATIVE_INFINITY));
308        assertEquals("Should return POSITIVE_INFINITY",
309                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
310                Double.POSITIVE_INFINITY));
311        assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(Double.NaN,
312                2342301.89843)));
313        assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(-345.2680,
314                Double.NaN)));
315
316        assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath
317                .hypot(12322.12, -2396393.2258));
318        assertEquals("Should return 138.16958070558556", 138.16958070558556,
319                StrictMath.hypot(-138.16951162, 0.13817035864));
320        assertEquals("Should return 1.7976931348623157E308",
321                1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35));
322        assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot(
323                -5413.7185, Double.MIN_VALUE));
324
325    }
326
327    /**
328     * @tests java.lang.StrictMath#IEEEremainder(double,double)
329     */
330    @SmallTest
331    public void testIEEEremainderDD() {
332        // Test for method double java.lang.StrictMath.IEEEremainder(double,
333        // double)
334        assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
335                1.0, 1.0), 0.0);
336        assertTrue(
337                "Incorrect remainder returned",
338                StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
339                        || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
340    }
341
342    /**
343     * @tests java.lang.StrictMath#log(double)
344     */
345    @SmallTest
346    public void testLogD() {
347        // Test for method double java.lang.StrictMath.log(double)
348        for (double d = 10; d >= -10; d -= 0.5) {
349            double answer = StrictMath.log(StrictMath.exp(d));
350            assertTrue("Answer does not equal expected answer for d = " + d
351                    + " answer = " + answer,
352                    StrictMath.abs(answer - d) <= StrictMath
353                            .abs(d * 0.00000001));
354        }
355    }
356
357    /**
358     * @tests java.lang.StrictMath#log10(double)
359     */
360    @SuppressWarnings("boxing")
361    @SmallTest
362    public void testLog10D() {
363        // Test for special cases
364        assertTrue("Should return NaN", Double.isNaN(StrictMath
365                .log10(Double.NaN)));
366        assertTrue("Should return NaN", Double.isNaN(StrictMath
367                .log10(-2541.05745687234187532)));
368        assertEquals("Should return POSITIVE_INFINITY",
369                Double.POSITIVE_INFINITY, StrictMath
370                .log10(Double.POSITIVE_INFINITY));
371        assertEquals("Should return NEGATIVE_INFINITY",
372                Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
373        assertEquals("Should return NEGATIVE_INFINITY",
374                Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0));
375        assertEquals("Should return NEGATIVE_INFINITY",
376                Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0));
377        assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath
378                .pow(10, 14)));
379
380        assertEquals("Should return 3.7389561269540406", 3.7389561269540406,
381                StrictMath.log10(5482.2158));
382        assertEquals("Should return 14.661551142893833", 14.661551142893833,
383                StrictMath.log10(458723662312872.125782332587));
384        assertEquals("Should return -0.9083828622192334", -0.9083828622192334,
385                StrictMath.log10(0.12348583358871));
386        assertEquals("Should return 308.25471555991675", 308.25471555991675,
387                StrictMath.log10(Double.MAX_VALUE));
388        assertEquals("Should return -323.3062153431158", -323.3062153431158,
389                StrictMath.log10(Double.MIN_VALUE));
390    }
391
392    /**
393     * @tests java.lang.StrictMath#log1p(double)
394     */
395    @SuppressWarnings("boxing")
396    @SmallTest
397    public void testLog1pD() {
398        // Test for special cases
399        assertTrue("Should return NaN", Double.isNaN(StrictMath
400                .log1p(Double.NaN)));
401        assertTrue("Should return NaN", Double.isNaN(StrictMath
402                .log1p(-32.0482175)));
403        assertEquals("Should return POSITIVE_INFINITY",
404                Double.POSITIVE_INFINITY, StrictMath
405                .log1p(Double.POSITIVE_INFINITY));
406        assertEquals(Double.doubleToLongBits(0.0), Double
407                .doubleToLongBits(StrictMath.log1p(0.0)));
408        assertEquals(Double.doubleToLongBits(+0.0), Double
409                .doubleToLongBits(StrictMath.log1p(+0.0)));
410        assertEquals(Double.doubleToLongBits(-0.0), Double
411                .doubleToLongBits(StrictMath.log1p(-0.0)));
412
413        assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
414                StrictMath.log1p(-0.254856327));
415        assertEquals("Should return 7.368050685564151", 7.368050685564151,
416                StrictMath.log1p(1583.542));
417        assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
418                StrictMath.log1p(0.5894227));
419        assertEquals("Should return 709.782712893384", 709.782712893384,
420                StrictMath.log1p(Double.MAX_VALUE));
421        assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE,
422                StrictMath.log1p(Double.MIN_VALUE));
423    }
424
425    /**
426     * @tests java.lang.StrictMath#max(double,double)
427     */
428    @SmallTest
429    public void testMaxDD() {
430        // Test for method double java.lang.StrictMath.max(double, double)
431        assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
432                -1908897.6000089, 1908897.6000089), 0D);
433        assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
434                1908897.6000089), 0D);
435        assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
436                -1908897.6000089), 0D);
437
438    }
439
440    /**
441     * @tests java.lang.StrictMath#max(float,float)
442     */
443    @SmallTest
444    public void testMaxFF() {
445        // Test for method float java.lang.StrictMath.max(float, float)
446        assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
447                1908897.600f) == 1908897.600f);
448        assertTrue("Incorrect float max value", StrictMath.max(2.0f,
449                1908897.600f) == 1908897.600f);
450        assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
451                -1908897.600f) == -2.0f);
452    }
453
454    /**
455     * @tests java.lang.StrictMath#max(int,int)
456     */
457    @SmallTest
458    public void testMaxII() {
459        // Test for method int java.lang.StrictMath.max(int, int)
460        assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
461                19088976));
462        assertEquals("Incorrect int max value",
463                19088976, StrictMath.max(20, 19088976));
464        assertEquals("Incorrect int max value",
465                -20, StrictMath.max(-20, -19088976));
466    }
467
468    /**
469     * @tests java.lang.StrictMath#max(long,long)
470     */
471    @SmallTest
472    public void testMaxJJ() {
473        // Test for method long java.lang.StrictMath.max(long, long)
474        assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
475                19088976000089L));
476        assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
477                19088976000089L));
478        assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
479                -19088976000089L));
480    }
481
482    /**
483     * @tests java.lang.StrictMath#min(double,double)
484     */
485    @SmallTest
486    public void testMinDD() {
487        // Test for method double java.lang.StrictMath.min(double, double)
488        assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
489                -1908897.6000089, 1908897.6000089), 0D);
490        assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
491                1908897.6000089), 0D);
492        assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
493                -1908897.6000089), 0D);
494    }
495
496    /**
497     * @tests java.lang.StrictMath#min(float,float)
498     */
499    @SmallTest
500    public void testMinFF() {
501        // Test for method float java.lang.StrictMath.min(float, float)
502        assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
503                1908897.600f) == -1908897.600f);
504        assertTrue("Incorrect float min value", StrictMath.min(2.0f,
505                1908897.600f) == 2.0f);
506        assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
507                -1908897.600f) == -1908897.600f);
508    }
509
510    /**
511     * @tests java.lang.StrictMath#min(int,int)
512     */
513    @SmallTest
514    public void testMinII() {
515        // Test for method int java.lang.StrictMath.min(int, int)
516        assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
517                19088976));
518        assertEquals("Incorrect int min value",
519                20, StrictMath.min(20, 19088976));
520        assertEquals("Incorrect int min value",
521                -19088976, StrictMath.min(-20, -19088976));
522
523    }
524
525    /**
526     * @tests java.lang.StrictMath#min(long,long)
527     */
528    @SmallTest
529    public void testMinJJ() {
530        // Test for method long java.lang.StrictMath.min(long, long)
531        assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
532                19088976000089L));
533        assertEquals("Incorrect long min value", 20, StrictMath.min(20,
534                19088976000089L));
535        assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
536                -19088976000089L));
537    }
538
539    /**
540     * @tests java.lang.StrictMath#pow(double,double)
541     */
542    @SmallTest
543    public void testPowDD() {
544        // Test for method double java.lang.StrictMath.pow(double, double)
545        assertTrue("pow returned incorrect value",
546                (long) StrictMath.pow(2, 8) == 256l);
547        assertTrue("pow returned incorrect value",
548                StrictMath.pow(2, -8) == 0.00390625d);
549    }
550
551    /**
552     * @tests java.lang.StrictMath#rint(double)
553     */
554    @SmallTest
555    public void testRintD() {
556        // Test for method double java.lang.StrictMath.rint(double)
557        assertEquals("Failed to round properly - up to odd",
558                3.0, StrictMath.rint(2.9), 0D);
559        assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
560                .rint(Double.NaN)));
561        assertEquals("Failed to round properly down  to even", 2.0, StrictMath
562                .rint(2.1), 0D);
563        assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
564                .rint(2.5) == 2.0);
565    }
566
567    /**
568     * @tests java.lang.StrictMath#round(double)
569     */
570    @SmallTest
571    public void testRoundD() {
572        // Test for method long java.lang.StrictMath.round(double)
573        assertEquals("Incorrect rounding of a float",
574                -91, StrictMath.round(-90.89d));
575    }
576
577    /**
578     * @tests java.lang.StrictMath#round(float)
579     */
580    @SmallTest
581    public void testRoundF() {
582        // Test for method int java.lang.StrictMath.round(float)
583        assertEquals("Incorrect rounding of a float",
584                -91, StrictMath.round(-90.89f));
585    }
586
587    /**
588     * @tests java.lang.StrictMath#signum(double)
589     */
590    @SmallTest
591    public void testSignumD() {
592        assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
593        assertEquals(Double.doubleToLongBits(0.0), Double
594                .doubleToLongBits(StrictMath.signum(0.0)));
595        assertEquals(Double.doubleToLongBits(+0.0), Double
596                .doubleToLongBits(StrictMath.signum(+0.0)));
597        assertEquals(Double.doubleToLongBits(-0.0), Double
598                .doubleToLongBits(StrictMath.signum(-0.0)));
599
600        assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
601        assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
602        assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
603        assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
604
605        assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
606        assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
607        assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
608        assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
609        assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D);
610        assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D);
611
612    }
613
614    /**
615     * @tests java.lang.StrictMath#signum(float)
616     */
617    @SmallTest
618    public void testSignumF() {
619        assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
620        assertEquals(Float.floatToIntBits(0.0f), Float
621                .floatToIntBits(StrictMath.signum(0.0f)));
622        assertEquals(Float.floatToIntBits(+0.0f), Float
623                .floatToIntBits(StrictMath.signum(+0.0f)));
624        assertEquals(Float.floatToIntBits(-0.0f), Float
625                .floatToIntBits(StrictMath.signum(-0.0f)));
626
627        assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
628        assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
629        assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
630        assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
631
632        assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
633        assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
634        assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
635        assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
636        assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f);
637        assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f);
638    }
639
640    /**
641     * @tests java.lang.StrictMath#sin(double)
642     */
643    @SmallTest
644    public void testSinD() {
645        // Test for method double java.lang.StrictMath.sin(double)
646        assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
647                .asin(OPP / HYP)) == OPP / HYP);
648    }
649
650    /**
651     * @tests java.lang.StrictMath#sinh(double)
652     */
653    @SmallTest
654    public void testSinhD() {
655        // Test for special situations
656        assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN)));
657        assertEquals("Should return POSITIVE_INFINITY",
658                Double.POSITIVE_INFINITY, StrictMath
659                .sinh(Double.POSITIVE_INFINITY), 0D);
660        assertEquals("Should return NEGATIVE_INFINITY",
661                Double.NEGATIVE_INFINITY, StrictMath
662                .sinh(Double.NEGATIVE_INFINITY), 0D);
663        assertEquals(Double.doubleToLongBits(0.0), Double
664                .doubleToLongBits(StrictMath.sinh(0.0)));
665        assertEquals(Double.doubleToLongBits(+0.0), Double
666                .doubleToLongBits(StrictMath.sinh(+0.0)));
667        assertEquals(Double.doubleToLongBits(-0.0), Double
668                .doubleToLongBits(StrictMath.sinh(-0.0)));
669
670        assertEquals("Should return POSITIVE_INFINITY",
671                Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D);
672        assertEquals("Should return NEGATIVE_INFINITY",
673                Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D);
674        assertEquals("Should return 1.0000000000001666E-6",
675                1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D);
676        assertEquals("Should return -1.0000000000001666E-6",
677                -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D);
678        assertEquals("Should return 5.115386441963859", 5.115386441963859,
679                StrictMath.sinh(2.33482), 0D);
680        assertEquals("Should return POSITIVE_INFINITY",
681                Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D);
682        assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
683                .sinh(Double.MIN_VALUE), 0D);
684    }
685
686    /**
687     * @tests java.lang.StrictMath#sqrt(double)
688     */
689    @SmallTest
690    public void testSqrtD() {
691        // Test for method double java.lang.StrictMath.sqrt(double)
692        assertEquals("Incorrect root returned1",
693                2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
694        assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
695    }
696
697    /**
698     * @tests java.lang.StrictMath#tan(double)
699     */
700    @SmallTest
701    public void testTanD() {
702        // Test for method double java.lang.StrictMath.tan(double)
703        assertTrue(
704                "Returned incorrect tangent: ",
705                StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
706                        || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
707    }
708
709    /**
710     * @tests java.lang.StrictMath#tanh(double)
711     */
712    @SmallTest
713    public void testTanhD() {
714        // Test for special situations
715        assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN)));
716        assertEquals("Should return +1.0", +1.0, StrictMath
717                .tanh(Double.POSITIVE_INFINITY), 0D);
718        assertEquals("Should return -1.0", -1.0, StrictMath
719                .tanh(Double.NEGATIVE_INFINITY), 0D);
720        assertEquals(Double.doubleToLongBits(0.0), Double
721                .doubleToLongBits(StrictMath.tanh(0.0)));
722        assertEquals(Double.doubleToLongBits(+0.0), Double
723                .doubleToLongBits(StrictMath.tanh(+0.0)));
724        assertEquals(Double.doubleToLongBits(-0.0), Double
725                .doubleToLongBits(StrictMath.tanh(-0.0)));
726
727        assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D);
728        assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D);
729        assertEquals("Should return 9.999999999996666E-7",
730                9.999999999996666E-7, StrictMath.tanh(0.000001), 0D);
731        assertEquals("Should return 0.981422884124941", 0.981422884124941,
732                StrictMath.tanh(2.33482), 0D);
733        assertEquals("Should return 1.0", 1.0, StrictMath
734                .tanh(Double.MAX_VALUE), 0D);
735        assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
736                .tanh(Double.MIN_VALUE), 0D);
737    }
738
739    /**
740     * @tests java.lang.StrictMath#random()
741     */
742    @MediumTest
743    public void testRandom() {
744        // There isn't a place for these tests so just stick them here
745        assertEquals("Wrong value E",
746                4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
747        assertEquals("Wrong value PI",
748                4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
749
750        for (int i = 500; i >= 0; i--) {
751            double d = StrictMath.random();
752            assertTrue("Generated number is out of range: " + d, d >= 0.0
753                    && d < 1.0);
754        }
755    }
756
757    /**
758     * @tests java.lang.StrictMath#toRadians(double)
759     */
760    @MediumTest
761    public void testToRadiansD() {
762        for (double d = 500; d >= 0; d -= 1.0) {
763            double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
764            assertTrue("Converted number not equal to original. d = " + d,
765                    converted >= d * 0.99999999 && converted <= d * 1.00000001);
766        }
767    }
768
769    /**
770     * @tests java.lang.StrictMath#toDegrees(double)
771     */
772    @MediumTest
773    public void testToDegreesD() {
774        for (double d = 500; d >= 0; d -= 1.0) {
775            double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
776            assertTrue("Converted number not equal to original. d = " + d,
777                    converted >= d * 0.99999999 && converted <= d * 1.00000001);
778        }
779    }
780
781    /**
782     * @tests java.lang.StrictMath#ulp(double)
783     */
784    @SuppressWarnings("boxing")
785    @SmallTest
786    public void testUlp_D() {
787        // Test for special cases
788        assertTrue("Should return NaN", Double
789                .isNaN(StrictMath.ulp(Double.NaN)));
790        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
791                StrictMath.ulp(Double.POSITIVE_INFINITY), 0D);
792        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
793                StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D);
794        assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
795                .ulp(0.0), 0D);
796        assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
797                .ulp(+0.0), 0D);
798        assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
799                .ulp(-0.0), 0D);
800        assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
801                StrictMath.ulp(Double.MAX_VALUE), 0D);
802        assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
803                StrictMath.ulp(-Double.MAX_VALUE), 0D);
804
805        assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
806                .ulp(Double.MIN_VALUE), 0D);
807        assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
808                .ulp(-Double.MIN_VALUE), 0D);
809
810        assertEquals("Returned incorrect value", 2.220446049250313E-16,
811                StrictMath.ulp(1.0), 0D);
812        assertEquals("Returned incorrect value", 2.220446049250313E-16,
813                StrictMath.ulp(-1.0), 0D);
814        assertEquals("Returned incorrect value", 2.2737367544323206E-13,
815                StrictMath.ulp(1153.0), 0D);
816    }
817
818    /**
819     * @tests java.lang.StrictMath#ulp(float)
820     */
821    @SuppressWarnings("boxing")
822    @SmallTest
823    public void testUlpF() {
824        // Test for special cases
825        assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN)));
826        assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
827                StrictMath.ulp(Float.POSITIVE_INFINITY), 0f);
828        assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
829                StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f);
830        assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
831                .ulp(0.0f), 0f);
832        assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
833                .ulp(+0.0f), 0f);
834        assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
835                .ulp(-0.0f), 0f);
836        assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
837                .ulp(Float.MAX_VALUE), 0f);
838        assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
839                .ulp(-Float.MAX_VALUE), 0f);
840
841        assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
842                .ulp(Float.MIN_VALUE), 0f);
843        assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
844                .ulp(-Float.MIN_VALUE), 0f);
845
846        assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
847                .ulp(1.0f), 0f);
848        assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
849                .ulp(-1.0f), 0f);
850        assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath
851                .ulp(1153.0f), 0f);
852        assertEquals("Returned incorrect value", 5.6E-45f, Math
853                .ulp(9.403954E-38f), 0f);
854    }
855}
856