You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/09/20 00:47:27 UTC

cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat FrequencyTest.java

psteitz     2004/09/19 15:47:27

  Modified:    math/src/java/org/apache/commons/math/stat Frequency.java
               math/src/test/org/apache/commons/math/stat
                        FrequencyTest.java
  Log:
  Fixed error computing cumulative frequencies when actual parameter is an Integer.  Reported to commons-dev list by Jon Langlois.
  
  Revision  Changes    Path
  1.28      +8 -1      jakarta-commons/math/src/java/org/apache/commons/math/stat/Frequency.java
  
  Index: Frequency.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/Frequency.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Frequency.java	22 Aug 2004 01:42:58 -0000	1.27
  +++ Frequency.java	19 Sep 2004 22:47:27 -0000	1.28
  @@ -149,6 +149,10 @@
       
       /**
        * Returns an Iterator over the set of values that have been added.
  +     * <p>
  +     * If added values are itegral (i.e., integers, longs, Integers, or Longs), 
  +     * they are converted to Longs when they are added, so the objects returned
  +     * by the Iterator will in this case be Longs.
        * 
        * @return values Iterator
        */
  @@ -288,6 +292,9 @@
       public long getCumFreq(Object v) {
           if (getSumFreq() == 0) {
               return 0;
  +        }
  +        if (v instanceof Integer) {
  +            return getCumFreq(((Integer) v).longValue());
           }
           Comparator c = freqTable.comparator();
           if (c == null) {
  
  
  
  1.14      +3 -1      jakarta-commons/math/src/test/org/apache/commons/math/stat/FrequencyTest.java
  
  Index: FrequencyTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/FrequencyTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FrequencyTest.java	12 Aug 2004 15:33:39 -0000	1.13
  +++ FrequencyTest.java	19 Sep 2004 22:47:27 -0000	1.14
  @@ -69,6 +69,7 @@
           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("Integer argument cum freq",4, f.getCumFreq(new Integer(2)));
           assertEquals("five cumulative frequency", 4,  f.getCumFreq(5));
           assertEquals("foo cumulative frequency", 0,  f.getCumFreq("foo"));
           
  @@ -128,6 +129,7 @@
           assertEquals("foo pct",0,f.getPct("foo"),tolerance);
           assertEquals("one cum pct",0.25,f.getCumPct(1),tolerance);
           assertEquals("two cum pct",0.50,f.getCumPct(new Long(2)),tolerance);
  +        assertEquals("Integer argument",0.50,f.getCumPct(new Integer(2)),tolerance);
           assertEquals("three cum pct",1.0,f.getCumPct(threeL),tolerance);
           assertEquals("five cum pct",1.0,f.getCumPct(5),tolerance);
           assertEquals("zero cum pct",0.0,f.getCumPct(0),tolerance);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org