diff --git a/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java b/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java index 63210cf..452ad18 100644 --- a/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java +++ b/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java @@ -87,6 +87,10 @@ public Double getStandardDeviation() { final IndexedCollection list = collectionStatistics.getList(); final int count = list.size(); + if (count == 0) + { + return null; + } final double average = getAverage(); BigDecimal sd = BigDecimal.valueOf(0); for (long l : list) diff --git a/src/main/java/com/ethlo/util/LongList.java b/src/main/java/com/ethlo/util/LongList.java index 857209f..cee97da 100644 --- a/src/main/java/com/ethlo/util/LongList.java +++ b/src/main/java/com/ethlo/util/LongList.java @@ -93,7 +93,7 @@ public void set(final int index, final Long l) @Override public Iterator iterator() { - return new Iterator() + return new Iterator<>() { private int idx = 0; @@ -143,7 +143,7 @@ public void sort() @Override public Stream stream() { - final Iterable iterable = LongList.this::iterator; + final Iterable iterable = LongList.this; return StreamSupport.stream(iterable.spliterator(), false); } } diff --git a/src/test/java/com/ethlo/time/statistics/ThroughputPerformanceStatisticsTest.java b/src/test/java/com/ethlo/time/statistics/ThroughputPerformanceStatisticsTest.java new file mode 100644 index 0000000..f804d30 --- /dev/null +++ b/src/test/java/com/ethlo/time/statistics/ThroughputPerformanceStatisticsTest.java @@ -0,0 +1,25 @@ +package com.ethlo.time.statistics; + +import com.ethlo.util.IndexedCollection; +import com.ethlo.util.IndexedCollectionStatistics; + +import com.ethlo.util.LongList; + +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +import static org.junit.jupiter.api.Assertions.*; + +class ThroughputPerformanceStatisticsTest +{ + + @Test + void getStandardDeviation() + { + final IndexedCollection list = new LongList(1000); + list.add(123); + final ThroughputPerformanceStatistics stats = new ThroughputPerformanceStatistics(new IndexedCollectionStatistics(list), 5, Duration.ofMillis(456)); + stats.getStandardDeviation(); + } +} \ No newline at end of file