MATH-795: factored out testMinMax().

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1346467 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-06-05 17:01:57 +00:00
parent ce5671bfb0
commit 1d9b3006bf
2 changed files with 24 additions and 25 deletions

View File

@ -506,30 +506,6 @@ public class ArrayRealVectorTest extends RealVectorAbstractTest {
Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension());
}
@Test
public void testMinMax() {
ArrayRealVector v1 = new ArrayRealVector(new double[] { 0, -6, 4, 12, 7 });
Assert.assertEquals(1, v1.getMinIndex());
Assert.assertEquals(-6, v1.getMinValue(), 1.0e-12);
Assert.assertEquals(3, v1.getMaxIndex());
Assert.assertEquals(12, v1.getMaxValue(), 1.0e-12);
ArrayRealVector v2 = new ArrayRealVector(new double[] { Double.NaN, 3, Double.NaN, -2 });
Assert.assertEquals(3, v2.getMinIndex());
Assert.assertEquals(-2, v2.getMinValue(), 1.0e-12);
Assert.assertEquals(1, v2.getMaxIndex());
Assert.assertEquals(3, v2.getMaxValue(), 1.0e-12);
ArrayRealVector v3 = new ArrayRealVector(new double[] { Double.NaN, Double.NaN });
Assert.assertEquals(-1, v3.getMinIndex());
Assert.assertTrue(Double.isNaN(v3.getMinValue()));
Assert.assertEquals(-1, v3.getMaxIndex());
Assert.assertTrue(Double.isNaN(v3.getMaxValue()));
ArrayRealVector v4 = new ArrayRealVector(new double[0]);
Assert.assertEquals(-1, v4.getMinIndex());
Assert.assertTrue(Double.isNaN(v4.getMinValue()));
Assert.assertEquals(-1, v4.getMaxIndex());
Assert.assertTrue(Double.isNaN(v4.getMaxValue()));
}
@Test
public void testCosine() {
final ArrayRealVector v = new ArrayRealVector(new double[] {1, 0, 0});

View File

@ -752,7 +752,6 @@ public abstract class RealVectorAbstractTest {
Assert.assertEquals(v,TestUtils.serializeAndRecover(v));
}
@Test
public void testAddToEntry() {
final double[] v = new double[] { 1, 2, 3 };
@ -766,6 +765,30 @@ public abstract class RealVectorAbstractTest {
}
}
@Test
public void testMinMax() {
final RealVector v1 = create(new double[] {0, -6, 4, 12, 7});
Assert.assertEquals(1, v1.getMinIndex());
Assert.assertEquals(-6, v1.getMinValue(), 1.0e-12);
Assert.assertEquals(3, v1.getMaxIndex());
Assert.assertEquals(12, v1.getMaxValue(), 1.0e-12);
final RealVector v2 = create(new double[] {Double.NaN, 3, Double.NaN, -2});
Assert.assertEquals(3, v2.getMinIndex());
Assert.assertEquals(-2, v2.getMinValue(), 1.0e-12);
Assert.assertEquals(1, v2.getMaxIndex());
Assert.assertEquals(3, v2.getMaxValue(), 1.0e-12);
final RealVector v3 = create(new double[] {Double.NaN, Double.NaN});
Assert.assertEquals(-1, v3.getMinIndex());
Assert.assertTrue(Double.isNaN(v3.getMinValue()));
Assert.assertEquals(-1, v3.getMaxIndex());
Assert.assertTrue(Double.isNaN(v3.getMaxValue()));
final RealVector v4 = create(new double[0]);
Assert.assertEquals(-1, v4.getMinIndex());
Assert.assertTrue(Double.isNaN(v4.getMinValue()));
Assert.assertEquals(-1, v4.getMaxIndex());
Assert.assertTrue(Double.isNaN(v4.getMaxValue()));
}
/*
* TESTS OF THE VISITOR PATTERN
*/