1   package baseCode.dataStructure.matrix;
2   
3   import java.io.InputStream;
4   
5   import junit.framework.TestCase;
6   import baseCode.dataStructure.matrix.RCDoubleMatrix1D;
7   import baseCode.dataStructure.matrix.SparseRaggedDoubleMatrix2DNamed;
8   import baseCode.io.reader.SparseRaggedDouble2DNamedMatrixReader;
9   import baseCode.io.reader.TestSparseDoubleMatrixReader;
10  import cern.colt.list.DoubleArrayList;
11  import cern.colt.matrix.DoubleMatrix1D;
12  
13  /***
14   * <hr>
15   * <p>
16   * Copyright (c) 2004 Columbia University
17   * 
18   * @author pavlidis
19   * @version $Id: TestSparseRaggedDoubleMatrix2DNamed.java,v 1.1 2005/03/17 13:58:43 pavlidis Exp $
20   */
21  public class TestSparseRaggedDoubleMatrix2DNamed extends TestCase {
22     SparseRaggedDoubleMatrix2DNamed matrix = null;
23     InputStream is = null;
24     InputStream isa = null;
25     SparseRaggedDouble2DNamedMatrixReader reader = null;
26  
27     /*
28      * @see TestCase#setUp()
29      */
30     protected void setUp() throws Exception {
31        super.setUp();
32        reader = new SparseRaggedDouble2DNamedMatrixReader();
33        is = TestSparseDoubleMatrixReader.class
34              .getResourceAsStream( "/data/JW-testmatrix.txt" );
35        isa = TestSparseDoubleMatrixReader.class
36              .getResourceAsStream( "/data/adjacencylist-testmatrix.txt" );
37        matrix = ( SparseRaggedDoubleMatrix2DNamed ) reader.read( is , 1);
38     }
39  
40     public void testRows() {
41  
42        int actualReturn = matrix.rows();
43        int expectedReturn = 3;
44  
45        assertEquals( "return value", expectedReturn, actualReturn );
46     }
47  
48     public void testColumns() {
49        int actualReturn = matrix.columns();
50        int expectedReturn = 3;
51        assertEquals( "return value", expectedReturn, actualReturn );
52     }
53  
54  
55     public void testGetRowArrayList() {
56  
57        DoubleArrayList actualReturn = matrix.getRowArrayList( 2 );
58  
59        DoubleArrayList expectedReturn = new DoubleArrayList( new double[] {
60              0.3, 0.8
61        } );
62  
63        assertEquals( "return value", expectedReturn, actualReturn );
64     }
65  
66     //
67     public void testGetRowMatrix1D() {
68  
69        DoubleMatrix1D actualReturn = matrix.viewRow( 2 );
70        DoubleMatrix1D expectedReturn = new RCDoubleMatrix1D( new double[] {
71              0.3, 0.0, 0.8
72        } );
73        assertEquals( "return value", expectedReturn, actualReturn );
74     }
75     
76     /* getRow returns a double[] */
77     public void testGetRow() {
78        DoubleArrayList actualReturn = new DoubleArrayList(matrix.getRow(2));
79        DoubleArrayList  expectedReturn = new DoubleArrayList(new double[] {
80              0.3, 0.0, 0.8
81        });
82        assertEquals( "return value", expectedReturn, actualReturn );
83     }
84     
85  
86  }