;;;; (import test) (import (only (chicken format) format) (test-utils gloss)) ;;; (define R1 #(1 2 3 4 5 6 7 8 9)) (define R2 '(1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9)) ;;; (test-begin "micro-stats") (import scheme (chicken base)) (import micro-stats) (test-group "Statistics-sets" (test-assert (list? (statistics-sets))) (test-assert (list? (alist-ref 'normal (statistics-sets) eq?))) (test-assert (list? (alist-ref 'verbose (statistics-sets) eq?))) (test (alist-ref 'normal (statistics-sets) eq?) (statistics-set #f)) (test (alist-ref 'verbose (statistics-sets) eq?) (statistics-set #t)) ) ;FIXME floats used to test exact values 0- need @prec (test-group "Mean* & Co" (let-values (((m h g) (mean* R1))) (test 5 m) (test 22680/7129 h) (test 4.14716627439691 (exact->inexact g)) (test m (arithmetic-mean R1)) (test h (harmonic-mean R1)) (test g (geometric-mean R1)) ) (let-values (((m h g) (mean* R2))) (test 5.5 m) (test 3.49950904755225 (exact->inexact h)) (test 4.5618829018366 (exact->inexact g)) (test m (arithmetic-mean R2)) (test h (harmonic-mean R2)) (test g (geometric-mean R2)) ) ) (test-group "Median" (test 5 (median R1)) (test 5.5 (median R2)) ) (test-group "Mode" (test 1 (mode R1)) (test 1.1 (mode R2)) ) (test-group "Percentile" (test 17/2 (percentile R1)) (test 9.35 (percentile R2)) ) (test-group "Standard-deviation*" (test-assert (exact? (receive (a b) (standard-deviation* R1) a))) (test 2.73861278752583 (exact->inexact (receive (a b) (standard-deviation* R1) a))) (test-assert (inexact? (receive (a b) (standard-deviation* R2) a))) (test 3.01247406627841 (receive (a b) (standard-deviation* R2) a)) ) (test-group "Standard-deviation (no bias)" (test-assert (exact? (standard-deviation R1 #f))) (test 2.58198889747161 (exact->inexact (standard-deviation R1 #f))) (test-assert (inexact? (standard-deviation R2 #f))) (test 2.84018778721877 (standard-deviation R2 #f)) ) (test-group "Basic-statistics" (let ((expt #(5 22680/7129 4.14716627439691 2.73861278752583 15/2)) (stats (basic-statistics R1)) ) (test "mean" (vector-ref expt 0) (vector-ref expt 0)) (test "mean harmonic" (vector-ref expt 1) (vector-ref expt 1)) (test "mean geometric" (vector-ref expt 2) (vector-ref expt 2)) (test "standard-deviation" (vector-ref expt 3) (vector-ref expt 3)) (test "variance" (vector-ref expt 4) (vector-ref expt 4)) ) (let ((expt #(5.5 3.49950904755225 4.5618829018366 3.01247406627841 9.075)) (stats (basic-statistics R2)) ) (test "mean" (vector-ref expt 0) (vector-ref expt 0)) (test "mean harmonic" (vector-ref expt 1) (vector-ref expt 1)) (test "mean geometric" (vector-ref expt 2) (vector-ref expt 2)) (test "standard-deviation" (vector-ref expt 3) (vector-ref expt 3)) (test "variance" (vector-ref expt 4) (vector-ref expt 4)) ) ) (define observed '(1003390.64498901 1003339.76300049 1002674.73300171)) (define expected '(1000726.09802246 1004995.05200195 1000966.09100342)) ;#; (test-group "Distirbution" (gloss "Kurtosis" ":" (kurtosis observed)) (gloss "Kurtosis" ":" (kurtosis observed #f) "(no bias)") (gloss "Skewness" ":" (skewness observed)) (gloss "Skewness" ":" (skewness observed #f) "(no bias)") ) ;#; (test-group "Co..." (gloss "Covariance" ":" (covariance observed expected)) (gloss "Covariance" ":" (covariance observed expected #f) "(no bias)") (gloss "Correlation" ":" (correlation observed expected)) (gloss "Correlation" ":" (correlation observed expected #f) "(no bias)") ) ;#; (test-group "Chi-square" (gloss "Chi^2" ":" (chi-square observed expected)) (gloss "Chi^2" ":" (chi-square observed expected #t) "(yates)") ) (test-end "micro-stats") (test-exit)