(import scheme (chicken base) (chicken condition) pseudolists simple-tests) ;(define pl (pl-maker #f 0 1 2)) (define-test (pseudolists?) (pl? "x") (pl? '(a b . c)) (pl-null? 5) ((pl-of?) "x") ((pl-of? symbol?) '(a b . c)) (equal? (pl-maker #f 0 1 2) '(0 1 2 . #f)) (not (pl-maker #f)) (equal? (pl-iterate add1 5 0) '(0 1 2 3 4)) (not (pl-sentinel '(1 2 3 4 . #f))) (= (pl-sentinel '(0 1 2 3 2 . 2)) 2) (= (pl-length '(0 1 2 3 . 4)) 4) (equal? (pl-head '(0 1 2 3 2 . 2)) '(0 1 2 3 2)) (equal? (pl-head 0) '()) (equal? (pl-head '(0 . 1)) '(0)) (= (pl-at 1 '(0 1 2 3 . 4)) 1) (= (pl-at 2 '(0 1 2 3 . #f)) 2) (not (condition-case (pl-at 0 1) ((exn) #f))) (= (pl-index odd? '(0 1 2 . 3)) 1) (= (pl-index odd? '(0 2 4 . 1)) -1) (equal? (pl-drop 1 '(0 1 2 3 . 4)) '(1 2 3)) (null? (pl-drop 0 1)) (equal? (pl-drop 2 '(0 1 2 3 . #f)) '(2 3)) (equal? (pl-drop-while odd? '(1 3 2 4 . #f)) '(2 4)) (equal? (pl-drop-while negative? '(1 3 2 4 . #f)) '(1 3 2 4)) (equal? (pl-take 3 '(0 1 2 3 4 . #t)) '(0 1 2)) (equal? (pl-take 2 '(0 1 2 3 . #f)) '(0 1)) (equal? (pl-take-while odd? '(1 3 2 4 . #f)) '(1 3)) (null? (pl-take-while negative? '(1 3 2 4))) (null? (pl-filter odd? 1)) (equal? (pl-filter odd? '(0 1 2 3 4)) '(1 3)) (equal? (pl-filter odd? '(0 1 2 3 . 4)) '(1 3)) (equal? (pl-filter even? '(0 1 2 3 . 4)) '(0 2)) (equal? (pl-map add1 '(0 1 2 3 . 4)) '(1 2 3 4)) (equal? (pl-map add1 '(0 1 2 3 . 4)) '(1 2 3 4)) (equal? (pl-map add1 '(0 1 2 3)) '(1 2 3 4)) (null? (pl-map add1 #f)) (not (pl-memp odd? '(0 2 4 . #t))) (not (pl-memv 5 '(0 1 2 3 4 . 5))) (equal? (pl-member 3 '(0 1 2 3 4 . 5)) '(3 4)) (equal? (pl-reverse '(0 1 2 3 . 4)) '(3 2 1 0)) (equal? (pl-reverse '(0 1 2 3 . 4)) '(3 2 1 0)) (equal? (pl-reverse '(0 1 2 3)) '(3 2 1 0)) (equal? (pl-append '(0 1) #f) '(0 1)) (equal? (pl-append '(0 1)) '(0 1)) (equal? (pl-append '(0 1) '(2 3) #f) '(0 1 2 3)) (equal? (pl-append '(0 1 . #f) '(2 3)) '(0 1 2 3)) (equal? (pl-append '(0 1) '(2 3) '(4 5)) '(0 1 2 3 4 5)) (equal? (pl-append '(0 1 . #f) '(2 3 . #t) '(4 5)) '(0 1 2 3 4 5)) (equal? (pl-append '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) '(0 1 2 3 4 5)) (equal? (pl-append '(0 1 . #t) '(2 3 . #t) '(4 5) #t) '(0 1 2 3 4 5)) (= (pl-fold-right + 0 '(1 2 3 . #f)) 6) (= (pl-fold-left + 0 '(1 2 3)) 6) (equal? (pl-adjoin 2 '(0 1 2 3 . #f)) '(0 1 2 3)) (equal? (pl-adjoin 4 '(0 1 2 3 #f . #t)) '(4 0 1 2 3 #f)) (equal? (pl-adjoin 1 '(0 1 2 3)) '(0 1 2 3)) (equal? (pl-adjoin 1 #f) '(1)) (equal? (pl-remove-dups '(0 1 2 3 2 . 2)) '(0 1 3 2)) (equal? (pl-remove-dups '(0 1 2 3 2 2)) '(0 1 3 2)) (equal? (pl-remove-dups '(0 1 2 1 3 2)) '(0 1 3 2)) (equal? (pl-flatten '(1 (2 3) . #t)) '(1 2 3)) (equal? (pl-flatten '(1 (2 (3 . #f) . #t) . #f)) '(1 2 3)) (null? (pl-flatten #f)) (equal? (pl-collect (add1 x) (x '(0 1 2 3 . #f))) ; map '(1 2 3 4)) (equal? (pl-collect (add1 x) (x '(0 1 2 3))) ; map '(1 2 3 4)) (equal? (pl-collect x (x '(0 1 2 3 4 5 . #f) (odd? x))) ; filter '(1 3 5)) (equal? (pl-collect x (x '(0 1 2 3 4 5) (odd? x))) ; filter '(1 3 5)) (equal? (pl-collect (* 10 n) (n '(0 1 2 3 4 5) (positive? n) (even? n))) '(20 40)) (equal? (pl-collect (list c k) (c '(A B C)) (k '(1 2 3 4))) '((A 1) (A 2) (A 3) (A 4) (B 1) (B 2) (B 3) (B 4) (C 1) (C 2) (C 3) (C 4))) (equal? (pl-collect (list c k) (c '(A B C . #f)) (k '(1 2 3 4 . #f))) '((A 1) (A 2) (A 3) (A 4) (B 1) (B 2) (B 3) (B 4) (C 1) (C 2) (C 3) (C 4))) ) (compound-test (PSEUDOLISTS) (pseudolists?) )