commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject [5/8] [math] Prevent NullPointerException in tests.
Date Tue, 08 Dec 2015 19:34:10 GMT
Prevent NullPointerException in tests.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a3d10998
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a3d10998
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a3d10998

Branch: refs/heads/field-ode
Commit: a3d10998f03bbdaaf4e63e98591f76b8f64fb793
Parents: b9e3ac5
Author: Luc Maisonobe <luc@apache.org>
Authored: Tue Dec 8 20:12:49 2015 +0100
Committer: Luc Maisonobe <luc@apache.org>
Committed: Tue Dec 8 20:12:49 2015 +0100

----------------------------------------------------------------------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 32 +++++++++++++++++---
 1 file changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3d10998/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 82e9887..64365b4 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -22,7 +22,9 @@ import java.lang.reflect.InvocationTargetException;
 
 import org.apache.commons.math3.Field;
 import org.apache.commons.math3.RealFieldElement;
+import org.apache.commons.math3.ode.AbstractIntegrator;
 import org.apache.commons.math3.ode.EquationsMapper;
+import org.apache.commons.math3.ode.ExpandableStatefulODE;
 import org.apache.commons.math3.ode.FieldEquationsMapper;
 import org.apache.commons.math3.ode.FieldExpandableODE;
 import org.apache.commons.math3.ode.FieldFirstOrderDifferentialEquations;
@@ -70,7 +72,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
         RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
                                                                             new SinCos<>(field),
-                                                                            0.0, new double[]
{ 0.0, 1.0 }, 0.125);
+                                                                            0.0, new double[]
{ 0.0, 1.0 }, 0.0125);
 
         int n = 100;
         double maxErrorSin = 0;
@@ -95,9 +97,10 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                                                      double
epsilonSin, double epsilonCos,
                                                                                      double
epsilonSinDot, double epsilonCosDot) {
 
+        FieldFirstOrderDifferentialEquations<T> eqn = new SinCos<>(field);
         RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
-                        setUpInterpolator(field, new SinCos<>(field), 0.0, new double[]
{ 0.0, 1.0 }, 0.125);
-        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator);
+                        setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
+        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator,
eqn);
 
         int n = 100;
         double maxErrorSin    = 0;
@@ -185,7 +188,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
     }
 
     private <T extends RealFieldElement<T>>
-    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T>
fieldInterpolator) {
+    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T>
fieldInterpolator,
+                                                   final FieldFirstOrderDifferentialEquations<T>
eqn) {
 
         RungeKuttaStepInterpolator regularInterpolator = null;
         try {
@@ -225,7 +229,25 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                 secondaryMappers[i] = new EquationsMapper(start[i + 1], start[i + 2]);
             }
 
-            regularInterpolator.reinitialize(null, y, yDotArray,
+            AbstractIntegrator dummyIntegrator = new AbstractIntegrator("dummy") {
+                @Override
+                public void integrate(ExpandableStatefulODE equations, double t) {
+                    Assert.fail("this method should not be called");
+                }
+                @Override
+                public void computeDerivatives(final double t, final double[] y, final double[]
yDot) {
+                    T fieldT = fieldInterpolator.getField().getZero().add(t);
+                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getField(), y.length);
+                    for (int i = 0; i < y.length; ++i) {
+                        fieldY[i] = fieldInterpolator.getField().getZero().add(y[i]);
+                    }
+                    T[] fieldYDot = eqn.computeDerivatives(fieldT, fieldY);
+                    for (int i = 0; i < yDot.length; ++i) {
+                        yDot[i] = fieldYDot[i].getReal();
+                    }
+                }
+            };
+            regularInterpolator.reinitialize(dummyIntegrator, y, yDotArray,
                                              fieldInterpolator.isForward(),
                                              primaryMapper, secondaryMappers);
 


Mime
View raw message