JAL-2416 support roundtrip print/parse of ScoreMatrix
[jalview.git] / test / jalview / analysis / scoremodels / ScoreMatrixTest.java
index 97cb742..002084d 100644 (file)
@@ -1,9 +1,18 @@
 package jalview.analysis.scoremodels;
+
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
+import jalview.io.ScoreMatrixFile;
 import jalview.math.MatrixI;
 
+import java.io.IOException;
+import java.net.MalformedURLException;
+
 import org.testng.annotations.Test;
 
 public class ScoreMatrixTest
@@ -190,4 +199,24 @@ public class ScoreMatrixTest
     // Q.G + I.W + A.C = -2 + -3 + 0 = -5
     assertEquals(pairwise.getValue(2, 3), -5d);
   }
+
+  /**
+   * Test that the result of outputMatrix can be reparsed to give an identical
+   * ScoreMatrix
+   * 
+   * @throws IOException
+   * @throws MalformedURLException
+   */
+  @Test(groups = "Functional")
+  public void testOutputMatrix_roundTrip() throws MalformedURLException,
+          IOException
+  {
+    ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
+    String output = sm.outputMatrix(false);
+    FileParse fp = new FileParse(output, DataSourceType.PASTE);
+    ScoreMatrixFile parser = new ScoreMatrixFile(fp);
+    ScoreMatrix sm2 = parser.parseMatrix();
+    assertNotNull(sm2);
+    assertTrue(sm2.equals(sm));
+  }
 }