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.DenseDoubleMatrix2DNamed;
8 import baseCode.io.reader.DoubleMatrixReader;
9
10 /***
11 *
12 * <p>
13 * Copyright (c) 2004 Columbia University
14 *
15 * @author pavlidis
16 * @version $Id: TestDoubleMatrixReader.java,v 1.2 2004/06/24 17:48:03 pavlidis
17 * Exp $
18 */
19 public class TestDoubleMatrixReader extends TestCase {
20
21 DenseDoubleMatrix2DNamed matrix = null;
22 InputStream is = null;
23 DoubleMatrixReader reader = null;
24 InputStream ism = null;
25 InputStream ismb = null;
26 InputStream isbig = null;
27
28
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 reader = new DoubleMatrixReader();
33 is = TestStringMatrixReader.class
34 .getResourceAsStream( "/data/testdata.txt" );
35
36 ism = TestStringMatrixReader.class
37 .getResourceAsStream( "/data/testdatamissing.txt" );
38
39 ismb = TestStringMatrixReader.class
40 .getResourceAsStream( "/data/testdatamissing-badrows.txt" );
41
42 isbig = TestStringMatrixReader.class
43 .getResourceAsStream( "/data/melanoma_and_sarcomaMAS5.txt" );
44 }
45
46
47
48
49 protected void tearDown() throws Exception {
50 super.tearDown();
51 is.close();
52 ism.close();
53 ismb.close();
54 isbig.close();
55 matrix = null;
56 }
57
58 public void testReadInputStreamMissing() {
59 try {
60 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( ism );
61 int actualReturn = matrix.rows();
62 int expectedReturn = 30;
63 assertEquals( "return value", expectedReturn, actualReturn );
64 } catch ( IOException e ) {
65 e.printStackTrace();
66 }
67 }
68
69 public void testReadInputStreamMissingBad() {
70 try {
71 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( ismb );
72 fail( "Should have gotten an IO error" );
73 } catch ( IOException e ) {
74 }
75 }
76
77
78
79
80 public void testReadInputStreamRowCount() {
81 try {
82 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( is );
83 int actualReturn = matrix.rows();
84 int expectedReturn = 30;
85 assertEquals( "return value", expectedReturn, actualReturn );
86 } catch ( IOException e ) {
87 e.printStackTrace();
88 }
89 }
90
91 public void testReadInputStreamColumnCount() {
92 try {
93 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( is );
94 int actualReturn = matrix.columns();
95 int expectedReturn = 12;
96 assertEquals( "return value", expectedReturn, actualReturn );
97 } catch ( IOException e ) {
98 e.printStackTrace();
99 }
100 }
101
102 public void testReadInputStreamGotRowName() {
103 try {
104 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( is );
105 boolean actualReturn = matrix.containsRowName( "gene1_at" )
106 && matrix.containsRowName( "AFFXgene30_at" );
107 boolean expectedReturn = true;
108 assertEquals( "return value", expectedReturn, actualReturn );
109 } catch ( IOException e ) {
110 e.printStackTrace();
111 }
112 }
113
114 public void testReadInputStreamGotColName() {
115 try {
116 matrix = ( DenseDoubleMatrix2DNamed ) reader.read( is );
117 boolean actualReturn = matrix.containsColumnName( "sample1" )
118 && matrix.containsColumnName( "sample12" );
119 boolean expectedReturn = true;
120 assertEquals( "return value (for sample1 and sample12)",
121 expectedReturn, actualReturn );
122 } catch ( IOException e ) {
123 e.printStackTrace();
124 }
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 }