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.supervised.attribute; |
---|
22 | |
---|
23 | import weka.attributeSelection.ASEvaluation; |
---|
24 | import weka.attributeSelection.ASSearch; |
---|
25 | import weka.core.Attribute; |
---|
26 | import weka.core.Instances; |
---|
27 | import weka.filters.AbstractFilterTest; |
---|
28 | import weka.filters.Filter; |
---|
29 | import weka.filters.unsupervised.attribute.RemoveType; |
---|
30 | |
---|
31 | import junit.framework.Test; |
---|
32 | import junit.framework.TestSuite; |
---|
33 | |
---|
34 | /** |
---|
35 | * Tests AttributeSelection. Run from the command line with:<p> |
---|
36 | * java weka.filters.supervised.attribute.AttributeSelectionTest |
---|
37 | * |
---|
38 | * @author <a href="mailto:len@reeltwo.com">Len Trigg</a> |
---|
39 | * @version $Revision: 1.3 $ |
---|
40 | */ |
---|
41 | public class AttributeSelectionTest extends AbstractFilterTest { |
---|
42 | |
---|
43 | public AttributeSelectionTest(String name) { super(name); } |
---|
44 | |
---|
45 | /** Creates a default AttributeSelection */ |
---|
46 | public Filter getFilter() { |
---|
47 | return new AttributeSelection(); |
---|
48 | } |
---|
49 | |
---|
50 | /** Creates a specialized AttributeSelection */ |
---|
51 | public Filter getFilter(ASEvaluation evaluator, ASSearch search) { |
---|
52 | |
---|
53 | AttributeSelection af = new AttributeSelection(); |
---|
54 | if (evaluator != null) { |
---|
55 | af.setEvaluator(evaluator); |
---|
56 | } |
---|
57 | if (search != null) { |
---|
58 | af.setSearch(search); |
---|
59 | } |
---|
60 | return af; |
---|
61 | } |
---|
62 | |
---|
63 | /** Remove string attributes from default fixture instances */ |
---|
64 | protected void setUp() throws Exception { |
---|
65 | |
---|
66 | super.setUp(); |
---|
67 | RemoveType af = new RemoveType(); |
---|
68 | af.setInputFormat(m_Instances); |
---|
69 | m_Instances = Filter.useFilter(m_Instances, af); |
---|
70 | for (int i = 0; i < m_Instances.numAttributes(); i++) { |
---|
71 | assertTrue("Problem with AttributeTypeFilter in setup", |
---|
72 | m_Instances.attribute(i).type() != Attribute.STRING); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | public void testPrincipalComponent() { |
---|
77 | m_Filter = getFilter(new weka.attributeSelection.PrincipalComponents(), |
---|
78 | new weka.attributeSelection.Ranker()); |
---|
79 | Instances result = useFilter(); |
---|
80 | assertTrue(m_Instances.numAttributes() != result.numAttributes()); |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | public static Test suite() { |
---|
85 | return new TestSuite(AttributeSelectionTest.class); |
---|
86 | } |
---|
87 | |
---|
88 | public static void main(String[] args){ |
---|
89 | junit.textui.TestRunner.run(suite()); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|