Clean up linear serialization tests

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@780521 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
William Barker 2009-05-31 22:18:18 +00:00
parent 5881224dcf
commit 6fecb32ad6
8 changed files with 27 additions and 141 deletions

View File

@ -1252,25 +1252,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
@SuppressWarnings("unchecked")
public void testSerial() {
try {
File test = File.createTempFile("DFM",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
out.writeObject(m);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
DenseFieldMatrix<Fraction> nm = (DenseFieldMatrix<Fraction>)in.readObject();
in.close();
test.delete();
assertEquals(m,nm);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
private static class SetVisitor extends DefaultFieldMatrixChangingVisitor<Fraction> {

View File

@ -25,6 +25,7 @@ import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.Random;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.linear.decomposition.LUDecompositionImpl;
import org.apache.commons.math.linear.decomposition.NonSquareMatrixException;
@ -1163,23 +1164,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSerial() {
try {
File test = File.createTempFile("DRM",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
DenseRealMatrix m = new DenseRealMatrix(testData);
out.writeObject(m);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
DenseRealMatrix nm = (DenseRealMatrix)in.readObject();
in.close();
test.delete();
assertEquals(m,nm);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
DenseRealMatrix m = new DenseRealMatrix(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
private static class SetVisitor extends DefaultRealMatrixChangingVisitor {

View File

@ -939,25 +939,9 @@ public final class FieldMatrixImplTest extends TestCase {
}
@SuppressWarnings("unchecked")
public void testSerial() {
try {
File test = File.createTempFile("FMI",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
FieldMatrixImpl<Fraction> m = new FieldMatrixImpl<Fraction>(testData);
out.writeObject(m);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
FieldMatrixImpl<Fraction> nm = (FieldMatrixImpl<Fraction>)in.readObject();
in.close();
test.delete();
assertEquals(m,nm);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
FieldMatrixImpl<Fraction> m = new FieldMatrixImpl<Fraction>(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
private static class SetVisitor extends DefaultFieldMatrixChangingVisitor<Fraction> {

View File

@ -31,6 +31,7 @@ import junit.framework.TestSuite;
import org.apache.commons.math.Field;
import org.apache.commons.math.FieldElement;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.fraction.Fraction;
import org.apache.commons.math.fraction.FractionField;
@ -618,25 +619,9 @@ public class FieldVectorImplTest extends TestCase {
}
@SuppressWarnings("unchecked")
public void testSerial() {
try {
File test = File.createTempFile("FVI",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
FieldVectorImpl<Fraction> v = new FieldVectorImpl<Fraction>(vec1);
out.writeObject(v);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
FieldVectorImpl<Fraction> nv = (FieldVectorImpl<Fraction>)in.readObject();
in.close();
test.delete();
assertEquals(v,nv);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
FieldVectorImpl<Fraction> v = new FieldVectorImpl<Fraction>(vec1);
assertEquals(v,TestUtils.serializeAndRecover(v));
}
/** verifies that two vectors are equals */

View File

@ -942,23 +942,8 @@ public final class RealMatrixImplTest extends TestCase {
}
public void testSerial() {
try {
File test = File.createTempFile("RMI",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
RealMatrixImpl m = new RealMatrixImpl(testData);
out.writeObject(m);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
RealMatrixImpl nm = (RealMatrixImpl)in.readObject();
in.close();
test.delete();
assertEquals(m,nm);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
RealMatrixImpl m = new RealMatrixImpl(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}

View File

@ -23,6 +23,9 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.commons.math.TestUtils;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -1176,23 +1179,8 @@ public class RealVectorImplTest extends TestCase {
}
public void testSerial() {
try {
File test = File.createTempFile("RVI",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
RealVectorImpl v = new RealVectorImpl(new double[] { 0, 1, 2 });
out.writeObject(v);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
RealVectorImpl nv = (RealVectorImpl)in.readObject();
in.close();
test.delete();
assertEquals(v,nv);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
RealVectorImpl v = new RealVectorImpl(new double[] { 0, 1, 2 });
assertEquals(v,TestUtils.serializeAndRecover(v));
}

View File

@ -27,6 +27,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.linear.decomposition.LUDecompositionImpl;
import org.apache.commons.math.linear.decomposition.NonSquareMatrixException;
@ -649,23 +650,8 @@ public final class SparseRealMatrixTest extends TestCase {
}
public void testSerial() {
try {
File test = File.createTempFile("OMRM",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
OpenMapRealMatrix m = createSparseMatrix(testData);
out.writeObject(m);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
OpenMapRealMatrix nm = (OpenMapRealMatrix)in.readObject();
in.close();
test.delete();
assertEquals(m,nm);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
OpenMapRealMatrix m = createSparseMatrix(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
// --------------- -----------------Protected methods

View File

@ -23,6 +23,9 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.commons.math.TestUtils;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -1100,23 +1103,8 @@ public class SparseRealVectorTest extends TestCase {
}
public void testSerial() {
try {
File test = File.createTempFile("OMV",".ser");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(test));
OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
out.writeObject(v);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(test));
OpenMapRealVector nv = (OpenMapRealVector)in.readObject();
in.close();
test.delete();
assertEquals(v,nv);
} catch (IOException e) {
fail("IOException: "+e);
} catch (ClassNotFoundException e) {
fail("Can't happen: "+e);
}
OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
assertEquals(v,TestUtils.serializeAndRecover(v));
}
/** verifies that two vectors are close (sup norm) */