source: branches/MetisMQI/src/test/java/weka/filters/unsupervised/attribute/PropositionalToMultiInstanceTest.java

Last change on this file was 29, checked in by gnappo, 15 years ago

Taggata versione per la demo e aggiunto branch.

File size: 3.1 KB
Line 
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) 2006 University of Waikato, Hamilton, New Zealand
19 */
20
21package weka.filters.unsupervised.attribute;
22
23import weka.core.Attribute;
24import weka.core.Instances;
25import weka.core.TestInstances;
26import weka.filters.AbstractFilterTest;
27import weka.filters.Filter;
28
29import junit.framework.Test;
30import junit.framework.TestSuite;
31
32/**
33 * Tests PropositionalToMultiInstance. Run from the command line with: <p/>
34 * java weka.filters.unsupervised.attribute.PropositionalToMultiInstanceTest
35 *
36 * @author FracPete (fracpete at waikato dot ac dot nz)
37 * @version $Revision: 1.3 $
38 */
39public class PropositionalToMultiInstanceTest 
40  extends AbstractFilterTest {
41 
42  public PropositionalToMultiInstanceTest(String name) { 
43    super(name); 
44  }
45
46  /** Creates a default PropositionalToMultiInstance */
47  public Filter getFilter() {
48    return new PropositionalToMultiInstance();
49  }
50
51  /**
52   * Called by JUnit before each test method. This implementation creates
53   * the default filter to test and loads a test set of Instances.
54   *
55   * @throws Exception if an error occurs reading the example instances.
56   */
57  protected void setUp() throws Exception {
58    super.setUp();
59
60    TestInstances test = new TestInstances();
61    test.setNumNominal(2);
62    test.setClassType(Attribute.NOMINAL);
63    test.setNumInstances(400);
64    m_Instances = test.generate();
65  }
66
67  /**
68   * performs a typical test
69   */
70  public void testTypical() {
71    Instances icopy = new Instances(m_Instances);
72    Instances result = useFilter();
73    // # of instances
74    int count = 0;
75    for (int i = 0; i < result.numInstances(); i++)
76      count += result.instance(i).relationalValue(1).numInstances();
77    assertEquals(icopy.numInstances(), count);
78    // # of attributes
79    count =   result.numAttributes() 
80            + result.attribute(1).relation().numAttributes()
81            - 1;
82    assertEquals(icopy.numAttributes(), count);
83  }
84 
85  /**
86   * filter cannot be used in conjunction with the FilteredClassifier, since
87   * it makes no sense creating bags containing only one instance in the
88   * distributionForInstance/classifyInstance methods.
89   */
90  public void testFilteredClassifier() {
91    // nothing
92  }
93
94  public static Test suite() {
95    return new TestSuite(PropositionalToMultiInstanceTest.class);
96  }
97
98  public static void main(String[] args){
99    junit.textui.TestRunner.run(suite());
100  }
101}
Note: See TracBrowser for help on using the repository browser.