commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1179927 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/StepFunction.java test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
Date Fri, 07 Oct 2011 03:19:10 GMT
Author: psteitz
Date: Fri Oct  7 03:19:10 2011
New Revision: 1179927

URL: http://svn.apache.org/viewvc?rev=1179927&view=rev
Log:
Improved javadoc, added test.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/StepFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/StepFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/StepFunction.java?rev=1179927&r1=1179926&r2=1179927&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/StepFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/StepFunction.java
Fri Oct  7 03:19:10 2011
@@ -38,15 +38,22 @@ public class StepFunction implements Uni
     private final double[] ordinate;
 
     /**
-     * Builds a step function from a list of abscissae and the corresponding
-     * ordinates.
+     * Builds a step function from a list of arguments and the corresponding
+     * values. Specifically, returns the function h(x) defined by <pre></code>
+     * h(x) = y[0] for all x < x[1]
+     *        y[1] for x[1] <= x < x[2]
+     *        ...
+     *        y[y.length] for x >= x[x.length]
+     * </pre></code>
+     * The value of x[0] is ignored, but it must be strictly less than x[1].
      *
-     * @param x Abscissae.
-     * @param y Ordinates.
+     * @param x domain values where the function changes value.
+     * @param y values of the function.
      * @throws org.apache.commons.math.exception.NonMonotonicSequenceException
      * if the {@code x} array is not sorted in strictly increasing order.
      * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
      * @throws NoDataException if {@code x} or {@code y} are zero-length.
+     * @throws DimensionMismatchException if x and y do not have the same length
      */
     public StepFunction(double[] x,
                         double[] y) {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java?rev=1179927&r1=1179926&r2=1179927&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
Fri Oct  7 03:19:10 2011
@@ -78,6 +78,27 @@ public class StepFunctionTest {
         Assert.assertEquals(51.2, f.value(30), EPS);
         Assert.assertEquals(51.2, f.value(Double.POSITIVE_INFINITY), EPS);
     }
+    
+    @Test
+    public void testEndpointBehavior() {
+        final double[] x = {0, 1, 2, 3};
+        final double[] xp = {-8, 1, 2, 3};
+        final double[] y = {1, 2, 3, 4};
+        final UnivariateRealFunction f = new StepFunction(x, y);
+        final UnivariateRealFunction fp = new StepFunction(xp, y);
+        Assert.assertEquals(f.value(-8), fp.value(-8), EPS);
+        Assert.assertEquals(f.value(-10), fp.value(-10), EPS);
+        Assert.assertEquals(f.value(0), fp.value(0), EPS);
+        Assert.assertEquals(f.value(0.5), fp.value(0.5), EPS);
+        for (int i = 0; i < x.length; i++) {
+           Assert.assertEquals(y[i], f.value(x[i]), EPS);
+           if (i > 0) {
+               Assert.assertEquals(y[i - 1], f.value(x[i] - 0.5), EPS); 
+           } else {
+               Assert.assertEquals(y[0], f.value(x[i] - 0.5), EPS); 
+           }
+        }
+    }
 
     @Test
     public void testHeaviside() {   



Mime
View raw message