SpikeInterpolation { static double getUpperValue(double[] doubles, double val) { double lowestUpper = Double.MAX_VALUE; for (double current : doubles) { if (current >= val && current <= lowestUpper) { lowestUpper = current; } } if (lowestUpper == Double.MAX_VALUE) { throw new IllegalArgumentException("Can't find the closest max value of " + val); } return lowestUpper; }    }
@Test public void testClosestToUpperBound() { assertEquals(1.3, SpikeInterpolation.getUpperValue(useAr, 1.3), 1e-8); assertEquals(2, SpikeInterpolation.getUpperValue(useAr, 1.9), 1e-8); assertEquals(2.9, SpikeInterpolation.getUpperValue(useAr, 2.7), 1e-8); assertEquals(2.9, SpikeInterpolation.getUpperValue(useAr, 2.9), 1e-8); }
@Test public void testClosestToUpperBoundNotInArray() { try { SpikeInterpolation.getUpperValue(useAr, 100); fail("Can fine the closest max value of 100.0"); } catch (IllegalArgumentException e) { } }