    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.SparseDoubleMatrix2DNamed;
    8   import baseCode.io.reader.SparseDoubleMatrixReader;
    9   import baseCode.util.RegressionTesting;
    10
    11  /***
    12   *
    13   *
    14   * <hr>
    15   * <p>Copyright (c) 2004 Columbia University
    16   * @author pavlidis
    17   * @version $Id: TestSparseDoubleMatrixReader.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
    18   */
    19  public class TestSparseDoubleMatrixReader extends TestCase {
    20     SparseDoubleMatrix2DNamed matrix = null;
    21     InputStream is = null;
    22     InputStream isa = null;
    23     SparseDoubleMatrixReader reader = null;
    24     /*
    25      * @see TestCase#setUp()
    26      */
    27     protected void setUp() throws Exception {
    28        super.setUp();
    29        reader = new SparseDoubleMatrixReader();
    30        is = TestSparseDoubleMatrixReader.class
    31              .getResourceAsStream( "/data/JW-testmatrix.txt" );
    32        isa = TestSparseDoubleMatrixReader.class
    33        .getResourceAsStream( "/data/adjacencylist-testmatrix.txt" );
    34     }
    35
    36     /*
    37      * Class under test for NamedMatrix read(String)
    38      */
    39     public void testReadStream() {
    40        try {
    41           matrix = ( SparseDoubleMatrix2DNamed ) reader.read ( isa, null );
    42           String actualReturn = matrix.toString();
    43           String expectedReturn = RegressionTesting.readTestResult(TestSparseDoubleMatrixReader.class
    44                 .getResourceAsStream("/data/JW-testoutputSym.txt"));
    45       //    System.err.println("testReadStream\nHere it is:\n" + actualReturn + "\nExpected:\n" + expectedReturn);
    46           assertEquals( "return value", expectedReturn, actualReturn );
    47
    48        } catch ( IOException e ) {
    49           e.printStackTrace();
    50        }
    51
    52     }
    53
    54     public void testReadJW() {
    55        try {
    56           matrix = ( SparseDoubleMatrix2DNamed ) reader.readJW( is );
    57           String actualReturn = matrix.toString();
    58           String expectedReturn = RegressionTesting.readTestResult(TestSparseDoubleMatrixReader.class
    59                 .getResourceAsStream("/data/JW-testoutput.txt"));
    60       //    System.err.println("testReadJW\nHere it is:\n" + actualReturn + "\nExpected:\n" + expectedReturn);
    61           assertEquals( "return value", expectedReturn, actualReturn );
    62         //
    63        } catch ( IOException e ) {
    64           e.printStackTrace();
    65        } catch ( IllegalAccessException e ) {
    66           // TODO Auto-generated catch block
    67           e.printStackTrace();
    68        } catch ( NoSuchFieldException e ) {
    69           // TODO Auto-generated catch block
    70           e.printStackTrace();
    71        }
    72     }
    73
    74  }