JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
MathObjectReaderTest.java
Go to the documentation of this file.
1 package jarmos.test;
2 
3 import static org.junit.Assert.assertTrue;
4 import static org.junit.Assert.fail;
5 import jarmos.MathFactory;
6 import jarmos.Util;
8 
9 import org.apache.commons.math.linear.RealMatrix;
10 import org.apache.commons.math.linear.RealVector;
11 import org.junit.Test;
12 
17 public class MathObjectReaderTest {
18 
22  @Test
23  public void testReadMatrixString() {
24 
25  // FileModelManager f = new FileModelManager(new File(".").getAbsolutePath());
26  // try {
27  // f.setModelDir("test");
28  // } catch (ModelManagerException e1) {
29  // fail(e1.getMessage());
30  // e1.printStackTrace();
31  // }
32  // f.fileExists("test.bin");
33 
34  MathObjectReader rd = new MathObjectReader();
35 
36  RealMatrix m = null;
37  try {
38  m = rd.readMatrix("./test/test.bin");
39  } catch (Exception e) {
40  fail(e.getMessage());
41  }
42 
43  RealMatrix truth = MathFactory.createRealMatrix(new double[][] { new double[] { .5, 1.5 },
44  new double[] { 2.0, 1.0 } });
45  assertTrue(truth.equals(m));
46 
47  try {
48  m = rd.readMatrix("./test/test2.bin");
49  } catch (Exception e) {
50  fail(e.getMessage());
51  }
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));
55  }
56 
60  @Test
61  public void testReadVectorString() {
62  MathObjectReader rd = new MathObjectReader();
63 
64  RealVector v = null;
65  try {
66  v = rd.readVector("./test/testvec.bin");
67  } catch (Exception e) {
68  fail(e.getMessage());
69  }
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));
74  }
75 
76 }
Factory method to create new RealMatrix instances.
Reading matrices and vectors with a bunch of convenient overloads for different sources and output fo...
Utility functions.
Definition: Util.java:15