()
| 359 | } |
| 360 | |
| 361 | @Test |
| 362 | public void testWriteRead() |
| 363 | { |
| 364 | CategoricalData[] cats = new CategoricalData[] |
| 365 | { |
| 366 | new CategoricalData(2), |
| 367 | new CategoricalData(4), |
| 368 | new CategoricalData(3), |
| 369 | }; |
| 370 | cats[0].setOptionName("A", 0); |
| 371 | cats[0].setOptionName("B", 1); |
| 372 | |
| 373 | |
| 374 | cats[1].setOptionName("a", 0); |
| 375 | cats[1].setOptionName("b", 1); |
| 376 | cats[1].setOptionName("c", 2); |
| 377 | cats[1].setOptionName("d", 3); |
| 378 | |
| 379 | cats[2].setOptionName("hello", 0); |
| 380 | cats[2].setOptionName("hello_world", 1); |
| 381 | cats[2].setOptionName("whats up?", 2); |
| 382 | |
| 383 | |
| 384 | SimpleDataSet truth_data = new SimpleDataSet(cats, 3); |
| 385 | Random rand = RandomUtil.getRandom(); |
| 386 | for (int i = 0; i < 100; i++) |
| 387 | { |
| 388 | DenseVector dv = new DenseVector(3); |
| 389 | int[] vals = new int[3]; |
| 390 | for (int j = 0; j < 3; j++) |
| 391 | { |
| 392 | dv.set(j, rand.nextInt(20)); |
| 393 | vals[j] = rand.nextInt(cats[j].getNumOfCategories()); |
| 394 | } |
| 395 | truth_data.add(new DataPoint(dv, vals, cats)); |
| 396 | } |
| 397 | |
| 398 | for (int lines_to_skip = 0; lines_to_skip < 10; lines_to_skip++) |
| 399 | { |
| 400 | StringBuilder extraLines = new StringBuilder(); |
| 401 | |
| 402 | for(int i = 0; i < lines_to_skip; i++) |
| 403 | { |
| 404 | for(int j = 0; j < rand.nextInt(1000)+1; j++) |
| 405 | extraLines.append(i); |
| 406 | extraLines.append("\n"); |
| 407 | } |
| 408 | |
| 409 | try |
| 410 | { |
| 411 | StringWriter writter = new StringWriter(); |
| 412 | CSV.write(truth_data, writter, ','); |
| 413 | SimpleDataSet simpleIn = CSV.read(new StringReader(extraLines.toString()+writter.toString()), ',', lines_to_skip, '#', new HashSet<Integer>(Arrays.asList(3, 4, 5))); |
| 414 | compareDataSetPoints(truth_data, simpleIn); |
| 415 | |
| 416 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 417 | DataWriter dw = CSV.getWriter(baos, truth_data.getCategories(), truth_data.getNumNumericalVars(), null, DataWriter.DataSetType.SIMPLE, ','); |
| 418 | for(int i = 0; i < truth_data.getSampleSize(); i++) |
nothing calls this directly
no test coverage detected