source: trunk/CrossPare/test/de/ugoe/cs/cpdp/preprocessing/AverageStandardizationTest.java @ 2

Last change on this file since 2 was 2, checked in by sherbold, 10 years ago
  • initial commit
  • Property svn:mime-type set to text/plain
File size: 2.2 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.AverageStandardization;
12
13import weka.core.Attribute;
14import weka.core.DenseInstance;
15import weka.core.Instances;
16
17public class AverageStandardizationTest {
18
19        @Test
20        public void testSetParameter() {
21                new AverageStandardization().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                       
31                double[] value1 = new double[]{1.5, 0.0,  3.0};
32                double[] value2 = new double[]{1.4, 1.0,  6.0};
33                double[] value3 = new double[]{1.6, 0.0, 15.0};
34                double[] value4 = new double[]{ 3.0, 0.0, 1.5};
35                double[] value5 = new double[]{ 6.0, 1.0, 1.4 };
36                double[] value6 = new double[]{15.0, 0.0, 1.6};
37               
38                Instances instances = new Instances("test", attributes, 0);
39                instances.setClassIndex(1);
40               
41                instances.add(new DenseInstance(1.0, value1));
42                instances.add(new DenseInstance(1.0, value2));
43                instances.add(new DenseInstance(1.0, value3));
44                               
45                Instances instTest = new Instances("foo", attributes, 0);
46                instTest.add(new DenseInstance(1.0, value4));
47                instTest.add(new DenseInstance(1.0, value5));
48                instTest.add(new DenseInstance(1.0, value6));
49               
50                SetUniqueList<Instances> instSet = SetUniqueList.setUniqueList(new LinkedList<Instances>());
51                instSet.add(instTest);
52               
53                AverageStandardization processor = new AverageStandardization();
54                processor.apply(instances, instSet);
55               
56                double[] expected1 = new double[]{0.5625, 0.0, 8.0};
57                double[] expected2 = new double[]{1.125 , 1.0, 7.466666666666};
58                double[] expected3 = new double[]{2.8125, 0.0, 8.533333333333};
59               
60                assertArrayEquals(expected1, instSet.get(0).instance(0).toDoubleArray(), 0.0001);
61                assertArrayEquals(expected2, instSet.get(0).instance(1).toDoubleArray(), 0.0001);
62                assertArrayEquals(expected3, instSet.get(0).instance(2).toDoubleArray(), 0.0001);
63        }
64
65}
Note: See TracBrowser for help on using the repository browser.