ManhattanDistance implements IDistanceMetric { @Override public double distance(final double[] a, final double[] b) { RobustnessUtil.sameLengthOrDie(a, b); int n = a.length; double result = 0; for (int i = 0; i < n; i++) { result += Math.abs(a[i] - b[i]); } return result; }  @Override double distance(final double[] a, final double[] b);  }
@Test public void testCorrectnessForDistanceCalculation() { double[] timeSeries1 = { 1, 1, 1, 1, 1, 1 }; double[] timeSeries2 = { 1, 1, 1, 1, 1, 1 }; double expectation = 0; EuclideanDistance md = new EuclideanDistance(); double distance = md.distance(timeSeries1, timeSeries2); assertEquals(expectation, distance, 1.0E-5); }
@Test public void testCorrectnessForDistanceCalculation2() { double[] timeSeries1 = { 0.50, 0.87, 0.90, 0.82, 0.70 }; double[] timeSeries2 = { 0.10, 0.10, 0.10, 0.10, 0.10 }; double expectation = 3.29; ManhattanDistance md = new ManhattanDistance(); double distance = md.distance(timeSeries1, timeSeries2); assertEquals(expectation, distance, 1.0E-5); }