source: branches/MetisMQI/src/test/java/weka/filters/unsupervised/attribute/ReplaceMissingValuesTest.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: 2.8 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) 2002 University of Waikato
19 */
20
21package weka.filters.unsupervised.attribute;
22
23import weka.core.Attribute;
24import weka.core.Instances;
25import weka.filters.AbstractFilterTest;
26import weka.filters.Filter;
27
28import junit.framework.Test;
29import junit.framework.TestSuite;
30
31/**
32 * Tests ReplaceMissingValues. Run from the command line with:<p>
33 * java weka.filters.unsupervised.attribute.ReplaceMissingValuesTest
34 *
35 * @author <a href="mailto:len@reeltwo.com">Len Trigg</a>
36 * @version $Revision: 1.3 $
37 */
38public class ReplaceMissingValuesTest extends AbstractFilterTest {
39 
40  public ReplaceMissingValuesTest(String name) { super(name);  }
41
42  /** Creates a default ReplaceMissingValues */
43  public Filter getFilter() {
44    return new ReplaceMissingValues();
45  }
46
47  public void testTypical() {
48    Instances result = useFilter();
49    // Number of attributes and instances shouldn't change
50    assertEquals(m_Instances.numAttributes(), result.numAttributes());
51    assertEquals(m_Instances.numInstances(), result.numInstances());
52    for (int j = 0; j < m_Instances.numAttributes(); j++) {
53      Attribute inatt = m_Instances.attribute(j);
54      Attribute outatt = result.attribute(j);
55      for (int i = 0; i < m_Instances.numInstances(); i++) {
56        if (m_Instances.attribute(j).isString()) {
57          if (m_Instances.instance(i).isMissing(j)) {
58            assertTrue("Missing values in strings cannot be replaced",
59                   result.instance(i).isMissing(j));
60          } else {
61            assertEquals("String values should not have changed",
62                         inatt.value((int)m_Instances.instance(i).value(j)),
63                         outatt.value((int)result.instance(i).value(j)));
64          }
65        } else {
66          assertTrue("All non-string missing values should have been replaced",
67                 !result.instance(i).isMissing(j));
68        }
69      }
70    }
71  }
72
73  public static Test suite() {
74    return new TestSuite(ReplaceMissingValuesTest.class);
75  }
76
77  public static void main(String[] args){
78    junit.textui.TestRunner.run(suite());
79  }
80
81}
Note: See TracBrowser for help on using the repository browser.