;;;; (import test) ;(import (only (chicken format) format)) ;(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 "Sequences Utils") (import (prefix (sequences utils) seq:)) (test-group "coercion" (test '(#\a #\b) (seq:->list "ab")) (test #(#\a #\b) (seq:->vector "ab")) (test "ab" (seq:->string '(#\a #\b))) ) (test-group "sort" (define V1 #(5 3 4 2 1 9 7 8 6)) (test "Performs Sort" R1 (seq:sort V1 <)) (test-assert "And Source is Unsorted" (not (seq:sorted? V1 <))) (test "Performs Sort!" R1 (seq:sort! V1 <)) (test-assert "And Source is Sorted" (seq: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 (seq:sort V1L <)) (test-assert "And Source is Unsorted" (not (seq:sorted? V1L <))) (test "Performs Sort!" R1L (seq:sort! V1L <)) (test-assert "And Source is Sorted" (seq: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 (seq:merge R1 R2 <)) ;must copy R2 since destructive, but only defined on lists so vector ok (test "Merges into same type" RV (seq:merge! R1 (append R2 '()) <)) ;must copy R2 since destructive, but only defined on lists so vector ok (test "Merges into same list" RS (seq:merge! RS (append R2 '()) <)) ) (test-group "foldl->alist" (test '() (seq:foldl->alist '() (lambda (i v) (cons i v)) '())) (test '((b b) (a a a)) (seq:foldl->alist '(a b a) (lambda (i v) (cons i v)) '())) ) (test-group "histogram" (test '() (seq:histogram "")) (test '((#\a . 7)) (seq:histogram "aaaaaaa")) (test '((#\space . 1) (#\p . 2) (#\h . 1) (#\o . 3) (#\s . 4) (#\f . 2) (#\; . 2) (#\q . 1) (#\j . 6) (#\l . 2) (#\e . 3) (#\i . 1) (#\w . 3) (#\k . 5) (#\d . 2) (#\c . 3) (#\b . 1) (#\a . 7)) (seq:histogram "abcccdkwiweklajakjq;jkkladfsjaso;hasejfopasjeopw ")) (test '() (seq:histogram '())) (test '((a . 7)) (seq:histogram '(a a a a a a a))) ) (test-end "Sequences Utils") (test-exit)