From 56f696a86aea0c3fd8111870a6184d459a852ace Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Tue, 20 Jun 2017 17:58:30 +0100 Subject: [PATCH] create method to test HMM model as string --- test/jalview/io/HMMFileTest.java | 61 ++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/test/jalview/io/HMMFileTest.java b/test/jalview/io/HMMFileTest.java index 9beaab0..55e3721 100644 --- a/test/jalview/io/HMMFileTest.java +++ b/test/jalview/io/HMMFileTest.java @@ -7,7 +7,6 @@ import jalview.datamodel.HMMNode; import jalview.datamodel.HiddenMarkovModel; import java.io.BufferedReader; -import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; @@ -137,6 +136,7 @@ public class HMMFileTest { FileReader fr = new FileReader(fn3.getDataObject()); BufferedReader br = new BufferedReader(fr); fn3.parseFileProperties(br); + fn3.parseModel(br); // this is for a later test HiddenMarkovModel testHMM = new HiddenMarkovModel(); testHMM = fn3.getHmm(); br.close(); @@ -231,6 +231,7 @@ public class HMMFileTest { assertEquals(testHMM.getMSV(), "-8.5786 0.71858"); assertEquals(testHMM.getForward(), "-3.4823 0.71858"); + } @Test @@ -367,17 +368,10 @@ public class HMMFileTest { scanner2.close(); } - @Test(priority = 2) + @Test(priority = 3) public void testExportFile() throws IOException { - File file = new File(fn3.getDataObject()); - FileReader fr = new FileReader(file); - BufferedReader br = new BufferedReader(fr); - for (int i = 0; i < 23; i++) - { - br.readLine(); - } - fn3.parseModel(br); + fn3.exportFile("H:/WriteFileTest.hmm"); } @@ -406,11 +400,52 @@ public class HMMFileTest { testScanner.close(); } - public moveAheadBy(Scanner scanner, int nodeChange, int indexChange) + @Test(priority = 2) + public void testAppendModel() + { + StringBuilder testBuilder = new StringBuilder(); + fn3.appendModel(testBuilder); + String string = testBuilder.toString(); + assertEquals(findValue(2, 2, 2, string), "4.42225"); + assertEquals(findValue(12, 14, 1, string), "2.79307"); + } + + public String findValue(int symbolIndex, int nodeIndex, int line, + String model) { - for (int y = 0; y < nodeChange; y++) + + String value = ""; + Scanner scanner = new Scanner(model); + scanner.nextLine(); + scanner.nextLine(); + + for (int lineIndex = 0; lineIndex < line - 1; lineIndex++) + { + scanner.nextLine(); + } + for (int node = 0; node < nodeIndex; node++) { - + scanner.nextLine(); + scanner.nextLine(); + scanner.nextLine(); } + + for (int symbol = 0; symbol < symbolIndex; symbol++) + { + value = scanner.next(); + if ("COMPO".equals(value)) + { + scanner.next(); + } + else if (value.length() < 7) + { + scanner.next(); + } + + } + return value; + } + } + -- 1.7.10.2