;;;; (import test) (include "test-gloss.incl") ;;; (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 "seq-utils") (import seq-utils) (test-group "sort" (define V1 #(5 3 4 2 1 9 7 8 6)) (test "Performs Sort" R1 (sort V1 <)) (test-assert "And Source is Unsorted" (not (sorted? V1 <))) (test "Performs Sort!" R1 (sort! V1 <)) (test-assert "And Source is Sorted" (sorted? V1 <)) ) ;sort was side-effecting a list arg (test-group "sort bug" (define R1L '(1 2 3 4 5 6 7 8 9)) (define V1L '(5 3 4 2 1 9 7 8 6)) (test "Performs Sort" R1L (sort V1L <)) (test-assert "And Source is Unsorted" (not (sorted? V1L <))) (test "Performs Sort!" R1L (sort! V1L <)) (test-assert "And Source is Sorted" (sorted? V1L <)) ) (test-group "merge" (define RV #(1 1.1 2 2.2 3 3.3 4 4.4 5 5.5 6 6.6 7 7.7 8 8.8 9 9.9)) (define RS '(1 2 3 4 5 6 7 8 9)) (define R2x '(1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9)) (test "Merges into same type" RV (merge R1 R2 <)) ;must copy R2 since destructive, but only defined on lists so vector ok (test "Merges into same type" RV (merge! R1 (append R2 '()) <)) ;must copy R2 since destructive, but only defined on lists so vector ok (test "Merges into same list" RS (merge! RS (append R2 '()) <)) ) (test-end "seq-utils") ;;; (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)) ) ) (test-end "micro-stats") (test-exit)