You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ani5rudh (via GitHub)" <gi...@apache.org> on 2023/07/16 18:06:03 UTC

[GitHub] [commons-statistics] ani5rudh opened a new pull request, #49: [STATISTICS-76]: Max Implementation

ani5rudh opened a new pull request, #49:
URL: https://github.com/apache/commons-statistics/pull/49

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-statistics] ani5rudh commented on a diff in pull request #49: [STATISTICS-76]: Max Implementation

Posted by "ani5rudh (via GitHub)" <gi...@apache.org>.
ani5rudh commented on code in PR #49:
URL: https://github.com/apache/commons-statistics/pull/49#discussion_r1264800171


##########
commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MaxTest.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.statistics.descriptive;
+
+import java.util.Arrays;
+import java.util.function.DoubleSupplier;
+import java.util.stream.Stream;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Test for {@link Max}.
+ */
+final class MaxTest {
+
+    @Test
+    void testEmpty() {
+        Max max = Max.create();
+        Assertions.assertEquals(Double.NEGATIVE_INFINITY, max.getAsDouble());
+    }
+
+    @Test
+    void testIncrement() {
+        // Test the max after each incremental update
+        // First parameter of testArray is the value that would be added
+        // Second parameter of testArray is the max we expect after adding the value
+        double[][] testArray = {
+            {1729.22, 1729.22},
+            {2520.35, 2520.35},
+            {2010.87, 2520.35},
+            {100000000.1, 100000000.1},
+            {+0.0, 100000000.1},
+            {-0.0, 100000000.1},
+            {Double.MAX_VALUE, Double.MAX_VALUE},
+            {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
+            {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}
+        };
+
+        Max stat = Max.create();
+        for (final double[] valueAndExpected: testArray) {
+            final double value = valueAndExpected[0];
+            final double expected = valueAndExpected[1];
+            stat.accept(value);
+            Assertions.assertEquals(expected, stat.getAsDouble());
+        }
+    }
+
+    @Test
+    void testNaN() {
+        // Test non-nan values cannot revert a NaN
+        double[] testArray = {Double.NaN, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
+        Max stat = Max.create();
+        for (final double x : testArray) {
+            stat.accept(x);
+            Assertions.assertEquals(Double.NaN, stat.getAsDouble());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void testMax(double[] values, double expected) {
+        Max stat = Max.create();
+        Arrays.stream(values).forEach(stat);
+        double actual = stat.getAsDouble();
+        Assertions.assertEquals(expected, actual, "max");
+        Assertions.assertEquals(expected, Max.of(values).getAsDouble(), "max");
+    }
+
+    static Stream<Arguments> testMax() {
+        return Stream.of(
+            Arguments.of(new double[] {}, Double.NEGATIVE_INFINITY),
+            Arguments.of(new double[] {3.14}, 3.14),
+            Arguments.of(new double[] {12.34, 56.78, -2.0}, 56.78),
+            Arguments.of(new double[] {Double.NaN, 3.14, Double.NaN, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {-1d, 1d, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {Double.NaN, Double.NaN, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {0.0d, Double.NaN, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}, Double.NaN),
+            Arguments.of(new double[] {+0.0d, -0.0d, 1.0, 3.14}, 3.14),
+            Arguments.of(new double[] {-0.0, +0.0}, 0.0),
+            Arguments.of(new double[] {0.0, -0.0}, 0.0),
+            Arguments.of(new double[] {0.0, +0.0}, 0.0),
+            Arguments.of(new double[] {1.2, -34.56, 456.789, -5678.9012}, 456.789),
+            Arguments.of(new double[] {-23467824, 23648, 2368, 23749, -23424, -23492, -92397747}, 23749),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.MIN_VALUE}, Double.POSITIVE_INFINITY),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, -Double.MIN_VALUE}, Double.POSITIVE_INFINITY),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.MIN_VALUE}, Double.POSITIVE_INFINITY)

Review Comment:
   Thanks @kinow, I've updated the tests for Max per your feedback.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-statistics] kinow commented on a diff in pull request #49: [STATISTICS-76]: Max Implementation

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #49:
URL: https://github.com/apache/commons-statistics/pull/49#discussion_r1264731414


##########
commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MaxTest.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.statistics.descriptive;
+
+import java.util.Arrays;
+import java.util.function.DoubleSupplier;
+import java.util.stream.Stream;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Test for {@link Max}.
+ */
+final class MaxTest {
+
+    @Test
+    void testEmpty() {
+        Max max = Max.create();
+        Assertions.assertEquals(Double.NEGATIVE_INFINITY, max.getAsDouble());
+    }
+
+    @Test
+    void testIncrement() {
+        // Test the max after each incremental update
+        // First parameter of testArray is the value that would be added
+        // Second parameter of testArray is the max we expect after adding the value
+        double[][] testArray = {
+            {1729.22, 1729.22},
+            {2520.35, 2520.35},
+            {2010.87, 2520.35},
+            {100000000.1, 100000000.1},
+            {+0.0, 100000000.1},
+            {-0.0, 100000000.1},
+            {Double.MAX_VALUE, Double.MAX_VALUE},
+            {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
+            {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}
+        };
+
+        Max stat = Max.create();
+        for (final double[] valueAndExpected: testArray) {
+            final double value = valueAndExpected[0];
+            final double expected = valueAndExpected[1];
+            stat.accept(value);
+            Assertions.assertEquals(expected, stat.getAsDouble());
+        }
+    }
+
+    @Test
+    void testNaN() {
+        // Test non-nan values cannot revert a NaN
+        double[] testArray = {Double.NaN, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
+        Max stat = Max.create();
+        for (final double x : testArray) {
+            stat.accept(x);
+            Assertions.assertEquals(Double.NaN, stat.getAsDouble());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void testMax(double[] values, double expected) {
+        Max stat = Max.create();
+        Arrays.stream(values).forEach(stat);
+        double actual = stat.getAsDouble();
+        Assertions.assertEquals(expected, actual, "max");
+        Assertions.assertEquals(expected, Max.of(values).getAsDouble(), "max");
+    }
+
+    static Stream<Arguments> testMax() {
+        return Stream.of(
+            Arguments.of(new double[] {}, Double.NEGATIVE_INFINITY),
+            Arguments.of(new double[] {3.14}, 3.14),
+            Arguments.of(new double[] {12.34, 56.78, -2.0}, 56.78),
+            Arguments.of(new double[] {Double.NaN, 3.14, Double.NaN, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {-1d, 1d, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {Double.NaN, Double.NaN, Double.NaN}, Double.NaN),
+            Arguments.of(new double[] {0.0d, Double.NaN, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}, Double.NaN),
+            Arguments.of(new double[] {+0.0d, -0.0d, 1.0, 3.14}, 3.14),
+            Arguments.of(new double[] {-0.0, +0.0}, 0.0),
+            Arguments.of(new double[] {0.0, -0.0}, 0.0),
+            Arguments.of(new double[] {0.0, +0.0}, 0.0),
+            Arguments.of(new double[] {1.2, -34.56, 456.789, -5678.9012}, 456.789),
+            Arguments.of(new double[] {-23467824, 23648, 2368, 23749, -23424, -23492, -92397747}, 23749),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.MIN_VALUE}, Double.POSITIVE_INFINITY),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, -Double.MIN_VALUE}, Double.POSITIVE_INFINITY),
+            Arguments.of(new double[] {0.0d, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.MIN_VALUE}, Double.POSITIVE_INFINITY)

Review Comment:
   Quickly compared the code in this PR with the existing Min code, and everything looks OK. The only part I noticed that did not change was this with the `Double.MIN_VALUE`'s. Is that intentional or were we supposed to use `Double.MAX_VALUE` for this test?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-statistics] aherbert commented on a diff in pull request #49: [STATISTICS-76]: Max Implementation

Posted by "aherbert (via GitHub)" <gi...@apache.org>.
aherbert commented on code in PR #49:
URL: https://github.com/apache/commons-statistics/pull/49#discussion_r1265505789


##########
commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MaxTest.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.statistics.descriptive;
+
+import java.util.Arrays;
+import java.util.function.DoubleSupplier;
+import java.util.stream.Stream;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Test for {@link Max}.
+ */
+final class MaxTest {
+
+    @Test
+    void testEmpty() {
+        Max max = Max.create();
+        Assertions.assertEquals(Double.NEGATIVE_INFINITY, max.getAsDouble());
+    }
+
+    @Test
+    void testIncrement() {
+        // Test the max after each incremental update
+        // First parameter of testArray is the value that would be added
+        // Second parameter of testArray is the max we expect after adding the value
+        double[][] testArray = {
+            {1729.22, 1729.22},
+            {2520.35, 2520.35},
+            {2010.87, 2520.35},
+            {100000000.1, 100000000.1},
+            {+0.0, 100000000.1},
+            {-0.0, 100000000.1},
+            {Double.MAX_VALUE, Double.MAX_VALUE},
+            {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
+            {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}
+        };
+
+        Max stat = Max.create();
+        for (final double[] valueAndExpected: testArray) {
+            final double value = valueAndExpected[0];
+            final double expected = valueAndExpected[1];
+            stat.accept(value);
+            Assertions.assertEquals(expected, stat.getAsDouble());
+        }
+    }
+
+    @Test
+    void testNaN() {
+        // Test non-nan values cannot revert a NaN
+        double[] testArray = {Double.NaN, +0.0d, -0.0d, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
+        Max stat = Max.create();
+        for (final double x : testArray) {
+            stat.accept(x);
+            Assertions.assertEquals(Double.NaN, stat.getAsDouble());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void testMax(double[] values, double expected) {
+        Max stat = Max.create();
+        Arrays.stream(values).forEach(stat);
+        double actual = stat.getAsDouble();
+        Assertions.assertEquals(expected, actual, "max");
+        Assertions.assertEquals(expected, Max.of(values).getAsDouble(), "max");

Review Comment:
   The assertion message here is not helpful to distinguish this case. You could use "of(values)". Just change the test data so the test fails and you can see how JUnit will output the message. This should be helpful to diagnose the problem with the code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-statistics] aherbert merged pull request #49: STATISTICS-76: Max Implementation

Posted by "aherbert (via GitHub)" <gi...@apache.org>.
aherbert merged PR #49:
URL: https://github.com/apache/commons-statistics/pull/49


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-statistics] codecov-commenter commented on pull request #49: [STATISTICS-76]: Max Implementation

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #49:
URL: https://github.com/apache/commons-statistics/pull/49#issuecomment-1637161163

   ## [Codecov](https://app.codecov.io/gh/apache/commons-statistics/pull/49?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#49](https://app.codecov.io/gh/apache/commons-statistics/pull/49?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (f9706d6) into [master](https://app.codecov.io/gh/apache/commons-statistics/commit/a1094d6841ee746d5383cca0a4a380ea74c97db1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (a1094d6) will **not change** coverage.
   > The diff coverage is `n/a`.
   
   ```diff
   @@            Coverage Diff            @@
   ##             master      #49   +/-   ##
   =========================================
     Coverage     99.82%   99.82%           
     Complexity     1688     1688           
   =========================================
     Files            65       65           
     Lines          4472     4472           
     Branches        756      756           
   =========================================
     Hits           4464     4464           
     Misses            4        4           
     Partials          4        4           
   ```
   
   
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org