|
14 | 14 | */ |
15 | 15 | package ubic.basecode.dataStructure.matrix; |
16 | 16 |
|
| 17 | +import static org.junit.Assert.assertArrayEquals; |
17 | 18 | import static org.junit.Assert.assertEquals; |
18 | 19 | import static org.junit.Assert.fail; |
19 | 20 |
|
|
23 | 24 | import org.junit.Before; |
24 | 25 | import org.junit.Test; |
25 | 26 |
|
| 27 | +import cern.colt.matrix.DoubleMatrix1D; |
26 | 28 | import cern.colt.matrix.DoubleMatrix2D; |
27 | 29 | import cern.colt.matrix.impl.DenseDoubleMatrix2D; |
28 | 30 | import cern.colt.matrix.linalg.Algebra; |
29 | 31 | import ubic.basecode.io.reader.DoubleMatrixReader; |
30 | 32 | import ubic.basecode.io.reader.TestDoubleMatrixReader; |
31 | 33 |
|
32 | 34 | /** |
33 | | - * @author Paul |
| 35 | + * @author Paul |
34 | 36 | * @version $Id$ |
35 | 37 | */ |
36 | 38 | public class MatrixUtilTest { |
@@ -85,4 +87,28 @@ public void testSelectRows() { |
85 | 87 | assertEquals( 3, MatrixUtil.selectRows( testData, Arrays.asList( new Integer[] { 2, 3, 4 } ) ).rows() ); |
86 | 88 | } |
87 | 89 |
|
| 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 | + |
88 | 114 | } |
0 commit comments