public void testGetUpstreamPathLength() {
    XPDFComponentCylinder cap = new XPDFComponentCylinder();
    cap.setDistances(0.15, 0.16);
    cap.setStreamality(true, true);

    final int xSize = 64, ySize = 64;
    Dataset pathLengthExp = new DoubleDataset(xSize, ySize);
    Dataset pathLength = new DoubleDataset(pathLengthExp);
    Dataset r = new DoubleDataset(pathLengthExp);
    Dataset xi = new DoubleDataset(pathLengthExp);

    // Read the data from file
    String fileDirectory = "/home/rkl37156/ceria_dean_data/";
    Dataset[] datasets = {pathLengthExp, r, xi};
    String[] files = {"incoming", "sample_r", "sample_xi"};

    for (int k = 0; k < 3; k++) {

      Path filePath = new File(fileDirectory + files[k] + ".txt").toPath();
      List<String> filelines = new ArrayList<String>();
      try {
        filelines = Files.readAllLines(filePath);
      } catch (Exception e) {
        fail("Error reading " + filePath.toString());
      }
      for (int i = 0; i < ySize; i++) {
        String[] splitline = filelines.get(i).split(" ");
        for (int j = 0; j < xSize; j++) {
          double assignee = Double.parseDouble(splitline[j]);
          datasets[k].set(assignee, i, j);
        }
      }
    }
    Dataset x = Maths.multiply(r, Maths.sin(xi));
    Dataset z = Maths.multiply(r, Maths.cos(xi));
    Dataset y = DoubleDataset.zeros(x);
    pathLength = cap.getUpstreamPathLength(x, y, z);

    double rmsError =
        Math.sqrt((Double) Maths.square(Maths.subtract(pathLength, pathLengthExp)).mean());
    assertTrue("Error in upstream path length too large", rmsError < 1e-6);
    // fail("Not yet implemented");
  }
  public void testGetDownstreamPathLength() {
    XPDFComponentCylinder cap = new XPDFComponentCylinder();
    cap.setDistances(0.15, 0.16);
    cap.setStreamality(true, true);

    final int xSize = 64, ySize = 64;
    Dataset pathLengthExp = new DoubleDataset(xSize, ySize);
    Dataset pathLength = new DoubleDataset(pathLengthExp);
    Dataset r = new DoubleDataset(xSize, ySize);
    Dataset xi = new DoubleDataset(r);

    String[] angles = {"0.0", "15.0", "28.5", "29.5", "47.0"};
    int nAngles = angles.length;

    for (String angle : angles) {

      // Read the data from file
      String fileDirectory = "/home/rkl37156/ceria_dean_data/";
      Dataset[] datasets = {pathLengthExp, r, xi};
      String[] files = {"outgoing" + angle, "sample_r", "sample_xi"};

      for (int k = 0; k < 3; k++) {

        Path filePath = new File(fileDirectory + files[k] + ".txt").toPath();
        List<String> filelines = new ArrayList<String>();
        try {
          filelines = Files.readAllLines(filePath);
        } catch (Exception e) {
          fail("Error reading " + filePath.toString());
        }
        for (int i = 0; i < ySize; i++) {
          String[] splitline = filelines.get(i).split(" ");
          for (int j = 0; j < xSize; j++) {
            double assignee = Double.parseDouble(splitline[j]);
            datasets[k].set(assignee, i, j);
          }
        }
      }

      Dataset x = Maths.multiply(r, Maths.sin(xi));
      Dataset z = Maths.multiply(r, Maths.cos(xi));
      Dataset y = DoubleDataset.zeros(x);
      pathLength =
          cap.getDownstreamPathLength(x, y, z, 0.0, Math.toRadians(Double.parseDouble(angle)));

      // TODO: remove temporary write command
      try (Writer fileWriter =
          new BufferedWriter(
              new OutputStreamWriter(
                  new FileOutputStream(
                      "/home/rkl37156/ceria_dean_data/outgoing" + angle + ".java.txt"),
                  "utf-8"))) {
        for (int i = 0; i < ySize; i++) {
          for (int j = 0; j < xSize; j++) {
            fileWriter.write(((Double) pathLength.getDouble(i, j)).toString() + " ");
          }
          fileWriter.write(13); // Carriage return
        }
      } catch (Exception e) {;
      }

      double rmsError =
          Math.sqrt((Double) Maths.square(Maths.subtract(pathLength, pathLengthExp)).mean());
      assertTrue(
          "Error in downstream path length at " + angle + " too large: " + rmsError,
          rmsError < 1e-6);
    }
  }