X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FTCoffeeScoreFileTest.java;h=0277884ab9d56c8057544cb5872390de8b2d02b6;hb=47168f025aefdaa044802bd5f8f510ffe43a4808;hp=7257e144fd762488ed14ec25706c28721afc5af1;hpb=a79f9e113c51c032070c670e45ce3eb464691166;p=jalview.git diff --git a/test/jalview/io/TCoffeeScoreFileTest.java b/test/jalview/io/TCoffeeScoreFileTest.java index 7257e14..0277884 100644 --- a/test/jalview/io/TCoffeeScoreFileTest.java +++ b/test/jalview/io/TCoffeeScoreFileTest.java @@ -1,27 +1,56 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io; import static org.junit.Assert.*; import jalview.io.TCoffeeScoreFile.Block; import jalview.io.TCoffeeScoreFile.Header; -import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.io.StringReader; import java.util.List; +import javax.xml.parsers.ParserConfigurationException; + import org.junit.Test; +import org.xml.sax.SAXException; + +import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; +import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed; +import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied; +import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses; public class TCoffeeScoreFileTest { - final static File SCORE_FILE = new File("./test/jalview/io/tcoffee.score_ascii"); + final static File SCORE_FILE = new File("test/jalview/io/tcoffee.score_ascii"); + final static File ALIGN_FILE = new File("test/jalview/io/tcoffee.fasta_aln"); @Test - public void testReadHeader() throws FileNotFoundException { + public void testReadHeader() throws IOException { - Header header = TCoffeeScoreFile.readHeader( new BufferedReader(new FileReader(SCORE_FILE)) ); + TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),AppletFormatAdapter.FILE); + assertTrue(scoreFile.getWarningMessage(),scoreFile.isValid()); + + Header header = scoreFile.header; assertNotNull(header); assertEquals( "T-COFFEE, Version_9.02.r1228 (2012-02-16 18:15:12 - Revision 1228 - Build 336)", header.head ); assertEquals( 90, header.score ); @@ -38,15 +67,21 @@ public class TCoffeeScoreFileTest { @Test - public void testWrongFile() { - TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.fasta_aln")); - assertNull(result); + public void testWrongFile() { + try { + TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(), FormatAdapter.FILE); + assertFalse(result.isValid()); + } + catch (IOException x) + { + assertTrue("File not found exception thrown",x instanceof FileNotFoundException); + } } @Test - public void testHeightAndWidth() { - TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.score_ascii")); - assertNotNull(result); + public void testHeightAndWidth() throws IOException { + TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE); + assertTrue(result.isValid()); assertEquals( 8, result.getHeight() ); assertEquals( 83, result.getWidth() ); } @@ -68,9 +103,10 @@ public class TCoffeeScoreFileTest { "cons 999999999999999999999999999851000110321100001134\n" + "\n" + "\n"; - - Block block = TCoffeeScoreFile.readBlock(new BufferedReader(new StringReader(BLOCK)), 0); - assertNotNull(block); + FileParse source=new FileParse(BLOCK, FormatAdapter.PASTE); + Block block = TCoffeeScoreFile.readBlock(source, 0); + + assertNotNull(block); assertEquals( "999999999999999999999999998762112222543211112134", block.getScoresFor("1PHT") ); assertEquals( "99999999999999999999999999987-------4322----2234", block.getScoresFor("1BB9") ); assertEquals( "99999999999999999999999999987-------5321----2246", block.getScoresFor("1UHC") ); @@ -83,9 +119,9 @@ public class TCoffeeScoreFileTest { } @Test - public void testParse() throws FileNotFoundException { + public void testParse() throws IOException { - TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) ); + TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE); assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", parser.getScoresFor("1PHT") ); assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", parser.getScoresFor("1BB9") ); @@ -100,10 +136,10 @@ public class TCoffeeScoreFileTest { @Test - public void testGetAsList() throws FileNotFoundException { + public void testGetAsList() throws IOException { - TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) ); - + TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE); + assertTrue(parser.getWarningMessage(),parser.isValid()); List scores = parser.getScoresList(); assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", scores.get(0) ); assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", scores.get(1) ); @@ -119,10 +155,10 @@ public class TCoffeeScoreFileTest { @Test - public void testGetAsArray() throws FileNotFoundException { + public void testGetAsArray() throws IOException { - TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) ); - + TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE); + assertTrue(parser.getWarningMessage(),parser.isValid()); byte[][] scores = parser.getScoresArray(); assertEquals( 9, scores[0][0] ); @@ -147,6 +183,15 @@ public class TCoffeeScoreFileTest { } + @Test + public void testHeightAndWidthWithResidueNumbers() throws Exception { + String file = "test/jalview/io/tcoffee.score_ascii_with_residue_numbers"; + TCoffeeScoreFile result = new TCoffeeScoreFile(file, FormatAdapter.FILE); + assertTrue(result.isValid()); + assertEquals( 5, result.getHeight() ); + assertEquals( 84, result.getWidth() ); + } + }