You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by kh...@apache.org on 2019/06/02 19:50:16 UTC
[commons-statistics] 03/06: WIP - STATISTICS-14 - Improved.
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch STATISTICS-14
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit cf8a4bc95ea6e16f893d82216c222f1e9538371e
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Jun 2 16:23:35 2019 +0200
WIP - STATISTICS-14 - Improved.
---
.../descriptive/BigDecimalSummaryStatistics.java | 13 ++++---
.../BigDecimalSummaryStatisticsTest.java | 44 +++++++++++++++++++++-
2 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
index a936e63..28a43a1 100644
--- a/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
+++ b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
@@ -17,6 +17,7 @@
package org.apache.commons.statistics.bigdecimal.descriptive;
import java.math.BigDecimal;
+import java.util.DoubleSummaryStatistics;
import java.util.function.Consumer;
/**
@@ -24,6 +25,8 @@ import java.util.function.Consumer;
*/
public class BigDecimalSummaryStatistics implements Consumer<BigDecimal> {
+ private static final BigDecimal INFINITY = BigDecimal.ONE;
+
/**
* internal counter.
*/
@@ -127,7 +130,7 @@ public class BigDecimalSummaryStatistics implements Consumer<BigDecimal> {
throw new IllegalArgumentException("other is not allowed to be null.");
}
- count++;
+ count += other.count;
sum = sum.add(other.sum);
min = min == null ? other.min : min.min(other.min);
@@ -160,21 +163,21 @@ public class BigDecimalSummaryStatistics implements Consumer<BigDecimal> {
*/
public final BigDecimal getMin() {
if (this.count == 0) {
- return BigDecimal.valueOf(Double.NEGATIVE_INFINITY);
+ return BigDecimal.valueOf(Double.POSITIVE_INFINITY);
} else {
return min;
}
}
/**
- * Returns the maximum value recorded, or {@link Double#POSITIVE_INFINITY} if no values have
+ * Returns the maximum value recorded, or {@link Double#NEGATIVE_INFINITY} if no values have
* been recorded.
*
- * @return the maximum value, or {@link Double#POSITIVE_INFINITY} if none
+ * @return the maximum value, or {@link Double#NEGATIVE_INFINITY} if none
*/
public final BigDecimal getMax() {
if (this.count == 0) {
- return BigDecimal.valueOf(Double.POSITIVE_INFINITY);
+ return BigDecimal.valueOf(Double.NEGATIVE_INFINITY);
} else {
return max;
}
diff --git a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
index eeec30a..219aa04 100644
--- a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
+++ b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
@@ -68,7 +68,7 @@ class BigDecimalSummaryStatisticsTest {
@Test
@DisplayName("should fail if sum is given null.")
- void sshouldFailWithNullForSum() {
+ void shouldFailWithNullForSum() {
assertThatIllegalArgumentException()
.isThrownBy(
() -> new BigDecimalSummaryStatistics(0L, BigDecimal.ZERO, BigDecimal.TEN,
@@ -116,6 +116,33 @@ class BigDecimalSummaryStatisticsTest {
.withMessage("other is not allowed to be null.");
}
+ @Test
+ @DisplayName("average should result in Zero if no values have been provided.")
+ void averageShouldResultInZeroWhenNoValuesHaveBeenProvided() {
+ assertThat(this.bigDecimalSummaryStatistics.getAverage()).isEqualTo(BigDecimal.ZERO);
+ }
+
+ @Test
+ @DisplayName("count should result in Zero if no values have been provided.")
+ void countShouldResultInZeroWhenNoValuesHaveBeenProvided() {
+ assertThat(this.bigDecimalSummaryStatistics.getCount()).isEqualTo(0L);
+ }
+
+ @Test
+ @DisplayName("sum should result in Zero if no values have been provided.")
+ void sumShouldResultInZeroWhenNoValuesHaveBeenProvided() {
+ assertThat(this.bigDecimalSummaryStatistics.getSum()).isEqualTo(BigDecimal.ZERO);
+ }
+ @Test
+ @DisplayName("min should result in positiv infinity if no values have been provided.")
+ void minShouldResultInNegativeInfinityWhenNoValuesHaveBeenProvided() {
+ assertThat(this.bigDecimalSummaryStatistics.getMin()).isEqualTo(BigDecimal.valueOf(Double.POSITIVE_INFINITY));
+ }
+ @Test
+ @DisplayName("max should result in negative infinity if no values have been provided.")
+ void maxShouldResultInNegativeInfinityWhenNoValuesHaveBeenProvided() {
+ assertThat(this.bigDecimalSummaryStatistics.getMax()).isEqualTo(BigDecimal.valueOf(Double.NEGATIVE_INFINITY));
+ }
}
@Nested
@@ -160,4 +187,19 @@ class BigDecimalSummaryStatisticsTest {
}
+ @Nested
+ class TrialTest {
+
+ @Test
+ void XXX() {
+ Double d = Double.POSITIVE_INFINITY;
+ BigDecimal d1 = BigDecimal.ONE;
+ BigDecimal d0 = BigDecimal.ZERO;
+
+ BigDecimal result = d1.divide(d0);
+ System.out.println("result:" + result);
+ System.out.println("D:=" + d);
+ }
+ }
+
}