001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.lang;
032:
033: import junit.framework.*;
034:
035: /**
036: * @author Taras Puchko
037: */
038: public class _MathTestCase extends TestCase {
039:
040: public void testCbrt() throws Exception {
041: assertEquals(0.4641588833612779, Math.cbrt(0.1));
042: assertEquals(-0.4641588833612779, Math.cbrt(-0.1));
043: assertEquals(1.0, Math.cbrt(1));
044: assertEquals(-1.0, Math.cbrt(-1));
045: assertEquals(2.154434690031884, Math.cbrt(10));
046: assertEquals(-2.154434690031884, Math.cbrt(-10));
047: assertEquals(Double.NaN, Math.cbrt(Double.NaN));
048: assertEquals(Double.POSITIVE_INFINITY, Math
049: .cbrt(Double.POSITIVE_INFINITY));
050: assertEquals(Double.NEGATIVE_INFINITY, Math
051: .cbrt(Double.NEGATIVE_INFINITY));
052: assertEquals(0.0, Math.cbrt(0.0));
053: assertEquals(-0.0, Math.cbrt(-0.0));
054: }
055:
056: public void testCosh() throws Exception {
057: assertEquals(1.0050041680558035, Math.cosh(0.1));
058: assertEquals(1.0050041680558035, Math.cosh(-0.1));
059: assertEquals(1.543080634815244, Math.cosh(1));
060: assertEquals(1.543080634815244, Math.cosh(-1));
061: assertEquals(11013.232920103324, Math.cosh(10));
062: assertEquals(11013.232920103324, Math.cosh(-10));
063: assertEquals(Double.NaN, Math.cosh(Double.NaN));
064: assertEquals(Double.POSITIVE_INFINITY, Math
065: .cosh(Double.POSITIVE_INFINITY));
066: assertEquals(Double.POSITIVE_INFINITY, Math
067: .cosh(Double.NEGATIVE_INFINITY));
068: assertEquals(1.0, Math.cosh(0.0));
069: assertEquals(1.0, Math.cosh(-0.0));
070: }
071:
072: public void testExpm1() throws Exception {
073: assertEquals(0.10517091807564763, Math.expm1(0.1), 1E-16);
074: assertEquals(-0.09516258196404043, Math.expm1(-0.1), 1E-16);
075: assertEquals(1.718281828459045, Math.expm1(1), 1E-15);
076: assertEquals(-0.6321205588285577, Math.expm1(-1));
077: assertEquals(22025.465794806718, Math.expm1(10));
078: assertEquals(-0.9999546000702375, Math.expm1(-10));
079: assertEquals(Double.NaN, Math.expm1(Double.NaN));
080: assertEquals(Double.POSITIVE_INFINITY, Math
081: .expm1(Double.POSITIVE_INFINITY));
082: assertEquals(-1.0, Math.expm1(Double.NEGATIVE_INFINITY));
083: assertEquals(0.0, Math.expm1(0.0));
084: assertEquals(-0.0, Math.expm1(-0.0));
085: }
086:
087: public void testLog10() throws Exception {
088: assertEquals(-1.0, Math.log10(0.1), 1E-15);
089: assertEquals(Double.NaN, Math.log10(-0.1));
090: assertEquals(0.0, Math.log10(1));
091: assertEquals(Double.NaN, Math.log10(-1));
092: assertEquals(1.0, Math.log10(10));
093: assertEquals(3.0, Math.log10(1000));
094: assertTrue(Math.log10(100) <= Math.log10(100.00001));
095: assertEquals(Double.NaN, Math.log10(-10));
096: assertEquals(4.091491094267951, Math.log10(12345), 1E-15);
097: assertEquals(Double.NaN, Math.log10(Double.NaN));
098: assertEquals(Double.POSITIVE_INFINITY, Math
099: .log10(Double.POSITIVE_INFINITY));
100: assertEquals(Double.NaN, Math.log10(Double.NEGATIVE_INFINITY));
101: assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0));
102: assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0));
103: }
104:
105: public void testLog1p() throws Exception {
106: assertEquals(0.09531017980432487, Math.log1p(0.1), 1E-16);
107: assertEquals(-0.10536051565782631, Math.log1p(-0.1), 1E-16);
108: assertEquals(0.6931471805599453, Math.log1p(1));
109: assertEquals(Double.NEGATIVE_INFINITY, Math.log1p(-1));
110: assertEquals(2.3978952727983707, Math.log1p(10));
111: assertEquals(Double.NaN, Math.log1p(-10));
112: assertEquals(Double.NaN, Math.log1p(Double.NaN));
113: assertEquals(Double.POSITIVE_INFINITY, Math
114: .log1p(Double.POSITIVE_INFINITY));
115: assertEquals(Double.NaN, Math.log1p(Double.NEGATIVE_INFINITY));
116: assertEquals(0.0, Math.log1p(0.0));
117: assertEquals(-0.0, Math.log1p(-0.0));
118: }
119:
120: public void testSinh() throws Exception {
121: assertEquals(0.10016675001984403, Math.sinh(0.1), 1E-16);
122: assertEquals(-0.10016675001984403, Math.sinh(-0.1), 1E-16);
123: assertEquals(1.1752011936438014, Math.sinh(1), 1E-15);
124: assertEquals(-1.1752011936438014, Math.sinh(-1), 1E-15);
125: assertEquals(11013.232874703393, Math.sinh(10));
126: assertEquals(-11013.232874703393, Math.sinh(-10));
127: assertEquals(Double.NaN, Math.sinh(Double.NaN));
128: assertEquals(Double.POSITIVE_INFINITY, Math
129: .sinh(Double.POSITIVE_INFINITY));
130: assertEquals(Double.NEGATIVE_INFINITY, Math
131: .sinh(Double.NEGATIVE_INFINITY));
132: assertEquals(0.0, Math.sinh(0.0));
133: assertEquals(-0.0, Math.sinh(-0.0));
134: }
135:
136: public void testTanh() throws Exception {
137: assertEquals(0.09966799462495582, Math.tanh(0.1), 1E-16);
138: assertEquals(-0.09966799462495582, Math.tanh(-0.1), 1E-16);
139: assertEquals(0.7615941559557649, Math.tanh(1));
140: assertEquals(-0.7615941559557649, Math.tanh(-1));
141: assertEquals(0.9999999958776927, Math.tanh(10), 1E-15);
142: assertEquals(-0.9999999958776927, Math.tanh(-10), 1E-15);
143: assertEquals(Double.NaN, Math.tanh(Double.NaN));
144: assertEquals(0.0, Math.tanh(0.0));
145: assertEquals(-0.0, Math.tanh(-0.0));
146: assertEquals(1.0, Math.tanh(Double.POSITIVE_INFINITY));
147: assertEquals(-1.0, Math.tanh(Double.NEGATIVE_INFINITY));
148: }
149:
150: public void testSignum_Double() throws Exception {
151: assertEquals(1.0, Math.signum(123d));
152: assertEquals(-1.0, Math.signum(-12d));
153: assertEquals(Double.NaN, Math.signum(Double.NaN));
154: assertEquals(0.0, Math.signum(0.0d));
155: assertEquals(-0.0, Math.signum(-0.0d));
156: assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY));
157: assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY));
158: }
159:
160: public void testSignum_Float() throws Exception {
161: assertEquals(1.0f, Math.signum(123f));
162: assertEquals(-1.0f, Math.signum(-12f));
163: assertEquals(Float.NaN, Math.signum(Float.NaN));
164: assertEquals(0.0f, Math.signum(0.0f));
165: assertEquals(-0.0f, Math.signum(-0.0f));
166: assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY));
167: assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY));
168: }
169:
170: }
|