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.SparseRaggedDoubleMatrix2DNamed;
8 import baseCode.io.reader.SparseRaggedDouble2DNamedMatrixReader;
9 import baseCode.util.RegressionTesting;
10
11 /***
12 * <hr>
13 * <p>
14 * Copyright (c) 2004 Columbia University
15 *
16 * @author pavlidis
17 * @version $Id: TestSparseRaggedDouble2DNamedMatrixReader.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
18 */
19 public class TestSparseRaggedDouble2DNamedMatrixReader extends TestCase {
20
21 SparseRaggedDoubleMatrix2DNamed matrix = null;
22 InputStream is = null;
23 SparseRaggedDouble2DNamedMatrixReader reader = null;
24 InputStream isa = null;
25 InputStream isbig = null;
26
27
28
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 reader = new SparseRaggedDouble2DNamedMatrixReader();
33 is = TestSparseRaggedDouble2DNamedMatrixReader.class
34 .getResourceAsStream( "/data/JW-testmatrix.txt" );
35 isa = TestSparseRaggedDouble2DNamedMatrixReader.class
36 .getResourceAsStream( "/data/adjacencylist-testmatrix.txt" );
37 isbig = TestSparseRaggedDouble2DNamedMatrixReader.class
38 .getResourceAsStream( "/data/adjacency_list.7ormore.txt" );
39 }
40
41
42
43
44 public void testReadInputStream() {
45
46 try {
47 matrix = ( SparseRaggedDoubleMatrix2DNamed ) reader.read( is, 1 );
48 String actualReturn = matrix.toString();
49 String expectedReturn = RegressionTesting
50 .readTestResult( TestSparseDoubleMatrixReader.class
51 .getResourceAsStream( "/data/JW-testoutput.txt" ) );
52 assertEquals( "return value", expectedReturn, actualReturn );
53
54 } catch ( IOException e ) {
55 e.printStackTrace();
56 }
57
58 }
59
60
61
62
63 public void testReadStreamAdjList() {
64 try {
65 matrix = ( SparseRaggedDoubleMatrix2DNamed ) reader
66 .readFromAdjList( isa );
67 String actualReturn = matrix.toString();
68 String expectedReturn = RegressionTesting
69 .readTestResult( TestSparseDoubleMatrixReader.class
70 .getResourceAsStream( "/data/JW-testoutputSym.txt" ) );
71 assertEquals( "return value", expectedReturn, actualReturn );
72
73 } catch ( IOException e ) {
74 e.printStackTrace();
75 }
76
77 }
78
79
80
81
82 public void testReadStreamAdjListBig() {
83 try {
84 matrix = ( SparseRaggedDoubleMatrix2DNamed ) reader
85 .readFromAdjList( isbig );
86
87 String actualReturn = matrix.toString();
88
89 String expectedReturn = RegressionTesting
90 .readTestResult( TestSparseDoubleMatrixReader.class
91 .getResourceAsStream( "/data/adjacency_list.7ormore.output.txt" ) );
92
93 assertEquals( "return value", expectedReturn, actualReturn );
94
95 } catch ( IOException e ) {
96 e.printStackTrace();
97 }
98
99 }
100
101 }