1 38 39 package org.jfree.data.junit; 40 41 import junit.framework.Test; 42 import junit.framework.TestCase; 43 import junit.framework.TestSuite; 44 45 import org.jfree.data.Regression; 46 import org.jfree.data.XYDataset; 47 import org.jfree.data.XYSeries; 48 import org.jfree.data.XYSeriesCollection; 49 50 55 public class RegressionTests extends TestCase { 56 57 62 public static Test suite() { 63 return new TestSuite(RegressionTests.class); 64 } 65 66 71 public RegressionTests(String name) { 72 super(name); 73 } 74 75 78 public void testOLSRegression1a() { 79 80 double[][] data = createSampleData1(); 81 double[] result1 = Regression.getOLSRegression(data); 82 assertEquals(.25680930, result1[0], 0.0000001); 83 assertEquals(0.72792106, result1[1], 0.0000001); 84 85 } 86 87 91 public void testOLSRegression1b() { 92 93 double[][] data = createSampleData1(); 94 95 XYSeries series = new XYSeries("Test"); 96 for (int i = 0; i < 11; i++) { 97 series.add(data[i][0], data[i][1]); 98 } 99 XYDataset ds = new XYSeriesCollection(series); 100 double[] result2 = Regression.getOLSRegression(ds, 0); 101 102 assertEquals(.25680930, result2[0], 0.0000001); 103 assertEquals(0.72792106, result2[1], 0.0000001); 104 105 } 106 107 110 public void testPowerRegression1a() { 111 112 double[][] data = createSampleData1(); 113 double[] result = Regression.getPowerRegression(data); 114 assertEquals(0.91045813, result[0], 0.0000001); 115 assertEquals(0.88918346, result[1], 0.0000001); 116 117 } 118 119 123 public void testPowerRegression1b() { 124 125 double[][] data = createSampleData1(); 126 127 XYSeries series = new XYSeries("Test"); 128 for (int i = 0; i < 11; i++) { 129 series.add(data[i][0], data[i][1]); 130 } 131 XYDataset ds = new XYSeriesCollection(series); 132 double[] result = Regression.getPowerRegression(ds, 0); 133 134 assertEquals(0.91045813, result[0], 0.0000001); 135 assertEquals(0.88918346, result[1], 0.0000001); 136 137 } 138 139 142 public void testOLSRegression2a() { 143 144 double[][] data = createSampleData2(); 145 double[] result = Regression.getOLSRegression(data); 146 assertEquals(53.9729697, result[0], 0.0000001); 147 assertEquals(-4.1823030, result[1], 0.0000001); 148 149 } 150 151 155 public void testOLSRegression2b() { 156 157 double[][] data = createSampleData2(); 158 159 XYSeries series = new XYSeries("Test"); 160 for (int i = 0; i < 10; i++) { 161 series.add(data[i][0], data[i][1]); 162 } 163 XYDataset ds = new XYSeriesCollection(series); 164 double[] result = Regression.getOLSRegression(ds, 0); 165 166 assertEquals(53.9729697, result[0], 0.0000001); 167 assertEquals(-4.1823030, result[1], 0.0000001); 168 169 } 170 171 174 public void testPowerRegression2a() { 175 176 double[][] data = createSampleData2(); 177 double[] result = Regression.getPowerRegression(data); 178 assertEquals(106.1241681, result[0], 0.0000001); 179 assertEquals(-0.8466615, result[1], 0.0000001); 180 181 } 182 183 187 public void testPowerRegression2b() { 188 189 double[][] data = createSampleData2(); 190 191 XYSeries series = new XYSeries("Test"); 192 for (int i = 0; i < 10; i++) { 193 series.add(data[i][0], data[i][1]); 194 } 195 XYDataset ds = new XYSeriesCollection(series); 196 double[] result = Regression.getPowerRegression(ds, 0); 197 198 assertEquals(106.1241681, result[0], 0.0000001); 199 assertEquals(-0.8466615, result[1], 0.0000001); 200 201 } 202 203 211 private double[][] createSampleData1() { 212 213 double[][] result = new double[11][2]; 214 215 result[0][0] = 2.00; 216 result[0][1] = 1.60; 217 result[1][0] = 2.25; 218 result[1][1] = 2.00; 219 result[2][0] = 2.60; 220 result[2][1] = 1.80; 221 result[3][0] = 2.65; 222 result[3][1] = 2.80; 223 result[4][0] = 2.80; 224 result[4][1] = 2.10; 225 result[5][0] = 3.10; 226 result[5][1] = 2.00; 227 result[6][0] = 2.90; 228 result[6][1] = 2.65; 229 result[7][0] = 3.25; 230 result[7][1] = 2.25; 231 result[8][0] = 3.30; 232 result[8][1] = 2.60; 233 result[9][0] = 3.60; 234 result[9][1] = 3.00; 235 result[10][0] = 3.25; 236 result[10][1] = 3.10; 237 238 return result; 239 240 } 241 242 247 private double[][] createSampleData2() { 248 249 double[][] result = new double[10][2]; 250 251 result[0][0] = 2; 252 result[0][1] = 56.27; 253 result[1][0] = 3; 254 result[1][1] = 41.32; 255 result[2][0] = 4; 256 result[2][1] = 31.45; 257 result[3][0] = 5; 258 result[3][1] = 30.05; 259 result[4][0] = 6; 260 result[4][1] = 24.69; 261 result[5][0] = 7; 262 result[5][1] = 19.78; 263 result[6][0] = 8; 264 result[6][1] = 20.94; 265 result[7][0] = 9; 266 result[7][1] = 16.73; 267 result[8][0] = 10; 268 result[8][1] = 14.21; 269 result[9][0] = 11; 270 result[9][1] = 12.44; 271 272 return result; 273 274 } 275 276 } 277 | Popular Tags |