Added toString() override to StatistictalSummaryValues. JIRA: MATH-420.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1038873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3d93dbf5ce
commit
bf98dae677
|
@ -160,5 +160,27 @@ public class StatisticalSummaryValues implements Serializable,
|
|||
result = result * 31 + MathUtils.hash(getVariance());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a text report displaying values of statistics.
|
||||
* Each statistic is displayed on a separate line.
|
||||
*
|
||||
* @return String with line feeds displaying statistics
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer outBuffer = new StringBuffer();
|
||||
String endl = "\n";
|
||||
outBuffer.append("StatisticalSummaryValues:").append(endl);
|
||||
outBuffer.append("n: ").append(getN()).append(endl);
|
||||
outBuffer.append("min: ").append(getMin()).append(endl);
|
||||
outBuffer.append("max: ").append(getMax()).append(endl);
|
||||
outBuffer.append("mean: ").append(getMean()).append(endl);
|
||||
outBuffer.append("std dev: ").append(getStandardDeviation())
|
||||
.append(endl);
|
||||
outBuffer.append("variance: ").append(getVariance()).append(endl);
|
||||
outBuffer.append("sum: ").append(getSum()).append(endl);
|
||||
return outBuffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.commons.math.stat.descriptive;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.math.TestUtils;
|
||||
|
@ -65,4 +67,19 @@ public final class StatisticalSummaryValuesTest extends TestCase {
|
|||
TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0);
|
||||
TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
StatisticalSummaryValues u = new StatisticalSummaryValues(4.5, 16, 10, 5, 4, 45);
|
||||
Locale d = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
assertEquals("StatisticalSummaryValues:\n" +
|
||||
"n: 10\n" +
|
||||
"min: 4.0\n" +
|
||||
"max: 5.0\n" +
|
||||
"mean: 4.5\n" +
|
||||
"std dev: 4.0\n" +
|
||||
"variance: 16.0\n" +
|
||||
"sum: 45.0\n", u.toString());
|
||||
Locale.setDefault(d);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue