FillGaps { public static double[] linearInterpolate(double from, double to, int gapsCount) { double[] res = new double[gapsCount + 2]; res[0] = from; res[res.length - 1] = to; double gradient = (to - from) / (gapsCount + 1); for (int i = 1; i < res.length - 1; i++) { res[i] = res[i-1] + gradient; } return res; }  static double[] linearInterpolate(double from, double to, int gapsCount); static double average(double sum, int count);  }
@Test public void testLinearInterpolate() { assertTrue(checkDoubleArrayEquality(FillGaps.linearInterpolate(1,7,5), new double[] {1,2,3,4,5,6,7})); assertTrue(checkDoubleArrayEquality(FillGaps.linearInterpolate(5.7, 25.5, 5), new double[] {5.7, 9, 12.3, 15.6, 18.9, 22.2, 25.5})); assertTrue(checkDoubleArrayEquality(FillGaps.linearInterpolate(6.9, 19.3, 2), new double[] {6.9, 11.033, 15.166, 19.3})); assertTrue(checkDoubleArrayEquality(FillGaps.linearInterpolate(5, 15, 1), new double[] {5, 10, 15})); assertTrue(checkDoubleArrayEquality(FillGaps.linearInterpolate(3, -5, 7), new double[] {3, 2, 1, 0, -1, -2, -3, -4, -5})); }