commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1358319 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
Date Fri, 06 Jul 2012 17:59:43 GMT
Author: celestin
Date: Fri Jul  6 17:59:42 2012
New Revision: 1358319

URL: http://svn.apache.org/viewvc?rev=1358319&view=rev
Log:
MATH-795: in ArrayRealVectorTest, cleaned up the minimal implementation of RealVector, RealVectorTestImpl.
This minimal implementation used to be cluttered with unnecessary method implementations,
which should have been removed when the interface RealVector was changed into an abstract
class.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1358319&r1=1358318&r2=1358319&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
Fri Jul  6 17:59:42 2012
@@ -17,11 +17,9 @@
 package org.apache.commons.math3.linear;
 
 import java.io.Serializable;
-import java.util.Iterator;
 
 import org.apache.commons.math3.analysis.UnivariateFunction;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
-import org.apache.commons.math3.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -32,13 +30,15 @@ import org.junit.Test;
  */
 public class ArrayRealVectorTest extends RealVectorAbstractTest {
 
-    // Testclass to test the RealVector interface
-    // only with enough content to support the test
+    /**
+     * Minimal implementation of the {@link RealVector} abstract class, for
+     * mixed types unit tests.
+     */
     public static class RealVectorTestImpl extends RealVector
         implements Serializable {
 
         /** Serializable version identifier. */
-        private static final long serialVersionUID = 4715341047369582908L;
+        private static final long serialVersionUID = 20120706L;
 
         /** Entries of the vector. */
         protected double data[];
@@ -52,111 +52,16 @@ public class ArrayRealVectorTest extends
         }
 
         @Override
-        public RealVector map(UnivariateFunction function) {
-            throw unsupported();
-        }
-
-        @Override
         public RealVector mapToSelf(UnivariateFunction function) {
-            throw unsupported();
-        }
-
-        @Override
-        public Iterator<Entry> iterator() {
-            return new Iterator<Entry>() {
-                int i = 0;
-                public boolean hasNext() {
-                    return i<data.length;
-                }
-                public Entry next() {
-                    final int j = i++;
-                    Entry e = new Entry() {
-                        @Override
-                        public double getValue() {
-                            return data[j];
-                        }
-                        @Override
-                        public void setValue(double newValue) {
-                            data[j] = newValue;
-                        }
-                    };
-                    e.setIndex(j);
-                    return e;
-                }
-                public void remove() { }
-            };
-        }
-
-        @Override
-        public Iterator<Entry> sparseIterator() {
-            return iterator();
-        }
-
-        @Override
-        public RealVector copy() {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector add(RealVector v) {
-            throw unsupported();
-        }
-
-        public RealVector add(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector subtract(RealVector v) {
-            throw unsupported();
-        }
-
-        public RealVector subtract(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapAdd(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapAddToSelf(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapSubtract(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapSubtractToSelf(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapMultiply(double d) {
-            double[] out = new double[data.length];
             for (int i = 0; i < data.length; i++) {
-                out[i] = data[i] * d;
+                data[i] = function.value(data[i]);
             }
-            return new ArrayRealVector(out);
+            return this;
         }
 
         @Override
-        public RealVector mapMultiplyToSelf(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapDivide(double d) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector mapDivideToSelf(double d) {
-            throw unsupported();
+        public RealVector copy() {
+            return new RealVectorTestImpl(data);
         }
 
         @Override
@@ -164,114 +69,11 @@ public class ArrayRealVectorTest extends
             throw unsupported();
         }
 
-        public RealVector ebeMultiply(double[] v) {
-            throw unsupported();
-        }
-
         @Override
         public RealVector ebeDivide(RealVector v) {
             throw unsupported();
         }
 
-        public RealVector ebeDivide(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public double dotProduct(RealVector v) {
-            double dot = 0;
-            for (int i = 0; i < data.length; i++) {
-                dot += data[i] * v.getEntry(i);
-            }
-            return dot;
-        }
-
-        public double dotProduct(double[] v) {
-            double dot = 0;
-            for (int i = 0; i < data.length; i++) {
-                dot += data[i] * v[i];
-            }
-            return dot;
-        }
-
-        @Override
-        public double cosine(RealVector v) {
-            throw unsupported();
-        }
-
-        public double cosine(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public double getNorm() {
-            double sqrNorm = 0.0;
-            for (int i = 0; i < data.length; i++) {
-                sqrNorm += data[i] * data[i];
-            }
-            return FastMath.sqrt(sqrNorm);
-        }
-
-        @Override
-        public double getL1Norm() {
-            throw unsupported();
-        }
-
-        @Override
-        public double getLInfNorm() {
-            throw unsupported();
-        }
-
-        @Override
-        public double getDistance(RealVector v) {
-            throw unsupported();
-        }
-
-        public double getDistance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public double getL1Distance(RealVector v) {
-            throw unsupported();
-        }
-
-        public double getL1Distance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public double getLInfDistance(RealVector v) {
-            throw unsupported();
-        }
-
-        public double getLInfDistance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector unitVector() {
-            throw unsupported();
-        }
-
-        @Override
-        public void unitize() {
-            throw unsupported();
-        }
-
-        public RealVector projection(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealMatrix outerProduct(RealVector v) {
-            throw unsupported();
-        }
-
-        public RealMatrix outerProduct(double[] v) {
-            throw unsupported();
-        }
-
         @Override
         public double getEntry(int index) {
             return data[index];
@@ -292,10 +94,6 @@ public class ArrayRealVectorTest extends
             throw unsupported();
         }
 
-        public RealVector append(double[] a) {
-            throw unsupported();
-        }
-
         @Override
         public RealVector getSubVector(int index, int n) {
             throw unsupported();
@@ -311,10 +109,6 @@ public class ArrayRealVectorTest extends
             throw unsupported();
         }
 
-        public void setSubVector(int index, double[] v) {
-            throw unsupported();
-        }
-
         @Override
         public void set(double value) {
             throw unsupported();
@@ -334,24 +128,6 @@ public class ArrayRealVectorTest extends
         public boolean isInfinite() {
             throw unsupported();
         }
-
-        public RealVector combine(double a, double b, double[] y) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector combine(double a, double b, RealVector y) {
-            throw unsupported();
-        }
-
-        public RealVector combineToSelf(double a, double b, double[] y) {
-            throw unsupported();
-        }
-
-        @Override
-        public RealVector combineToSelf(double a, double b, RealVector y) {
-            throw unsupported();
-        }
     }
 
     @Override
@@ -360,7 +136,7 @@ public class ArrayRealVectorTest extends
     }
 
     @Override
-    public RealVector createAlien(double[] data) {
+    public RealVector createAlien(final double[] data) {
         return new RealVectorTestImpl(data);
     }
 



Mime
View raw message