1   package baseCode.io.reader;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   
6   import junit.framework.TestCase;
7   import baseCode.dataStructure.matrix.StringMatrix2DNamed;
8   import baseCode.io.reader.StringMatrixReader;
9   
10  /***
11   * 
12   * <p>
13   * Copyright (c) 2004 Columbia University
14   * 
15   * @author pavlidis
16   * @version $Id: TestStringMatrixReader.java,v 1.1 2004/06/23 22:13:21 pavlidis
17   *          Exp $
18   */
19  public class TestStringMatrixReader extends TestCase {
20  
21     StringMatrix2DNamed matrix = null;
22     InputStream is = null;
23     StringMatrixReader reader = null;
24  
25     /*
26      * @see TestCase#setUp()
27      */
28     protected void setUp() throws Exception {
29        super.setUp();
30        reader = new StringMatrixReader();
31        is = TestStringMatrixReader.class
32              .getResourceAsStream( "/data/testdata.txt" );
33     }
34  
35     /*
36      * @see TestCase#tearDown()
37      */
38     protected void tearDown() throws Exception {
39        super.tearDown();
40     }
41  
42     /*
43      * Class under test for NamedMatrix read(InputStream)
44      */
45     public void testReadInputStreamRowCount() {
46        try {
47           matrix = ( StringMatrix2DNamed ) reader.read( is );
48           int actualReturn = matrix.rows();
49           int expectedReturn = 30;
50           assertEquals( "return value", expectedReturn, actualReturn );
51        } catch ( IOException e ) {
52           e.printStackTrace();
53        }
54     }
55  
56     public void testReadInputStreamColumnCount() {
57        try {
58           matrix = ( StringMatrix2DNamed ) reader.read( is );
59           int actualReturn = matrix.columns();
60           int expectedReturn = 12;
61           assertEquals( "return value", expectedReturn, actualReturn );
62        } catch ( IOException e ) {
63           e.printStackTrace();
64        }
65     }
66  
67     public void testReadInputStreamGotRowName() {
68        try {
69           matrix = ( StringMatrix2DNamed ) reader.read( is );
70           boolean actualReturn = matrix.containsRowName( "gene1_at" )
71                 && matrix.containsRowName( "AFFXgene30_at" );
72           boolean expectedReturn = true;
73           assertEquals( "return value", expectedReturn, actualReturn );
74        } catch ( IOException e ) {
75           e.printStackTrace();
76        }
77     }
78  
79     public void testReadInputStreamGotColName() {
80        try {
81           matrix = ( StringMatrix2DNamed ) reader.read( is );
82           boolean actualReturn = matrix.containsColumnName( "sample1" )
83                 && matrix.containsColumnName( "sample12" );
84           boolean expectedReturn = true;
85           assertEquals( "return value (for sample1 and sample12)",
86                 expectedReturn, actualReturn );
87        } catch ( IOException e ) {
88           e.printStackTrace();
89        }
90     }
91  
92  }