TestDataSet.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.data;
00002 
00003 import static org.junit.Assert.*;
00004 
00005 import java.io.BufferedWriter;
00006 import java.io.File;
00007 import java.io.FileWriter;
00008 import java.io.IOException;
00009 import java.util.ArrayList;
00010 
00011 import org.junit.Test;
00012 
00013 import weka.core.Instance;
00014 
00015 public class TestDataSet {
00016 
00017         @Test
00018         public void testConstructor() {
00019                 DataSet ds = new DataSet();
00020                 assertEquals(0, ds.size());
00021         }
00022 
00023         @Test
00024         public void testAdd() {
00025                 DataSet ds = new DataSet();
00026                 assertEquals(0, ds.size());
00027 
00028                 double x1 = 0.5;
00029                 double y1 = -0.5;
00030                 double z1 = 5.5;
00031                 double theta1 = Math.PI / 2.0;
00032                 ds.add(x1, y1, z1, theta1);
00033                 assertEquals(1, ds.size());
00034                 assertEquals(new DataPoint(x1, y1, z1, theta1), ds.get(0));
00035                 double x2 = 0.25;
00036                 double y2 = -0.25;
00037                 double z2 = -5.5;
00038                 double theta2 = Math.PI / 4.0;
00039                 ds.add(x2, y2, z2, theta2);
00040                 assertEquals(2, ds.size());
00041                 assertEquals(new DataPoint(x2, y2, z2, theta2), ds.get(1));
00042         }
00043 
00044         @Test
00045         public void testGetInstances() {
00046                 DataSet ds = new DataSet();
00047                 assertEquals(0, ds.size());
00048 
00049                 double x1 = 0.5;
00050                 double y1 = -0.5;
00051                 double z1 = 5.5;
00052                 double theta1 = Math.PI / 2.0;
00053                 ds.add(x1, y1, z1, theta1);
00054                 assertEquals(1, ds.size());
00055                 assertEquals(DataSet.N, ds.toInstances().numAttributes());
00056                 assertEquals(1, ds.toInstances().numInstances());
00057                 Instance inst1 = ds.toInstances().instance(0);
00058                 assertEquals(DataSet.N, inst1.numAttributes());
00059                 assertEquals(x1, inst1.value(DataSet.X_ATTRIBUTE));
00060                 assertEquals(y1, inst1.value(DataSet.Y_ATTRIBUTE));
00061                 assertEquals(z1, inst1.value(DataSet.Z_ATTRIBUTE));
00062                 assertEquals(theta1, inst1.value(DataSet.THETA_ATTRIBUTE));
00063 
00064                 double x2 = 0.25;
00065                 double y2 = -0.25;
00066                 double z2 = -5.5;
00067                 double theta2 = Math.PI / 4.0;
00068                 ds.add(x2, y2, z2, theta2);
00069                 assertEquals(2, ds.size());
00070                 assertEquals(DataSet.N, ds.toInstances().numAttributes());
00071                 assertEquals(2, ds.toInstances().numInstances());
00072                 Instance inst2 = ds.toInstances().instance(1);
00073                 assertEquals(DataSet.N, inst2.numAttributes());
00074                 assertEquals(x2, inst2.value(DataSet.X_ATTRIBUTE));
00075                 assertEquals(y2, inst2.value(DataSet.Y_ATTRIBUTE));
00076                 assertEquals(z2, inst2.value(DataSet.Z_ATTRIBUTE));
00077                 assertEquals(theta2, inst2.value(DataSet.THETA_ATTRIBUTE));
00078         }
00079 
00080         @Test
00081         public void testGetMinX() {
00082                 DataSet ds = new DataSet();
00083                 assertEquals(Double.POSITIVE_INFINITY, ds.getMinX(), 0);
00084 
00085                 double x1 = 0.5;
00086                 ds.add(x1, 0, 0, 0);
00087                 assertEquals(x1, ds.getMinX(), 0);
00088                 double x2 = 1.5;
00089                 ds.add(x2, 0, 0, 0);
00090                 assertEquals(x1, ds.getMinX(), 0);
00091                 double x3 = -1.5;
00092                 ds.add(x3, 0, 0, 0);
00093                 assertEquals(x3, ds.getMinX(), 0);
00094         }
00095 
00096         @Test
00097         public void testGetMaxX() {
00098                 DataSet ds = new DataSet();
00099                 assertEquals(Double.NEGATIVE_INFINITY, ds.getMaxX(), 0);
00100 
00101                 double x1 = 0.5;
00102                 ds.add(x1, 0, 0, 0);
00103                 assertEquals(x1, ds.getMaxX(), 0);
00104                 double x2 = 1.5;
00105                 ds.add(x2, 0, 0, 0);
00106                 assertEquals(x2, ds.getMaxX(), 0);
00107                 double x3 = -1.5;
00108                 ds.add(x3, 0, 0, 0);
00109                 assertEquals(x2, ds.getMaxX(), 0);
00110         }
00111 
00112         @Test
00113         public void testGetMinY() {
00114                 DataSet ds = new DataSet();
00115                 assertEquals(Double.POSITIVE_INFINITY, ds.getMinY(), 0);
00116 
00117                 double y1 = 0.5;
00118                 ds.add(0, y1, 0, 0);
00119                 assertEquals(y1, ds.getMinY(), 0);
00120                 double y2 = 1.5;
00121                 ds.add(0, y2, 0, 0);
00122                 assertEquals(y1, ds.getMinY(), 0);
00123                 double y3 = -1.5;
00124                 ds.add(0, y3, 0, 0);
00125                 assertEquals(y3, ds.getMinY(), 0);
00126         }
00127 
00128         @Test
00129         public void testGetMaxY() {
00130                 DataSet ds = new DataSet();
00131                 assertEquals(Double.NEGATIVE_INFINITY, ds.getMaxY(), 0);
00132 
00133                 double y1 = 0.5;
00134                 ds.add(0, y1, 0, 0);
00135                 assertEquals(y1, ds.getMaxY(), 0);
00136                 double y2 = 1.5;
00137                 ds.add(0, y2, 0, 0);
00138                 assertEquals(y2, ds.getMaxY(), 0);
00139                 double y3 = -1.5;
00140                 ds.add(0, y3, 0, 0);
00141                 assertEquals(y2, ds.getMaxY(), 0);
00142         }
00143 
00144         @Test
00145         public void testGetMinZ() {
00146                 DataSet ds = new DataSet();
00147                 assertEquals(Double.POSITIVE_INFINITY, ds.getMinZ(), 0);
00148 
00149                 double z1 = 0.5;
00150                 ds.add(0, 0, z1, 0);
00151                 assertEquals(z1, ds.getMinZ(), 0);
00152                 double z2 = 1.5;
00153                 ds.add(0, 0, z2, 0);
00154                 assertEquals(z1, ds.getMinZ(), 0);
00155                 double z3 = -1.5;
00156                 ds.add(0, 0, z3, 0);
00157                 assertEquals(z3, ds.getMinZ(), 0);
00158         }
00159 
00160         @Test
00161         public void testGetMaxZ() {
00162                 DataSet ds = new DataSet();
00163                 assertEquals(Double.NEGATIVE_INFINITY, ds.getMaxZ(), 0);
00164 
00165                 double z1 = 0.5;
00166                 ds.add(0, 0, z1, 0);
00167                 assertEquals(z1, ds.getMaxZ(), 0);
00168                 double z2 = 1.5;
00169                 ds.add(0, 0, z2, 0);
00170                 assertEquals(z2, ds.getMaxZ(), 0);
00171                 double z3 = -1.5;
00172                 ds.add(0, 0, z3, 0);
00173                 assertEquals(z2, ds.getMaxZ(), 0);
00174         }
00175 }


jinteractiveworld
Author(s): Russell Toris
autogenerated on Sun Dec 14 2014 11:27:03