Skip to content

Commit

Permalink
Improve DoubleStatTest
Browse files Browse the repository at this point in the history
  • Loading branch information
anistor authored and danberindei committed Nov 15, 2016
1 parent 06da111 commit 83b629b
Showing 1 changed file with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.infinispan.objectfilter.impl.aggregation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.junit.Test;
Expand Down Expand Up @@ -30,63 +31,79 @@ public void testSum() throws Exception {
DoubleStat sum = new DoubleStat();
sum.update(10);
sum.update(20);
assertEquals(30.0d, sum.getSum(), DELTA);
Double computedSum = sum.getSum();
assertNotNull(computedSum);
assertEquals(30.0d, computedSum, DELTA);
}

@Test
public void testAvg() throws Exception {
DoubleStat avg = new DoubleStat();
avg.update(10);
avg.update(20);
assertEquals(15.0d, avg.getAvg(), DELTA);
Double computedAvg = avg.getAvg();
assertNotNull(computedAvg);
assertEquals(15.0d, computedAvg, DELTA);
}

@Test
public void testSumWithNaN() throws Exception {
DoubleStat sum = new DoubleStat();
sum.update(10);
sum.update(Double.NaN);
assertEquals(Double.NaN, sum.getSum(), DELTA);
Double computedSum = sum.getSum();
assertNotNull(computedSum);
assertEquals(Double.NaN, computedSum, DELTA);
}

@Test
public void testAvgWithNaN() throws Exception {
DoubleStat avg = new DoubleStat();
avg.update(10);
avg.update(Double.NaN);
assertEquals(Double.NaN, avg.getAvg(), DELTA);
Double computedAvg = avg.getAvg();
assertNotNull(computedAvg);
assertEquals(Double.NaN, computedAvg, DELTA);
}

@Test
public void testSumWithPlusInf() throws Exception {
DoubleStat sum = new DoubleStat();
sum.update(10);
sum.update(Double.POSITIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, sum.getSum(), DELTA);
Double computedSum = sum.getSum();
assertNotNull(computedSum);
assertEquals(Double.POSITIVE_INFINITY, computedSum, DELTA);
}

@Test
public void testAvgWithPlusInf() throws Exception {
DoubleStat avg = new DoubleStat();
avg.update(10);
avg.update(Double.POSITIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, avg.getAvg(), DELTA);
Double computedAvg = avg.getAvg();
assertNotNull(computedAvg);
assertEquals(Double.POSITIVE_INFINITY, computedAvg, DELTA);
}

@Test
public void testSumWithMinusInf() throws Exception {
DoubleStat sum = new DoubleStat();
sum.update(10);
sum.update(Double.NEGATIVE_INFINITY);
assertEquals(Double.NEGATIVE_INFINITY, sum.getSum(), DELTA);
Double computedSum = sum.getSum();
assertNotNull(computedSum);
assertEquals(Double.NEGATIVE_INFINITY, computedSum, DELTA);
}

@Test
public void testAvgWithMinusInf() throws Exception {
DoubleStat avg = new DoubleStat();
avg.update(10);
avg.update(Double.NEGATIVE_INFINITY);
assertEquals(Double.NEGATIVE_INFINITY, avg.getAvg(), DELTA);
Double computedAvg = avg.getAvg();
assertNotNull(computedAvg);
assertEquals(Double.NEGATIVE_INFINITY, computedAvg, DELTA);
}

@Test
Expand All @@ -95,7 +112,9 @@ public void testSumWithMinusInfAndPlusInf() throws Exception {
sum.update(10);
sum.update(Double.NEGATIVE_INFINITY);
sum.update(Double.POSITIVE_INFINITY);
assertEquals(Double.NaN, sum.getSum(), DELTA);
Double computedSum = sum.getSum();
assertNotNull(computedSum);
assertEquals(Double.NaN, computedSum, DELTA);
}

@Test
Expand All @@ -104,6 +123,8 @@ public void testAvgWithMinusInfAndPlusInf() throws Exception {
avg.update(10);
avg.update(Double.NEGATIVE_INFINITY);
avg.update(Double.POSITIVE_INFINITY);
assertEquals(Double.NaN, avg.getAvg(), DELTA);
Double computedAvg = avg.getAvg();
assertNotNull(computedAvg);
assertEquals(Double.NaN, computedAvg, DELTA);
}
}

0 comments on commit 83b629b

Please sign in to comment.