Skip to content

Commit

Permalink
Add guard for deviation -> Infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Haraldsen committed Sep 12, 2024
1 parent 64bfbbb commit 7240712
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public Double getStandardDeviation()
{
final IndexedCollection<Long> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ethlo/util/LongList.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void set(final int index, final Long l)
@Override
public Iterator<Long> iterator()
{
return new Iterator<Long>()
return new Iterator<>()
{
private int idx = 0;

Expand Down Expand Up @@ -143,7 +143,7 @@ public void sort()
@Override
public Stream<Long> stream()
{
final Iterable<Long> iterable = LongList.this::iterator;
final Iterable<Long> iterable = LongList.this;
return StreamSupport.stream(iterable.spliterator(), false);
}
}
Original file line number Diff line number Diff line change
@@ -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<Long> list = new LongList(1000);
list.add(123);
final ThroughputPerformanceStatistics stats = new ThroughputPerformanceStatistics(new IndexedCollectionStatistics(list), 5, Duration.ofMillis(456));
stats.getStandardDeviation();
}
}

0 comments on commit 7240712

Please sign in to comment.