@Test(expected = IllegalArgumentException.class) public void testFindTempClosestToValueFailOnEmptyList() { double[] temperatureSeries = {}; double tempValue = 5; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); seriesAnalysis.findTempClosestToValue(tempValue); }
@Test public void testFindTempClosestToValue() { double arr[] = {3.0, 10.2, -20.4, -1.0, -5.3, 1.0, -5.1}; TemperatureSeriesAnalysis tsa = new TemperatureSeriesAnalysis(arr); double expected = -5.1; double result = tsa.findTempClosestToValue(-5.2); assertEquals(expected, result, 0.001); }
@Test public void testFindTempClosestToValueArrayWithSeveralEqualSubElementsGreaterElementFirst() { double[] temperatureSeries = {-5.03, 11.11, 5.4, 6.034, -5.03, 52.23, -2.034, -5.93}; double tempValue = -5.48; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = -5.03; double actualResult = seriesAnalysis.findTempClosestToValue(tempValue); assertEquals(expResult, actualResult, epsilon); }
@Test public void testFindTempClosestToValueArrayWithSeveralEqualSubElementsLessElementFirst() { double[] temperatureSeries = {-5.11, -2.035, -5.11, 6.034, 2.03, 5.23, -3.11}; double tempValue = -4.11; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = -3.11; double actualResult = seriesAnalysis.findTempClosestToValue(tempValue); assertEquals(expResult, actualResult, epsilon); }
@Test public void testFindTempClosestToValueArrayWithDiffeentElements() { double[] temperatureSeries = {3.25, -5.03, 6.034, 2.03, 5.23, 1.032, -0.24, -5.032}; double tempValue = 7.11; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 6.034; double actualResult = seriesAnalysis.findTempClosestToValue(tempValue); assertEquals(expResult, actualResult, epsilon); }
@Test public void testFindTempClosestToValueArrayWithElementsGreaterThenTempValue() { double[] temperatureSeries = {3.25, 5.03, 6, 2.03, 5.23}; double tempValue = 1.032; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 2.03; double actualResult = seriesAnalysis.findTempClosestToValue(tempValue); assertEquals(expResult, actualResult, epsilon); }
@Test public void testFindTempClosestToValueArrayWithSingleElement() { double[] temperatureSeries = {3.25}; double tempValue = 4; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 3.25; double actualResult = seriesAnalysis.findTempClosestToValue(tempValue); assertEquals(expResult, actualResult, epsilon); }
@Test(expected = IllegalArgumentException.class) public void testFindTempClosestToValue_onEmptyArray() { double arr[] = {}; TemperatureSeriesAnalysis tsa = new TemperatureSeriesAnalysis(arr); tsa.findTempClosestToValue(-5.2); }