1 | /* |
---|
2 | * This program is free software; you can redistribute it and/or modify |
---|
3 | * it under the terms of the GNU General Public License as published by |
---|
4 | * the Free Software Foundation; either version 2 of the License, or |
---|
5 | * (at your option) any later version. |
---|
6 | * |
---|
7 | * This program is distributed in the hope that it will be useful, |
---|
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | * GNU General Public License for more details. |
---|
11 | * |
---|
12 | * You should have received a copy of the GNU General Public License |
---|
13 | * along with this program; if not, write to the Free Software |
---|
14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * Copyright (C) 2002 University of Waikato |
---|
19 | */ |
---|
20 | |
---|
21 | package weka.filters.unsupervised.instance; |
---|
22 | |
---|
23 | import weka.core.Instances; |
---|
24 | import weka.core.SparseInstance; |
---|
25 | import weka.filters.AbstractFilterTest; |
---|
26 | import weka.filters.Filter; |
---|
27 | |
---|
28 | import junit.framework.Test; |
---|
29 | import junit.framework.TestSuite; |
---|
30 | |
---|
31 | /** |
---|
32 | * Tests SparseToNonSparse. Run from the command line with:<p> |
---|
33 | * java weka.filters.unsupervised.instance.SparseToNonSparseTest |
---|
34 | * |
---|
35 | * @author <a href="mailto:len@reeltwo.com">Len Trigg</a> |
---|
36 | * @version $Revision: 1.3 $ |
---|
37 | */ |
---|
38 | public class SparseToNonSparseTest extends AbstractFilterTest { |
---|
39 | |
---|
40 | public SparseToNonSparseTest(String name) { super(name); } |
---|
41 | |
---|
42 | /** Creates an example SparseToNonSparse */ |
---|
43 | public Filter getFilter() { |
---|
44 | SparseToNonSparse f = new SparseToNonSparse(); |
---|
45 | return f; |
---|
46 | } |
---|
47 | |
---|
48 | public void testTypical() { |
---|
49 | Instances result = useFilter(); |
---|
50 | // Number of attributes and instances shouldn't change |
---|
51 | assertEquals(m_Instances.numAttributes(), result.numAttributes()); |
---|
52 | assertEquals(m_Instances.numInstances(), result.numInstances()); |
---|
53 | // Check conversion is OK |
---|
54 | for (int i = 0; i < result.numInstances(); i++) { |
---|
55 | assertTrue("Instance should not be an instanceof SparseInstance:" + (i + 1), |
---|
56 | !(result.instance(i) instanceof SparseInstance)); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | public static Test suite() { |
---|
62 | return new TestSuite(SparseToNonSparseTest.class); |
---|
63 | } |
---|
64 | |
---|
65 | public static void main(String[] args){ |
---|
66 | junit.textui.TestRunner.run(suite()); |
---|
67 | } |
---|
68 | |
---|
69 | } |
---|