3 import static org.junit.Assert.assertTrue;
4 import static org.junit.Assert.fail;
9 import org.apache.commons.math.linear.RealMatrix;
10 import org.apache.commons.math.linear.RealVector;
11 import org.junit.Test;
17 public class MathObjectReaderTest {
23 public void testReadMatrixString() {
34 MathObjectReader rd =
new MathObjectReader();
38 m = rd.readMatrix(
"./test/test.bin");
39 }
catch (Exception e) {
43 RealMatrix truth = MathFactory.createRealMatrix(
new double[][] {
new double[] { .5, 1.5 },
44 new double[] { 2.0, 1.0 } });
45 assertTrue(truth.equals(m));
48 m = rd.readMatrix(
"./test/test2.bin");
49 }
catch (Exception e) {
52 truth = MathFactory.createRealMatrix(
new double[][] {
new double[] { 0, -.5, 3 },
53 new double[] { 13516.23425666, -13513.336, 100.000001 } });
54 assertTrue(truth.equals(m));
61 public void testReadVectorString() {
62 MathObjectReader rd =
new MathObjectReader();
66 v = rd.readVector(
"./test/testvec.bin");
67 }
catch (Exception e) {
70 RealVector truth = MathFactory.createRealVector(Util.range(.5, .5, 23));
71 System.out.println(truth);
72 System.out.println(v);
73 assertTrue(truth.equals(v));
Factory method to create new RealMatrix instances.
Reading matrices and vectors with a bunch of convenient overloads for different sources and output fo...