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