예제 #1
0
  @Test
  public void testIE_FileWithMoreThan3000Objects() {

    Importer im = new CSVBasedImporter(database, new CSVFileInfoExtractor());
    File oldCSV = new File(RESPATH + "csv_arff_ssd_files/synth_01_copy_with_20000.csv");
    File oldSSD = new File(RESPATH + "csv_arff_ssd_files/20000_objekte_5_subspaces.ssd");
    try {
      if (csv.exists()) csv.delete();
      if (ssd.exists()) ssd.delete();
      if (!csv.exists()) csv.createNewFile();
    } catch (IOException e) {
    }

    try {
      im.importFile(oldCSV, oldSSD);

      SubspaceController sc = new SubspaceController(database);
      GroupController gc = new GroupController(database, sc);
      DataHub hub = new DataHub(database, gc, sc);

      ExportLogic.init(hub, selCon, sc);
      ExportLogic ex = ExportLogic.getInstance();

      ex.exportFile(csv, false);
      if (ssd.exists()) {
        Assert.fail("Something wents wrong.");
      }

    } catch (Throwable t) {
    }

    if (ssd.exists()) {
      Assert.fail("Something wents wrong. There shouldn't be a ssd-file.");
    }

    // Tests exported csv-file.
    boolean succA = true;
    String[] newLine = null;
    String[] oldLine = null;
    try {
      CSVReader oldArffReader = new CSVReader(new FileReader(oldCSV), ',', '\'', 1);
      CSVReader newCSVReader = new CSVReader(new FileReader(csv), ',', '\'', 1);
      do {
        newLine = newCSVReader.readNext();
        oldLine = oldArffReader.readNext();
        if (oldLine == null) break;

        for (int i = 0; i < oldLine.length - 1; ++i) {
          succA &= new Float(Float.parseFloat(newLine[i])).equals(Float.parseFloat(oldLine[i]));
        }

      } while (newLine != null);

      if (oldLine != null) {
        Assert.fail("old and new file have to have the same size");
      }

    } catch (Throwable e) {
    }
    Assert.assertTrue("Old and new file don't have the same data content", succA);
  }
예제 #2
0
  @Test
  public void testExportCSVWithSSD() {

    Importer im = new CSVBasedImporter(database, new ArffFileInfoExtractor());
    File oldArff = new File(RESPATH + "csv_arff_ssd_files/breast.arff");
    File oldSSD = new File(RESPATH + "csv_arff_ssd_files/breast_for_testing.ssd");
    try {
      if (csv.exists()) csv.delete();
      if (!csv.exists()) csv.createNewFile();
    } catch (IOException e) {
    }

    try {
      List<String[]> expected = new CSVReader(new FileReader(oldSSD), ',', '\'', 16).readAll();
      im.importFile(oldArff, oldSSD);

      SubspaceController sc = new SubspaceController(database);
      GroupController gc = new GroupController(database, sc);
      DataHub hub = new DataHub(database, gc, sc);

      ExportLogic.init(hub, selCon, sc);
      ExportLogic ex = ExportLogic.getInstance();

      ex.exportFile(csv, true);
      CSVReader read = new CSVReader(new FileReader(ssd), ';', '\'', 15);
      List<String[]> l = read.readAll();
      if (ssd.exists()) {
        boolean succ = true;
        FileReader expecReader = new FileReader(oldSSD);
        FileReader testReader = new FileReader(ssd);
        for (int i = 0; i <= 13; ++i) {
          succ &= ((expecReader.read()) == (testReader.read()));
        }

        if (expected != null && l != null && expected.size() == l.size()) {
          for (int i = 0; i < l.size(); ++i) {
            for (int j = 0; j < l.get(i).length; ++j) {
              succ &=
                  new Float(Float.parseFloat(expected.get(i)[j]))
                      .equals(Float.parseFloat(l.get(i)[j]));
            }
          }
          Assert.assertTrue(succ);
        } else {
          Assert.fail("Amount of Objects has to be the same");
        }
      } else {
        Assert.fail("Something wents wrong.");
      }

    } catch (Throwable t) {
    }

    // Tests exported csv-file.
    boolean succA = true;
    String[] newLine = null;
    String[] oldLine = null;
    try {
      CSVReader oldArffReader = new CSVReader(new FileReader(oldArff), ',', '\'', 36);
      CSVReader newCSVReader = new CSVReader(new FileReader(csv), ',', '\'', 1);
      do {
        newLine = newCSVReader.readNext();
        oldLine = oldArffReader.readNext();
        if (oldLine == null) break;

        for (int i = 0; i < oldLine.length - 1; ++i) {
          succA &= new Float(Float.parseFloat(newLine[i])).equals(Float.parseFloat(oldLine[i]));
        }
      } while (newLine != null);
      if (oldLine != null) {
        Assert.fail("old and new file have to have the same size");
      }

    } catch (Throwable e) {
    }
    Assert.assertTrue("Old and new file don't have the same data content", succA);
  }