source: trunk/CrossPare/test/de/ugoe/cs/cpdp/preprocessing/MedianAsReferenceTest.java @ 9

Last change on this file since 9 was 2, checked in by sherbold, 10 years ago
  • initial commit
  • Property svn:mime-type set to text/plain
File size: 1.7 KB
Line 
1package de.ugoe.cs.cpdp.preprocessing;
2
3import static org.junit.Assert.*;
4
5import java.util.ArrayList;
6import java.util.LinkedList;
7
8import org.apache.commons.collections4.list.SetUniqueList;
9import org.junit.Test;
10
11import de.ugoe.cs.cpdp.dataprocessing.MedianAsReference;
12
13import weka.core.Attribute;
14import weka.core.DenseInstance;
15import weka.core.Instances;
16
17public class MedianAsReferenceTest {
18
19        @Test
20        public void testSetParameter() {
21                // simple crashstest
22                new MedianAsReference().setParameter("somestring");
23        }
24
25        @Test
26        public void testApply() {
27                ArrayList<Attribute> attributes = new ArrayList<Attribute>();
28                attributes.add(new Attribute("attr1"));
29                attributes.add(new Attribute("class"));
30                attributes.add(new Attribute("attr2"));
31                Instances instances = new Instances("test", attributes, 0);
32                instances.setClassIndex(1);
33               
34                double[] value1 = new double[]{1.5, 0.0,  3.0};
35                double[] value2 = new double[]{1.4, 1.0,  6.0};
36                double[] value3 = new double[]{1.6, 0.0, 15.0};
37               
38                instances.add(new DenseInstance(1.0, value1));
39                instances.add(new DenseInstance(1.0, value2));
40                instances.add(new DenseInstance(1.0, value3));
41               
42                MedianAsReference processor = new MedianAsReference();
43                processor.apply(instances, SetUniqueList.setUniqueList(new LinkedList<Instances>()) );
44               
45                double[] expected1 = new double[]{0.0, 0.0, -3.0};
46                double[] expected2 = new double[]{-0.1,1.0,  0.0};
47                double[] expected3 = new double[]{0.1, 0.0,  9.0};
48                               
49                assertArrayEquals(expected1, instances.instance(0).toDoubleArray(), 0.0001);
50                assertArrayEquals(expected2, instances.instance(1).toDoubleArray(), 0.0001);
51                assertArrayEquals(expected3, instances.instance(2).toDoubleArray(), 0.0001);
52        }
53
54}
Note: See TracBrowser for help on using the repository browser.