Skip to content

Commit 45be1f4

Browse files
committed
add test for new removemissing (two methods)
1 parent 4bcbf6b commit 45be1f4

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

test/ubic/basecode/dataStructure/matrix/MatrixUtilTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package ubic.basecode.dataStructure.matrix;
1616

17+
import static org.junit.Assert.assertArrayEquals;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.fail;
1920

@@ -23,14 +24,15 @@
2324
import org.junit.Before;
2425
import org.junit.Test;
2526

27+
import cern.colt.matrix.DoubleMatrix1D;
2628
import cern.colt.matrix.DoubleMatrix2D;
2729
import cern.colt.matrix.impl.DenseDoubleMatrix2D;
2830
import cern.colt.matrix.linalg.Algebra;
2931
import ubic.basecode.io.reader.DoubleMatrixReader;
3032
import ubic.basecode.io.reader.TestDoubleMatrixReader;
3133

3234
/**
33-
* @author Paul
35+
* @author Paul
3436
* @version $Id$
3537
*/
3638
public class MatrixUtilTest {
@@ -85,4 +87,28 @@ public void testSelectRows() {
8587
assertEquals( 3, MatrixUtil.selectRows( testData, Arrays.asList( new Integer[] { 2, 3, 4 } ) ).rows() );
8688
}
8789

90+
@Test
91+
public void testRemoveMissing1() {
92+
DoubleMatrix1D v1 = testData.viewRow( 1 ); // first value is NaN
93+
DoubleMatrix1D actual = MatrixUtil.removeMissing( v1 );
94+
DoubleMatrix1D expected = new DenseDoubleMatrix1D(
95+
new double[] { 172.5, 242.1, -8.8, 148.8, 190.3, 155.1, 205.3, 337.8, 276, -64.2, 295.4 } );
96+
97+
assertArrayEquals( expected.toArray(), actual.toArray(), 0.1 );
98+
99+
}
100+
101+
@Test
102+
public void testRemoveMissing2() {
103+
DoubleMatrix1D v1 = new DenseDoubleMatrix1D( new double[] { 1, 2, Double.NaN, 4, 5 } );
104+
105+
DoubleMatrix1D v2 = new DenseDoubleMatrix1D( new double[] { 11, 12, 13, 14, 15 } );
106+
107+
DoubleMatrix1D actual = MatrixUtil.removeMissing( v1, v2 );
108+
DoubleMatrix1D expected = new DenseDoubleMatrix1D(
109+
new double[] { 11, 12, 14, 15 } );
110+
111+
assertArrayEquals( expected.toArray(), actual.toArray(), 0.1 );
112+
}
113+
88114
}

0 commit comments

Comments
 (0)