Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add convenience method for initialization #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ public SummaryStatistics(SummaryStatistics original) throws NullArgumentExceptio
copy(original, this);
}

/**
* Construct a SummaryStatistics instance filling it with the given initialDoubleArray
* @param initialDoubleArray values for filling the array
*/
public SummaryStatistics(double[] initialDoubleArray) {
for (double initialValue : initialDoubleArray) {
addValue(initialValue);
}
}

/**
* Construct a SummaryStatistics instance filling it with the given initialDoubleArray
* @param initialDoubleArray values for filling the array
*/
public SummaryStatistics(Double[] initialDoubleArray) {
for (Double initialValue : initialDoubleArray) {
addValue(initialValue);
}
}

/**
* Return a {@link StatisticalSummaryValues} instance reporting current
* statistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public void testQuadraticMean() {
expected = Math.sqrt(expected);

Assert.assertEquals(expected, stats.getQuadraticMean(), Math.ulp(expected));

SummaryStatistics convenienceMethodStatistics = new SummaryStatistics(values);
Assert.assertEquals(expected, convenienceMethodStatistics.getQuadraticMean(), Math.ulp(expected));
}

/**
Expand Down