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.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1358319 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-07-06 17:59:42 +00:00
parent 12dfb2e92d
commit 092c0972ba

View File

@ -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[];
@ -51,112 +51,17 @@ public class ArrayRealVectorTest extends RealVectorAbstractTest {
return new UnsupportedOperationException("Not supported, unneeded for test purposes");
}
@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();
for (int i = 0; i < data.length; i++) {
data[i] = function.value(data[i]);
}
return this;
}
@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;
}
return new ArrayRealVector(out);
}
@Override
public RealVector mapMultiplyToSelf(double d) {
throw unsupported();
}
@Override
public RealVector mapDivide(double d) {
throw unsupported();
}
@Override
public RealVector mapDivideToSelf(double d) {
throw unsupported();
return new RealVectorTestImpl(data);
}
@Override
@ -164,114 +69,11 @@ public class ArrayRealVectorTest extends RealVectorAbstractTest {
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 RealVectorAbstractTest {
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 RealVectorAbstractTest {
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 RealVectorAbstractTest {
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 RealVectorAbstractTest {
}
@Override
public RealVector createAlien(double[] data) {
public RealVector createAlien(final double[] data) {
return new RealVectorTestImpl(data);
}