[2] | 1 | package de.ugoe.cs.cpdp.dataselection;
|
---|
| 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 weka.core.Attribute;
|
---|
| 12 | import weka.core.DenseInstance;
|
---|
| 13 | import weka.core.Instances;
|
---|
| 14 |
|
---|
| 15 | public 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 | }
|
---|