This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit a5302153bd7805c71c29d242565fdd9fcae65314 Author: Alex Herbert <aherb...@apache.org> AuthorDate: Fri Mar 21 12:45:28 2025 +0000 STATISTICS-90: Add range example to user guide --- .../org/apache/commons/statistics/descriptive/UserGuideTest.java | 4 ++++ src/site/xdoc/userguide/index.xml | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UserGuideTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UserGuideTest.java index 1ed6e25..0955dba 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UserGuideTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/UserGuideTest.java @@ -38,6 +38,8 @@ class UserGuideTest { double v = IntVariance.of(values).getAsDouble(); + int max = IntMax.ofRange(values, 3, 6).getAsInt(); + double m = Stream.of("one", "two", "three", "four") .mapToInt(String::length) .collect(IntMean::create, IntMean::accept, IntMean::combine) @@ -47,6 +49,8 @@ class UserGuideTest { // np.var([1, 1, 2, 3, 5, 8, 13, 21], ddof=1) Assertions.assertEquals(49.92857142857143, v, 1e-10); + Assertions.assertEquals(8, max); + // mean = sum([3, 3, 5, 4]) / 4 Assertions.assertEquals(15.0 / 4.0, m); } diff --git a/src/site/xdoc/userguide/index.xml b/src/site/xdoc/userguide/index.xml index 43f9851..a5dac66 100644 --- a/src/site/xdoc/userguide/index.xml +++ b/src/site/xdoc/userguide/index.xml @@ -193,13 +193,17 @@ </subsection> <subsection name="Examples" id="desc_examples"> <p> - Computation of a single statistic from an array of values, or a stream of data: + Computation of a single statistic from an array of values, an array range or a + stream of data: </p> <source class="prettyprint"> int[] values = {1, 1, 2, 3, 5, 8, 13, 21}; double v = IntVariance.of(values).getAsDouble(); +// Range uses inclusive start and exclusive end +int max = IntMax.ofRange(values, 3, 6).getAsInt(); // 8 + double m = Stream.of("one", "two", "three", "four") .mapToInt(String::length) .collect(IntMean::create, IntMean::accept, IntMean::combine)