source: trunk/CrossPare/test/de/ugoe/cs/cpdp/dataselection/TestAsTrainingTest.java @ 145

Last change on this file since 145 was 2, checked in by sherbold, 10 years ago
  • initial commit
  • Property svn:mime-type set to text/plain
File size: 2.1 KB
Line 
1package de.ugoe.cs.cpdp.dataselection;
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 weka.core.Attribute;
12import weka.core.DenseInstance;
13import weka.core.Instances;
14
15public class TestAsTrainingTest {
16
17        @Test
18        public void testApply() {
19                ArrayList<Attribute> attributes = new ArrayList<Attribute>();
20                attributes.add(new Attribute("attr1"));
21                attributes.add(new Attribute("class"));
22               
23                Instances testdata = new Instances("test", attributes, 0);
24                testdata.setClassIndex(1);
25                testdata.add(new DenseInstance(1.0, new double[]{3.0, 0.0}));
26                testdata.add(new DenseInstance(1.0, new double[]{6.6, 0.0}));
27                testdata.add(new DenseInstance(1.0, new double[]{3.1, 0.0}));
28                               
29                Instances traindata = new Instances("train", attributes, 0);
30                traindata.setClassIndex(1);
31                traindata.add(new DenseInstance(1.0, new double[]{2.9, 0.0}));
32                traindata.add(new DenseInstance(1.0, new double[]{2.8, 0.0}));
33                traindata.add(new DenseInstance(1.0, new double[]{3.2, 0.0}));
34                traindata.add(new DenseInstance(1.0, new double[]{3.05, 0.0}));
35                traindata.add(new DenseInstance(1.0, new double[]{10.0, 0.0}));
36                traindata.add(new DenseInstance(1.0, new double[]{9.0, 0.0}));
37                traindata.add(new DenseInstance(1.0, new double[]{8.0, 0.0}));
38                traindata.add(new DenseInstance(1.0, new double[]{1.0, 0.0}));
39                traindata.add(new DenseInstance(1.0, new double[]{5.0, 0.0}));
40                               
41                SetUniqueList<Instances> traindataSet = SetUniqueList.setUniqueList(new LinkedList<Instances>());
42                traindataSet.add(traindata);
43               
44                TestAsTraining filter = new TestAsTraining();
45                filter.apply(testdata, traindataSet);
46               
47                assertEquals(1, traindataSet.size());
48       
49                traindata = traindataSet.get(0);
50                assertNotSame(testdata, traindata);
51                assertEquals(testdata.numInstances(), traindata.numInstances());
52                for( int i=0; i<testdata.numInstances(); i++ ) {
53                        assertArrayEquals(testdata.instance(i).toDoubleArray(), traindata.instance(i).toDoubleArray(), 0.000000001);
54                }
55        }
56
57}
Note: See TracBrowser for help on using the repository browser.