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  package org.apache.commons.nabla;
18  
19  import org.junit.Test;
20  
21  public abstract class AbstractNablaTest extends AbstractStaticFunctionsTest {
22  
23      @Test
24      public void testExponential() {
25          defaultMonadicTest("exp");
26          defaultMonadicTest("expm1");
27          defaultMonadicTest("log");
28          defaultMonadicTest("log1p");
29          defaultMonadicTest("log10");
30      }
31  
32      @Test
33      public void testCircular() {
34          defaultMonadicTest("cos");
35          defaultMonadicTest("sin");
36          defaultMonadicTest("tan");
37          defaultMonadicTest("acos");
38          defaultMonadicTest("asin");
39          defaultMonadicTest("atan");
40          checkDiadicFunction(getNablaClass(), getJavaClass(), "atan2",
41                              -0.1, 0.3, 3, -0.7, 0.7, 15, 1.0e-15, 1.0e-12);
42          checkDiadicFunction(getNablaClass(), getJavaClass(), "hypot",
43                              -0.1, 0.3, 3, -0.7, 0.7, 15, 1.0e-15, 1.0e-12);
44      }
45  
46      @Test
47      public void testHyperbolic() {
48  
49          defaultMonadicTest("cosh");
50          defaultMonadicTest("sinh");
51          defaultMonadicTest("tanh");
52  
53          checkMonadicFunction(getNablaClass(), getClass(), "acosh",
54                               1.1, 1.3, 10, 1.0e-20, 2.0e-12);
55          checkMonadicFunction(getNablaClass(), getClass(), "asinh",
56                               1.1, 1.3, 10, 1.0e-20, 2.0e-12);
57          checkMonadicFunction(getNablaClass(), getClass(), "atanh",
58                               0.1, 0.3, 10, 1.0e-20, 2.0e-12);
59  
60      }
61  
62      @Test
63      public void testPower() {
64          defaultMonadicTest("sqrt");
65          defaultMonadicTest("cbrt");
66          checkDiadicFunction(getNablaClass(), getJavaClass(), "pow",
67                              0.1, 0.3, 3, 0.7, 1.5, 15, 1.0e-15, 1.0e-11);
68          checkDiadicFunction(getNablaClass(), getJavaClass(), "hypot",
69                              0.1, 0.3, 3, 0.7, 1.5, 15, 1.0e-15, 1.0e-11);
70      }
71  
72      @Test
73      public void testSign() {
74          defaultMonadicTest("abs");
75          defaultMonadicTest("signum");
76          defaultDiadicTest("copySign");
77      }
78  
79      @Test
80      public void testNeighborhood() {
81          defaultMonadicTest("floor");
82          defaultMonadicTest("rint");
83          defaultMonadicTest("ceil");
84          defaultMonadicTest("nextUp");
85          defaultDiadicTest("nextAfter");
86      }
87  
88      @Test
89      public void testEncoding() {
90          defaultMonadicTest("ulp");
91          checkFunction(getNablaClass(), getJavaClass(),
92                        new Class<?>[] { Double.TYPE, Integer.TYPE }, "scalb",
93                        new double[][] {
94                                        { 0.1, 5 }, { 0.2, 5 }, { 0.3, 5 },
95                                        { 0.1, 6 }, { 0.2, 6 }, { 0.3, 6 },
96                                        { 0.1, 7 }, { 0.2, 7 }, { 0.3, 7 }
97          }, 1.0e-20, 1.0e-12);
98          checkDiadicFunction(getNablaClass(), getJavaClass(), "IEEEremainder",
99                              0.1, 0.3, 3, 12, 17, 3, 1.0e-15, 1.0e-8);
100     }
101 
102     @Test
103     public void testConversion() {
104         defaultMonadicTest("toDegrees");
105         defaultMonadicTest("toRadians");
106     }
107 
108     @Test
109     public void testComparison() {
110         checkDiadicFunction(getNablaClass(), getJavaClass(), "max",
111                             0.1, 0.3, 3, 0.15, 0.35, 3, 1.0e-20, 1.0e-15);
112         checkDiadicFunction(getNablaClass(), getJavaClass(), "min",
113                             0.1, 0.3, 3, 0.15, 0.35, 3, 1.0e-20, 1.0e-15);
114     }
115 
116 }