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:
parent
5881224dcf
commit
6fecb32ad6
|
@ -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> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) */
|
||||
|
|
Loading…
Reference in New Issue