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.LogarithmTransform;
|
---|
12 |
|
---|
13 | import weka.core.Attribute;
|
---|
14 | import weka.core.DenseInstance;
|
---|
15 | import weka.core.Instances;
|
---|
16 |
|
---|
17 | public class LogarithmTranformTest {
|
---|
18 |
|
---|
19 | @Test
|
---|
20 | public void testSetParameter() {
|
---|
21 | new LogarithmTransform().setParameter("somestring");
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Test
|
---|
25 | public void testApply() {
|
---|
26 | ArrayList<Attribute> attributes = new ArrayList<Attribute>();
|
---|
27 | attributes.add(new Attribute("attr1"));
|
---|
28 | attributes.add(new Attribute("class"));
|
---|
29 | attributes.add(new Attribute("attr2"));
|
---|
30 | Instances instances = new Instances("test", attributes, 0);
|
---|
31 | instances.setClassIndex(1);
|
---|
32 |
|
---|
33 | double[] value1 = new double[]{1.5, 0.0, 3.0};
|
---|
34 | double[] value2 = new double[]{1.4, 1.0, 6.0};
|
---|
35 | double[] value3 = new double[]{1.6, 0.0, 15.0};
|
---|
36 |
|
---|
37 | instances.add(new DenseInstance(1.0, value1));
|
---|
38 | instances.add(new DenseInstance(1.0, value2));
|
---|
39 | instances.add(new DenseInstance(1.0, value3));
|
---|
40 |
|
---|
41 | LogarithmTransform processor = new LogarithmTransform();
|
---|
42 | processor.apply(instances, SetUniqueList.setUniqueList(new LinkedList<Instances>()) );
|
---|
43 |
|
---|
44 | double[] expected1 = new double[]{Math.log(1.5+1), 0.0, Math.log(3.0+1)};
|
---|
45 | double[] expected2 = new double[]{Math.log(1.4+1), 1.0, Math.log(6.0+1)};
|
---|
46 | double[] expected3 = new double[]{Math.log(1.6+1), 0.0, Math.log(15.0+1)};
|
---|
47 |
|
---|
48 | assertArrayEquals(expected1, instances.instance(0).toDoubleArray(), 0.0001);
|
---|
49 | assertArrayEquals(expected2, instances.instance(1).toDoubleArray(), 0.0001);
|
---|
50 | assertArrayEquals(expected3, instances.instance(2).toDoubleArray(), 0.0001);
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|