;;;; (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 micro-stats) (import (only (chicken base) alist-ref)) (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)) ) (test-group "mean" (let-values (((m h g) (mean R1))) (test 5 m) (test 22680/7129 h) (test 4.14716627439691 g) ) (let-values (((m h g) (mean R2))) (test 5.5 m) (test 3.49950904755225 h) (test 4.5618829018366 g) ) ) (test-group "median" (test 5 (median R1)) (test 5.5 (median R2)) ) (test-group "mode" (test 9 (mode R1)) (test 9.9 (mode R2)) ) (test-group "percentile" (test 9 (percentile R1)) (test 9.9 (percentile R2)) ) (test-group "standard-deviation" (test 2.73861278752583 (standard-deviation R1)) (test 3.01247406627841 (standard-deviation R2)) ) (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)) ) ) #| (import utf8) (char-name '|Chi| (integer->char #x003A7)) (char-name '|^2| (integer->char #x000B2)) (define Chi^2 (string (char-name '|Chi|) (char-name '|^2|))) |# (define Chi^2 "Chi^2") (test-group "chi-square" (define observed '(1003390.64498901 1003339.76300049 1002674.73300171)) (define expected '(1000726.09802246 1004995.05200195 1000966.09100342)) (gloss Chi^2 ":" (chi-square observed expected)) (gloss Chi^2 ":" (chi-square observed expected #t) "(yates)") ) (test-end "micro-stats") (test-exit)