@Test public void testSummaryStatistics() { double arr[] = {3.0, 10.2, -20.4, -1.0, -5.3, 1.0, -5.1}; TemperatureSeriesAnalysis tsa = new TemperatureSeriesAnalysis(arr); TempSummaryStatistics tss = tsa.summaryStatistics(); double average = tsa.average(); assertEquals(average, tss.getAvgTemp(), 0.001); }
@Test public void testAverage() { double arr[] = {-5.5, 0, 10.5, 3}; TemperatureSeriesAnalysis temperatureSeriesAnalysis = new TemperatureSeriesAnalysis(arr); double expected = 2.0; double actual = temperatureSeriesAnalysis.average(); assertEquals(expected, actual, 0.0001); }
@Test public void testAverageCheckForEpsilonError() { double[] temperatureSeries = {1.40215, -5.32102, 4.00012}; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 0.027083; double actualResult = seriesAnalysis.average(); assertEquals(expResult, actualResult, epsilon); }
@Test public void testAverageArrayWithFourElements() { double[] temperatureSeries = {1.0, -5.0, 1.0, 5.0}; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 0.5; double actualResult = seriesAnalysis.average(); assertEquals(expResult, actualResult, epsilon); }
@Test public void testAverageArrayWithPositiveElements() { double[] temperatureSeries = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 4.5; double actualResult = seriesAnalysis.average(); assertEquals(expResult, actualResult, epsilon); }
@Test public void testAverageArrayWithSingleElement() { double[] temperatureSeries = {1.0}; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = 1.0; double actualResult = seriesAnalysis.average(); assertEquals(expResult, actualResult, epsilon); }
@Test public void testAverageArrayWithTenElements() { double[] temperatureSeries = { 11.4, -52.51, 31.0, 25.03, -96.2, 2.5, -12.4, 63.45, -3.235, 1.321 }; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); double expResult = -2.9644; double actualResult = seriesAnalysis.average(); assertEquals(expResult, actualResult, epsilon); }
@Test(expected = IllegalArgumentException.class) public void testAverage_FailOnEmptyList() { double arr[] = {}; TemperatureSeriesAnalysis temperatureSeriesAnalysis = new TemperatureSeriesAnalysis(arr); temperatureSeriesAnalysis.average(); }
@Test(expected = IllegalArgumentException.class) public void testAverageFailOnEmptyArray() { double[] temperatureSeries = {}; TemperatureSeriesAnalysis seriesAnalysis = new TemperatureSeriesAnalysis(temperatureSeries); seriesAnalysis.average(); }