source: trunk/CrossPare/test/de/ugoe/cs/cpdp/preprocessing/LogarithmTranformTest.java @ 87

Last change on this file since 87 was 2, checked in by sherbold, 10 years ago
  • initial commit
  • Property svn:mime-type set to text/plain
File size: 1.8 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.LogarithmTransform;
12
13import weka.core.Attribute;
14import weka.core.DenseInstance;
15import weka.core.Instances;
16
17public 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}
Note: See TracBrowser for help on using the repository browser.