1 package baseCode.dataFilter;
2
3 import baseCode.dataFilter.RowAbsentFilter;
4 import baseCode.dataStructure.matrix.DenseDoubleMatrix2DNamed;
5 import baseCode.dataStructure.matrix.StringMatrix2DNamed;
6 import baseCode.io.reader.StringMatrixReader;
7
8 /***
9 * See the file test/data/matrix-testing.xls for the validation.
10 *
11 * Copyright (c) 2004 Columbia University
12 *
13 * @author Owner
14 * @version $Id: TestRowAbsentFilter.java,v 1.1 2005/03/17 13:58:41 pavlidis Exp $
15 */
16 public class TestRowAbsentFilter extends AbstractTestFilter {
17
18 StringMatrix2DNamed testpdata = null;
19
20 RowAbsentFilter f = null;
21
22
23
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 f = new RowAbsentFilter();
28 StringMatrixReader s = new StringMatrixReader();
29 testpdata = ( StringMatrix2DNamed ) s.read( AbstractTestFilter.class
30 .getResourceAsStream( "/data/test-presence-data.txt" ) );
31 }
32
33
34
35
36 protected void tearDown() throws Exception {
37 testpdata = null;
38 testdata = null;
39 super.tearDown();
40 }
41
42
43
44
45
46 public void testFilter() {
47 f.setFlagMatrix( testpdata );
48 f.setMinPresentCount( 12 );
49 DenseDoubleMatrix2DNamed filtered = ( DenseDoubleMatrix2DNamed ) f
50 .filter( testdata );
51 int expectedReturn = testdata.rows() - 7;
52
53 int actualReturn = filtered.rows();
54 assertEquals( "return value", expectedReturn, actualReturn );
55 }
56
57 public void testFilterWithMissing() {
58 f.setFlagMatrix( testpdata );
59 f.setMinPresentCount( 12 );
60 DenseDoubleMatrix2DNamed filtered = ( DenseDoubleMatrix2DNamed ) f
61 .filter( testmissingdata );
62 int expectedReturn = 17;
63 int actualReturn = filtered.rows();
64 assertEquals( "return value", expectedReturn, actualReturn );
65 }
66
67 public void testFilterWithMissingLessStringent() {
68 f.setFlagMatrix( testpdata );
69 f.setMinPresentCount( 8 );
70 DenseDoubleMatrix2DNamed filtered = ( DenseDoubleMatrix2DNamed ) f
71 .filter( testmissingdata );
72 int expectedReturn = 24;
73 int actualReturn = filtered.rows();
74 assertEquals( "return value", expectedReturn, actualReturn );
75 }
76
77 public void testFilterStringMatrix() {
78 f.setFlagMatrix( testpdata );
79 f.setMinPresentCount( 12 );
80 StringMatrix2DNamed filtered = ( StringMatrix2DNamed ) f
81 .filter( teststringdata );
82 int expectedReturn = testdata.rows() - 7;
83
84 int actualReturn = filtered.rows();
85 assertEquals( "return value", expectedReturn, actualReturn );
86 }
87
88 public void testFilterKeepMarginal() {
89 f.setFlagMatrix( testpdata );
90 f.setKeepMarginal( true );
91 f.setMinPresentCount( 12 );
92 DenseDoubleMatrix2DNamed filtered = ( DenseDoubleMatrix2DNamed ) f
93 .filter( testdata );
94 int expectedReturn = testdata.rows() - 6;
95 int actualReturn = filtered.rows();
96 assertEquals( "return value", expectedReturn, actualReturn );
97 }
98
99 public void testFilterFraction() {
100 f.setFlagMatrix( testpdata );
101 f.setMinPresentFraction( 1.0 );
102 DenseDoubleMatrix2DNamed filtered = ( DenseDoubleMatrix2DNamed ) f
103 .filter( testdata );
104 int expectedReturn = testdata.rows() - 7;
105
106 int actualReturn = filtered.rows();
107 assertEquals( "return value", expectedReturn, actualReturn );
108 }
109
110 public void testFilterFractionInvalid() {
111 try {
112 f.setFlagMatrix( testpdata );
113 f.setMinPresentFraction( 934109821 );
114 f.filter( testdata );
115 fail( "Should have gotten an exception" );
116 } catch ( IllegalArgumentException e ) {
117 System.err.println(e);
118 }
119
120 }
121
122 public void testFilterPresentCountInvalid() {
123 try {
124 f.setFlagMatrix( testpdata );
125 f.setMinPresentCount( 129 );
126 f.filter( testdata );
127 fail( "Should have gotten an exception" );
128 } catch ( IllegalStateException e ) {
129 System.err.println(e);
130 }
131
132 }
133
134 public void testFilterNullFlags() {
135 try {
136 f.setFlagMatrix( null );
137 f.setMinPresentCount( 10 );
138 f.filter( testdata );
139 fail( "Should have gotten an exception" );
140 } catch ( IllegalStateException success ) {
141 System.err.println(success);
142 } catch ( IllegalArgumentException success ) {
143 System.err.println(success);
144 }
145 }
146
147 }