You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2007/10/26 16:49:24 UTC
svn commit: r588671 -
/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java
Author: luc
Date: Fri Oct 26 07:49:23 2007
New Revision: 588671
URL: http://svn.apache.org/viewvc?rev=588671&view=rev
Log:
improved test coverage
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java?rev=588671&r1=588670&r2=588671&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DummyStepInterpolatorTest.java Fri Oct 26 07:49:23 2007
@@ -70,32 +70,78 @@
}
public void testSerialization()
- throws DerivativeException, IntegratorException,
- IOException, ClassNotFoundException {
+ throws DerivativeException, IntegratorException,
+ IOException, ClassNotFoundException {
- double[] y = { 0.0, 1.0, -2.0 };
- DummyStepInterpolator interpolator = new DummyStepInterpolator(y, true);
- interpolator.storeTime(0);
- interpolator.shift();
- interpolator.storeTime(1);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(interpolator);
-
- assertTrue(bos.size () > 150);
- assertTrue(bos.size () < 250);
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(bis);
- DummyStepInterpolator dsi = (DummyStepInterpolator) ois.readObject();
-
- dsi.setInterpolatedTime(0.5);
- double[] result = dsi.getInterpolatedState();
- for (int i = 0; i < result.length; ++i) {
- assertTrue(Math.abs(result[i] - y[i]) < 1.0e-10);
+ double[] y = { 0.0, 1.0, -2.0 };
+ DummyStepInterpolator interpolator = new DummyStepInterpolator(y, true);
+ interpolator.storeTime(0);
+ interpolator.shift();
+ interpolator.storeTime(1);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(interpolator);
+
+ assertTrue(bos.size () > 150);
+ assertTrue(bos.size () < 250);
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ DummyStepInterpolator dsi = (DummyStepInterpolator) ois.readObject();
+
+ dsi.setInterpolatedTime(0.5);
+ double[] result = dsi.getInterpolatedState();
+ for (int i = 0; i < result.length; ++i) {
+ assertTrue(Math.abs(result[i] - y[i]) < 1.0e-10);
+ }
+
+ }
+
+ public void testSerializationError()
+ throws DerivativeException, IntegratorException,
+ IOException, ClassNotFoundException {
+
+ double[] y = { 0.0, 1.0, -2.0 };
+ ErrorGeneratingInterpolator interpolator =
+ new ErrorGeneratingInterpolator(y, true);
+ interpolator.storeTime(0);
+ interpolator.shift();
+ interpolator.storeTime(1);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(interpolator);
+
+ assertTrue(bos.size () > 250);
+ assertTrue(bos.size () < 300);
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ try {
+ ois.readObject();
+ fail("an exception should have been thrown");
+ } catch (IOException ioe) {
+ // expected behavior
+ assertNull(ioe.getMessage());
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+
+ }
+
+ private static class ErrorGeneratingInterpolator extends DummyStepInterpolator {
+ public ErrorGeneratingInterpolator() {
+ super();
}
-
+ protected ErrorGeneratingInterpolator(double[] y, boolean forward) {
+ super(y, forward);
+ }
+ public void computeInterpolatedState(double theta, double oneMinusThetaH)
+ throws DerivativeException {
+ throw new DerivativeException(null);
+ }
+ private static final long serialVersionUID = 0x3f6ab636f0c93571L;
}
public static Test suite() {