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.forward;
18  
19  import org.apache.commons.math3.analysis.UnivariateFunction;
20  import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
21  import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
22  import org.apache.commons.math3.util.FastMath;
23  import org.apache.commons.nabla.AbstractMathTest;
24  import org.apache.commons.nabla.DifferentiationException;
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  public class Log10GeneratorTest extends AbstractMathTest {
29  
30      @Test
31      public void testReference(){
32          checkReference(new ReferenceFunction() {
33              public double value(double t) { return FastMath.log10(t); }
34              public double firstDerivative(double t) { return 1 / (FastMath.log(10) * t); }
35          }, 0.1, 10, 50, 3.0e-16);
36      }
37  
38      @Test
39      public void testSingularity() throws DifferentiationException {
40          UnivariateDifferentiableFunction derivative =
41              new ForwardModeDifferentiator().differentiate(new UnivariateFunction() {
42                  public double value(double t) { return FastMath.log10(t); }
43              });
44  
45          double dPlus = derivative.value(new DerivativeStructure(1, 1, 0.0, 1.0)).getPartialDerivative(1);
46          Assert.assertTrue(Double.isInfinite(dPlus));
47          Assert.assertTrue(dPlus > 0);
48  
49          double dMinus = derivative.value(new DerivativeStructure(1, 1, 0.0, -1.0)).getPartialDerivative(1);
50          Assert.assertTrue(Double.isInfinite(dMinus));
51          Assert.assertTrue(dMinus < 0);
52  
53      }
54  
55  }