public void testGetCoordinatesBetween() {

    try {
      // what if the null value is passed
      CoordinateSequence[] cs = nullLine.getCoordinatesBetween(0.0, 5.0);
      assertTrue("cs.length = " + cs.length + ". Should be 1", cs.length == 1);
      assertEquals(cs[0].size(), 0);

      arbitraryLine.measureOnLength(false);
      // what if from/to is outside of the range of values
      double maxM = arbitraryLine.getMaxM();
      cs = arbitraryLine.getCoordinatesBetween(maxM + 1.0, maxM + 10.0);

      // check for several ascending M-values
      int minIdx = (int) (Math.random() * (arbitraryLine.getNumPoints() - 1));
      int maxIdx = Math.min((arbitraryLine.getNumPoints() - 1), minIdx + 10);
      double minM = ((MCoordinate) arbitraryLine.getCoordinateN(minIdx)).m;
      maxM = ((MCoordinate) arbitraryLine.getCoordinateN(maxIdx)).m;
      cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
      assertNotNull(cs);
      assertTrue(cs.length > 0);
      Coordinate[] coar = cs[0].toCoordinateArray();
      int j = 0;
      for (int i = minIdx; i <= maxIdx; i++) {
        assertEquals((MCoordinate) arbitraryLine.getCoordinateN(i), coar[j]);
        j++;
      }

      minM = Math.max(0.0, minM - Math.random() * 10);
      cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
      coar = cs[0].toCoordinateArray();
      MCoordinate mctest = (MCoordinate) coar[0];
      MCoordinate mcexp = (MCoordinate) arbitraryLine.getCoordinateAtM(minM);
      assertEquals(mcexp, mctest);
      assertEquals(mctest.m, minM, DoubleComparator.defaultNumericalPrecision());

      maxM = Math.min(arbitraryLine.getLength(), maxM + Math.random() * 10);
      cs = arbitraryLine.getCoordinatesBetween(minM, maxM);
      coar = cs[0].toCoordinateArray();
      mctest = (MCoordinate) coar[coar.length - 1];
      mcexp = (MCoordinate) arbitraryLine.getCoordinateAtM(maxM);
      assertEquals(mcexp.x, mctest.x, Math.ulp(mcexp.x) * 100);
      assertEquals(mcexp.y, mctest.y, Math.ulp(mcexp.y) * 100);
      assertEquals(mctest.m, maxM, DoubleComparator.defaultNumericalPrecision());

    } catch (Exception e) {
      e.printStackTrace();
      assertTrue(false); // should never reach here
    }
  }
  public void testGetCoordinateAtM() {
    // what if null string
    try {
      Coordinate mc = nullLine.getCoordinateAtM(2);
      assertNull(mc);

      // get two neighbouring points along the arbitraryline
      arbitraryLine.measureOnLength(false);
      int elem1Indx = (int) (Math.random() * (arbitraryLine.getNumPoints() - 1));
      int elem2Indx = 0;
      if (elem1Indx == arbitraryLine.getNumPoints() - 1) {
        elem2Indx = elem1Indx - 1;
      } else {
        elem2Indx = elem1Indx + 1;
      }

      // if m is value of a coordinate, the returned coordinate should
      // equal that coordinate

      MCoordinate mco1 = (MCoordinate) arbitraryLine.getCoordinateN(elem1Indx);
      MCoordinate mcotest = (MCoordinate) arbitraryLine.getCoordinateAtM(mco1.m);
      assertNotSame(mco1, mcotest);
      assertEquals(mco1.x, mcotest.x, Math.ulp(100 * mco1.x));
      assertEquals(mco1.y, mcotest.y, Math.ulp(100 * mco1.y));
      assertEquals(mco1.m, mcotest.m, Math.ulp(100 * mco1.m));

      MCoordinate mco2 = (MCoordinate) arbitraryLine.getCoordinateN(elem2Indx);
      double offset = Math.random();
      double newM = mco1.m + offset * (mco2.m - mco1.m);
      MCoordinate mcexp =
          new MCoordinate(
              mco1.x + offset * (mco2.x - mco1.x),
              mco1.y + offset * (mco2.y - mco1.y),
              Double.NaN,
              mco1.m + offset * (mco2.m - mco1.m));
      MCoordinate mctest = (MCoordinate) arbitraryLine.getCoordinateAtM(newM);
      assertEquals(mcexp.x, mctest.x, 0.0001);
      assertEquals(mcexp.y, mctest.y, 0.0001);
      assertEquals(mcexp.m, mctest.m, 0.0001);

    } catch (Exception e) {
      System.err.println(e);
    }
  }