SquaredBackwardDifferenceComplexity implements ITimeSeriesComplexity { @Override public double complexity(final double[] t) { int n = t.length; double sum = .0; for (int i = 0; i < n - 1; i++) { sum += (t[i] - t[i + 1]) * (t[i] - t[i + 1]); } return Math.sqrt(sum); }  @Override double complexity(final double[] t);  }
@Test public void testComplexityCalculation() throws IllegalArgumentException { SquaredBackwardDifferenceComplexity sc = new SquaredBackwardDifferenceComplexity(); double complexity = sc.complexity(timeSeries1); double expectation = 0; String message = "Calculated %f, but %f was expected"; assertEquals(String.format(message, complexity, expectation), expectation, complexity, 0.001); }
@Test public void testComplexityCalculation2() throws IllegalArgumentException { SquaredBackwardDifferenceComplexity sc = new SquaredBackwardDifferenceComplexity(); double complexity = sc.complexity(timeSeries2); double expectation = Math.sqrt(40); String message = "Calculated %f, but %f was expected"; assertEquals(String.format(message, complexity, expectation), expectation, complexity, 0.001); }