@Test public final void testFromRunInfos() { final SignedResult result1 = makeSignedResult(40, 120); final SignedResult result2 = makeSignedResult(100, 100); final HistoricalCalculation calc3 = makeHistoricalCalc(70); final ImmutableList<HistoricalRunInfo> runInfos = ImmutableList.of( HistoricalRunInfo.signed(result1), HistoricalRunInfo.signed(result2), HistoricalRunInfo.unsigned(calc3)); final int expectedTotal = runInfos.size(); final int expectedSigned = 2; final int expectedFirstRunAvg = 70; final int expectedSignAvg = 110; final UtilizationSummary actualSummary = UtilizationSummary.fromRunInfos(runInfos); /* Behavior & Verification */ assertEquals(expectedTotal, actualSummary.getTotalCount()); assertEquals(expectedSigned, actualSummary.getSignedCount()); assertEquals(expectedFirstRunAvg, actualSummary.getSecondsToFirstRunAverage()); assertEquals(expectedSignAvg, actualSummary.getSecondsToSignAverage()); // Also verify toString() contract. assertThat( actualSummary.toString(), allOf( containsString(Integer.toString(expectedTotal)), containsString(Integer.toString(expectedSigned)), containsString(Integer.toString(expectedFirstRunAvg)), containsString(Integer.toString(expectedSignAvg)))); }
/** * Tests behavior if we pass in an empty collection of HistoricalRunInfos. Definitely an edge * case, but worth testing. */ @Test public final void testNoCalculations() { final ImmutableList<HistoricalRunInfo> runInfos = ImmutableList.of(); final UtilizationSummary actualSummary = UtilizationSummary.fromRunInfos(runInfos); assertEquals(runInfos.size(), actualSummary.getTotalCount()); assertEquals(0, actualSummary.getSignedCount()); assertEquals(-1, actualSummary.getSecondsToFirstRunAverage()); assertEquals(-1, actualSummary.getSecondsToSignAverage()); }