]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics: fix stack effect on collect-by
authorJoe Groff <arcata@gmail.com>
Tue, 1 Nov 2011 01:55:21 +0000 (18:55 -0700)
committerJoe Groff <arcata@gmail.com>
Wed, 2 Nov 2011 20:23:13 +0000 (13:23 -0700)
basis/math/statistics/statistics-tests.factor
basis/math/statistics/statistics.factor

index 0d3172f685800936875776b007b48fdb48775698..ec6cda05b1d42206737b0dea2bcd74267c1e6eeb 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel math math.functions math.statistics tools.test ;
+USING: assocs kernel math math.functions math.statistics sequences tools.test ;
 IN: math.statistics.tests
 
 [ 1 ] [ { 1 } mean ] unit-test
@@ -53,3 +53,12 @@ IN: math.statistics.tests
 ] [
     "aabbcc" histogram
 ] unit-test
+
+{
+    V{ 0 3 6 9 }
+    V{ 1 4 7 }
+    V{ 2 5 8 }
+} [
+    10 iota [ 3 mod ] collect-by
+    [ 0 swap at ] [ 1 swap at ] [ 2 swap at ] tri
+] unit-test
index 46b24bc98b24b297f4eea37e02fd60d61b6ea5d0..54edff34a44d57f5ff444385ca56b7b6166f7cbd 100644 (file)
@@ -84,10 +84,10 @@ PRIVATE>
 : sorted-histogram ( seq -- alist )
     histogram sort-values ;
 
-: collect-pairs ( seq quot: ( x -- x' ) -- hashtable )
+: collect-pairs ( seq quot: ( x -- v k ) -- hashtable )
     [ push-at ] sequence>hashtable ; inline
 
-: collect-by ( seq quot -- hashtable )
+: collect-by ( seq quot: ( x -- x' ) -- hashtable )
     [ dup ] prepose collect-pairs ; inline
 
 : mode ( seq -- x )