SpikeInterpolation { static double getLowerBound(double[] doubles, double val) { double xMin = Double.MAX_VALUE; for (double current : doubles) { xMin = current <= val ? current : xMin; } if (xMin > val) { throw new IllegalArgumentException("Can't find the closest min value of " + val); } return xMin; }    }
@Test public void testClosestToLowerBound() { assertEquals(1.3, SpikeInterpolation.getLowerBound(useAr, 1.4), 1e-8); assertEquals(1.3, SpikeInterpolation.getLowerBound(useAr, 1.5), 1e-8); assertEquals(1.7, SpikeInterpolation.getLowerBound(useAr, 1.9), 1e-8); assertEquals(2.0, SpikeInterpolation.getLowerBound(useAr, 2.1), 1e-8); assertEquals(3, SpikeInterpolation.getLowerBound(useAr, 3), 1e-8); assertEquals(3, SpikeInterpolation.getLowerBound(useAr, 4), 1e-8); assertEquals(3, SpikeInterpolation.getLowerBound(useAr, 30), 1e-8); }
@Test public void testClosestToLowerBoundNotInArray() { try { SpikeInterpolation.getLowerBound(useAr, -3); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }