cleaned up tests wrt Junit 4

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@816654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-09-18 14:39:18 +00:00
parent 59a0da9c4c
commit 5fbeb731b9
1 changed files with 65 additions and 104 deletions

View File

@ -16,9 +16,7 @@
*/ */
package org.apache.commons.math.analysis.interpolation; package org.apache.commons.math.analysis.interpolation;
import static org.junit.Assert.assertEquals; import org.junit.Assert;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.apache.commons.math.MathException; import org.apache.commons.math.MathException;
import org.junit.Test; import org.junit.Test;
@ -33,8 +31,8 @@ public class LoessInterpolatorTest {
double[] xval = {0.5}; double[] xval = {0.5};
double[] yval = {0.7}; double[] yval = {0.7};
double[] res = new LoessInterpolator().smooth(xval, yval); double[] res = new LoessInterpolator().smooth(xval, yval);
assertEquals(1, res.length); Assert.assertEquals(1, res.length);
assertEquals(0.7, res[0], 0.0); Assert.assertEquals(0.7, res[0], 0.0);
} }
@Test @Test
@ -42,9 +40,9 @@ public class LoessInterpolatorTest {
double[] xval = {0.5, 0.6}; double[] xval = {0.5, 0.6};
double[] yval = {0.7, 0.8}; double[] yval = {0.7, 0.8};
double[] res = new LoessInterpolator().smooth(xval, yval); double[] res = new LoessInterpolator().smooth(xval, yval);
assertEquals(2, res.length); Assert.assertEquals(2, res.length);
assertEquals(0.7, res[0], 0.0); Assert.assertEquals(0.7, res[0], 0.0);
assertEquals(0.8, res[1], 0.0); Assert.assertEquals(0.8, res[1], 0.0);
} }
@Test @Test
@ -53,9 +51,9 @@ public class LoessInterpolatorTest {
double[] yval = {2,4,6,8,10}; double[] yval = {2,4,6,8,10};
LoessInterpolator li = new LoessInterpolator(0.6, 2); LoessInterpolator li = new LoessInterpolator(0.6, 2);
double[] res = li.smooth(xval, yval); double[] res = li.smooth(xval, yval);
assertEquals(5, res.length); Assert.assertEquals(5, res.length);
for(int i = 0; i < 5; ++i) { for(int i = 0; i < 5; ++i) {
assertEquals(yval[i], res[i], 1e-8); Assert.assertEquals(yval[i], res[i], 1e-8);
} }
} }
@ -88,7 +86,7 @@ public class LoessInterpolatorTest {
fitResidualSum += Math.pow(fit - expected, 2); fitResidualSum += Math.pow(fit - expected, 2);
} }
assertTrue(fitResidualSum < noisyResidualSum); Assert.assertTrue(fitResidualSum < noisyResidualSum);
} }
@Test @Test
@ -118,7 +116,7 @@ public class LoessInterpolatorTest {
} }
for(int i = 1; i < variances.length; ++i) { for(int i = 1; i < variances.length; ++i) {
assertTrue(variances[i] < variances[i-1]); Assert.assertTrue(variances[i] < variances[i-1]);
} }
} }
@ -151,111 +149,74 @@ public class LoessInterpolatorTest {
} }
for(int i = 1; i < variances.length; ++i) { for(int i = 1; i < variances.length; ++i) {
assertTrue(variances[i] < variances[i-1]); Assert.assertTrue(variances[i] < variances[i-1]);
} }
} }
@Test @Test(expected=MathException.class)
public void testUnequalSizeArguments() { public void testUnequalSizeArguments() throws MathException {
try { new LoessInterpolator().smooth(new double[] {1,2,3}, new double[] {1,2,3,4});
new LoessInterpolator().smooth(new double[] {1,2,3}, new double[] {1,2,3,4});
fail();
} catch(MathException e) {
// Expected
}
} }
@Test @Test(expected=MathException.class)
public void testEmptyData() { public void testEmptyData() throws MathException {
try { new LoessInterpolator().smooth(new double[] {}, new double[] {});
new LoessInterpolator().smooth(new double[] {}, new double[] {});
fail();
} catch(MathException e) {
// Expected
}
} }
@Test @Test(expected=MathException.class)
public void testNonStrictlyIncreasing() { public void testNonStrictlyIncreasing1() throws MathException {
try { new LoessInterpolator().smooth(new double[] {4,3,1,2}, new double[] {3,4,5,6});
new LoessInterpolator().smooth(new double[] {4,3,1,2}, new double[] {3,4,5,6});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {1,2,2,3}, new double[] {3,4,5,6});
fail();
} catch(MathException e) {
// Expected
}
} }
@Test @Test(expected=MathException.class)
public void testNotAllFiniteReal() { public void testNonStrictlyIncreasing2() throws MathException {
try { new LoessInterpolator().smooth(new double[] {1,2,2,3}, new double[] {3,4,5,6});
new LoessInterpolator().smooth(new double[] {1,2,Double.NaN}, new double[] {3,4,5});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {1,2,Double.POSITIVE_INFINITY}, new double[] {3,4,5});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NaN});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.POSITIVE_INFINITY});
fail();
} catch(MathException e) {
// Expected
}
try {
new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY});
fail();
} catch(MathException e) {
// Expected
}
} }
@Test @Test(expected=MathException.class)
public void testInsufficientBandwidth() { public void testNotAllFiniteReal1() throws MathException {
try { new LoessInterpolator().smooth(new double[] {1,2,Double.NaN}, new double[] {3,4,5});
LoessInterpolator li = new LoessInterpolator(0.1, 3);
li.smooth(new double[] {1,2,3,4,5,6,7,8,9,10,11,12}, new double[] {1,2,3,4,5,6,7,8,9,10,11,12});
fail();
} catch(MathException e) {
// Expected
}
} }
@Test @Test(expected=MathException.class)
public void testCompletelyIncorrectBandwidth() { public void testNotAllFiniteReal2() throws MathException {
try { new LoessInterpolator().smooth(new double[] {1,2,Double.POSITIVE_INFINITY}, new double[] {3,4,5});
new LoessInterpolator(-0.2, 3); }
fail();
} catch(MathException e) { @Test(expected=MathException.class)
// Expected public void testNotAllFiniteReal3() throws MathException {
} new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5});
try { }
new LoessInterpolator(1.1, 3);
fail(); @Test(expected=MathException.class)
} catch(MathException e) { public void testNotAllFiniteReal4() throws MathException {
// Expected new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NaN});
} }
@Test(expected=MathException.class)
public void testNotAllFiniteReal5() throws MathException {
new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.POSITIVE_INFINITY});
}
@Test(expected=MathException.class)
public void testNotAllFiniteReal6() throws MathException {
new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY});
}
@Test(expected=MathException.class)
public void testInsufficientBandwidth() throws MathException {
LoessInterpolator li = new LoessInterpolator(0.1, 3);
li.smooth(new double[] {1,2,3,4,5,6,7,8,9,10,11,12}, new double[] {1,2,3,4,5,6,7,8,9,10,11,12});
}
@Test(expected=MathException.class)
public void testCompletelyIncorrectBandwidth1() throws MathException {
new LoessInterpolator(-0.2, 3);
}
@Test(expected=MathException.class)
public void testCompletelyIncorrectBandwidth2() throws MathException {
new LoessInterpolator(1.1, 3);
} }
private void generateSineData(double[] xval, double[] yval, double xnoise, double ynoise) { private void generateSineData(double[] xval, double[] yval, double xnoise, double ynoise) {