public void testBrokenCoordinateCannotBeSet() {
    PointTester[] testers = {
      new TopTester(), new LeftTester(), new BottomTester(), new RightTester()
    };
    GeoBoundingBoxQueryBuilder builder = createTestQueryBuilder();
    builder.setValidationMethod(GeoValidationMethod.STRICT);

    for (PointTester tester : testers) {
      expectThrows(
          IllegalArgumentException.class, () -> tester.invalidateCoordinate(builder, true));
    }
  }
  public void testBrokenCoordinateCanBeSetWithIgnoreMalformed() {
    PointTester[] testers = {
      new TopTester(), new LeftTester(), new BottomTester(), new RightTester()
    };

    GeoBoundingBoxQueryBuilder builder = createTestQueryBuilder();
    builder.setValidationMethod(GeoValidationMethod.IGNORE_MALFORMED);

    for (PointTester tester : testers) {
      tester.invalidateCoordinate(builder, true);
    }
  }
  public void testValidation() {
    PointTester[] testers = {
      new TopTester(), new LeftTester(), new BottomTester(), new RightTester()
    };

    for (PointTester tester : testers) {
      QueryValidationException except = null;

      GeoBoundingBoxQueryBuilder builder = createTestQueryBuilder();
      tester.invalidateCoordinate(builder.setValidationMethod(GeoValidationMethod.COERCE), false);
      except = builder.checkLatLon(true);
      assertNull(
          "Inner post 2.0 validation w/ coerce should ignore invalid "
              + tester.getClass().getName()
              + " coordinate: "
              + tester.invalidCoordinate
              + " ",
          except);

      tester.invalidateCoordinate(builder.setValidationMethod(GeoValidationMethod.COERCE), false);
      except = builder.checkLatLon(false);
      assertNull(
          "Inner pre 2.0 validation w/ coerce should ignore invalid coordinate: "
              + tester.getClass().getName()
              + " coordinate: "
              + tester.invalidCoordinate
              + " ",
          except);

      tester.invalidateCoordinate(builder.setValidationMethod(GeoValidationMethod.STRICT), false);
      except = builder.checkLatLon(true);
      assertNull(
          "Inner pre 2.0 validation w/o coerce should ignore invalid coordinate for old indexes: "
              + tester.getClass().getName()
              + " coordinate: "
              + tester.invalidCoordinate,
          except);

      tester.invalidateCoordinate(builder.setValidationMethod(GeoValidationMethod.STRICT), false);
      except = builder.checkLatLon(false);
      assertNotNull(
          "Inner post 2.0 validation w/o coerce should detect invalid coordinate: "
              + tester.getClass().getName()
              + " coordinate: "
              + tester.invalidCoordinate,
          except);
    }
  }
예제 #4
0
  public TestSetReader(String fileName, Graph g, String writeFile) {
    int num = 0;
    try {
      FileReader file = new FileReader(fileName);
      Scanner scan = new Scanner(file);
      for (; scan.hasNext(); num++) {
        {
          double[] features = new double[GraphPoint.nrDimensions];
          for (int i = 0; i < Point.nrDimensions; i += 1) {
            String attribute = scan.next();
            features[i] = Double.parseDouble(attribute);
          }
          pointsToTest.add(new GraphPoint(features));
        }
      }
      file.close();
    } catch (IOException ioe) {
      System.out.println("cannot read file " + ioe.getMessage());
    }

    ExecutorService executor = Executors.newCachedThreadPool();
    List<PointTester> testers = new ArrayList<PointTester>();

    for (int i = 0; i < NUM_THREADS; i++) {
      PointTester pt =
          new PointTester(
              g,
              pointsToTest.subList(
                  i * (pointsToTest.size() / NUM_THREADS),
                  (i + 1) * (pointsToTest.size() / NUM_THREADS)));
      testers.add(pt);
      executor.execute(pt);
    }

    try {
      executor.shutdown();
      executor.awaitTermination(10, TimeUnit.HOURS);
    } catch (InterruptedException ex) {
      Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex);
    }

    BufferedWriter out = null;

    try {
      // Create file
      FileWriter fstream = new FileWriter(writeFile);
      out = new BufferedWriter(fstream);
    } catch (Exception ex) {
      System.err.println("Error: " + ex.getMessage());
    }

    for (PointTester t : testers) {
      Iterator<Integer> i1 = t.getResults().iterator();
      while (i1.hasNext()) {
        try {
          int classification = i1.next();
          results.add(classification);
          out.write(classification + "\n");
        } catch (IOException ex) {
          Logger.getLogger(TestSetReader.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }

    try {
      out.close();
    } catch (IOException ex) {
      Logger.getLogger(TestSetReader.class.getName()).log(Level.SEVERE, null, ex);
    }
  }