1 | package de.ugoe.cs.cpdp.preprocessing;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.*;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.LinkedList;
|
---|
7 |
|
---|
8 | import org.apache.commons.collections4.list.SetUniqueList;
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | import de.ugoe.cs.cpdp.dataprocessing.MedianAsReference;
|
---|
12 |
|
---|
13 | import weka.core.Attribute;
|
---|
14 | import weka.core.DenseInstance;
|
---|
15 | import weka.core.Instances;
|
---|
16 |
|
---|
17 | public 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 | }
|
---|