From 7e6d5d5d54d0685411b9e482b841254d35bb3e1c Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sun, 7 Mar 2004 00:57:11 +0000 Subject: [PATCH] Added test cases corresponding to examples in the User Guide. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141120 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/stat/FrequencyTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/test/org/apache/commons/math/stat/FrequencyTest.java b/src/test/org/apache/commons/math/stat/FrequencyTest.java index df7bc77c7..7c158ec70 100644 --- a/src/test/org/apache/commons/math/stat/FrequencyTest.java +++ b/src/test/org/apache/commons/math/stat/FrequencyTest.java @@ -26,7 +26,7 @@ import junit.framework.TestSuite; /** * Test cases for the {@link Frequency} class. * - * @version $Revision: 1.11 $ $Date: 2004/02/21 21:35:17 $ + * @version $Revision: 1.12 $ $Date: 2004/03/07 00:57:11 $ */ public final class FrequencyTest extends TestCase { @@ -69,10 +69,32 @@ public final class FrequencyTest extends TestCase { assertEquals("zero cumulative frequency", 0, f.getCumFreq(0)); assertEquals("one cumulative frequency", 3, f.getCumFreq(1)); assertEquals("two cumulative frequency", 4, f.getCumFreq(2)); - assertEquals("two cumulative frequency", 4, f.getCumFreq(5)); - assertEquals("two cumulative frequency", 0, f.getCumFreq("foo")); + assertEquals("five cumulative frequency", 4, f.getCumFreq(5)); + assertEquals("foo cumulative frequency", 0, f.getCumFreq("foo")); + f.clear(); assertEquals("total count",0,f.getSumFreq()); + + // userguide examples ------------------------------------------------------------------- + f.addValue("one"); + f.addValue("One"); + f.addValue("oNe"); + f.addValue("Z"); + assertEquals("one cumulative frequency", 1 , f.getCount("one")); + assertEquals("Z cumulative pct", 0.5, f.getCumPct("Z"), tolerance); + assertEquals("z cumulative pct", 1.0, f.getCumPct("z"), tolerance); + assertEquals("Ot cumulative pct", 0.25, f.getCumPct("Ot"), tolerance); + f.clear(); + + f = null; + f = new Frequency(String.CASE_INSENSITIVE_ORDER); + f.addValue("one"); + f.addValue("One"); + f.addValue("oNe"); + f.addValue("Z"); + assertEquals("one count", 3 , f.getCount("one")); + assertEquals("Z cumulative pct -- case insensitive", 1 , f.getCumPct("Z"), tolerance); + assertEquals("z cumulative pct -- case insensitive", 1 , f.getCumPct("z"), tolerance); } /** test pcts */