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) 2005 University of Waikato, Hamilton, New Zealand |
---|
19 | */ |
---|
20 | |
---|
21 | package weka.filters.unsupervised.attribute; |
---|
22 | |
---|
23 | import weka.core.Instances; |
---|
24 | import weka.filters.AbstractFilterTest; |
---|
25 | import weka.filters.Filter; |
---|
26 | |
---|
27 | import junit.framework.Test; |
---|
28 | import junit.framework.TestSuite; |
---|
29 | |
---|
30 | /** |
---|
31 | * Tests RemoveUseless. Run from the command line with: <p/> |
---|
32 | * java weka.filters.unsupervised.attribute.RemoveUselessTest |
---|
33 | * |
---|
34 | * @author FracPete (fracpete at waikato dot ac dot nz) |
---|
35 | * @version $Revision: 1.2 $ |
---|
36 | */ |
---|
37 | public class RemoveUselessTest |
---|
38 | extends AbstractFilterTest { |
---|
39 | |
---|
40 | public RemoveUselessTest(String name) { |
---|
41 | super(name); |
---|
42 | } |
---|
43 | |
---|
44 | /** Need to remove non-nominal attributes, set class index */ |
---|
45 | protected void setUp() throws Exception { |
---|
46 | super.setUp(); |
---|
47 | |
---|
48 | // class index |
---|
49 | m_Instances.setClassIndex(1); |
---|
50 | } |
---|
51 | |
---|
52 | /** Creates a default RemoveUseless */ |
---|
53 | public Filter getFilter() { |
---|
54 | return getFilter(new RemoveUseless().getMaximumVariancePercentageAllowed()); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * creates a RemoveUseless filter with the given percentage of allowed |
---|
59 | * variance |
---|
60 | */ |
---|
61 | protected Filter getFilter(double percentage) { |
---|
62 | RemoveUseless f = new RemoveUseless(); |
---|
63 | f.setMaximumVariancePercentageAllowed(percentage); |
---|
64 | return f; |
---|
65 | } |
---|
66 | |
---|
67 | public void testNoneRemoved() { |
---|
68 | m_Filter = getFilter(100); |
---|
69 | Instances result = useFilter(); |
---|
70 | assertEquals(m_Instances.numAttributes(), result.numAttributes()); |
---|
71 | assertEquals(m_Instances.numInstances(), result.numInstances()); |
---|
72 | } |
---|
73 | |
---|
74 | public void testSomeRemoved() { |
---|
75 | m_Filter = getFilter(5); |
---|
76 | Instances result = useFilter(); |
---|
77 | assertTrue(m_Instances.numAttributes() > result.numAttributes()); |
---|
78 | assertEquals(m_Instances.numInstances(), result.numInstances()); |
---|
79 | } |
---|
80 | |
---|
81 | public static Test suite() { |
---|
82 | return new TestSuite(RemoveUselessTest.class); |
---|
83 | } |
---|
84 | |
---|
85 | public static void main(String[] args){ |
---|
86 | junit.textui.TestRunner.run(suite()); |
---|
87 | } |
---|
88 | } |
---|