(import scheme (chicken base) (chicken condition) pseudolists simple-tests) (define-test (pseudolists?) (pl? "x") (pl? '(a b . c)) (pl-null? 5) ((pl-of?) "x") ((pl-of? symbol?) '(a b . c)) (equal? (pl-maker (Some-sentinel #f) 1 2 3 4) '(1 2 3 4 . #f)) (equal? (pl-maker (Some-sentinel #f) 0 1 2 3) '(0 1 2 3 . #f)) (equal? (pl-maker (No-sentinel) 0 1 2 3) '(0 1 2 3)) (equal? (pl-iterate (Some-sentinel #f) add1 5 0) '(0 1 2 3 4 . #f)) (not (pl-sentinel (pl-maker (Some-sentinel #f) 1 2 3 4))) (= (pl-sentinel '(0 1 2 3 2 . 2)) 2) (not (pl-sentinel '(0 1 2 3 . #f))) (= (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 . 4)) (= (pl-drop 0 1) 1) (equal? (pl-drop 2 '(0 1 2 3 . #f)) '(2 3 . #f)) (equal? (pl-drop-while odd? '(1 3 2 4 . #f)) '(2 4 . #f)) (equal? (pl-drop-while negative? '(1 3 2 4 . #f)) '(1 3 2 4 . #f)) (equal? (pl-take 3 '(0 1 2 3 4 . #t)) '(0 1 2 . #t)) (equal? (pl-take 2 '(0 1 2 3 . #f)) '(0 1 . #f)) (equal? (pl-take-while odd? '(1 3 2 4 . #f)) '(1 3 . #f)) (null? (pl-take-while negative? '(1 3 2 4))) (= (pl-filter odd? 1) 1) (equal? (pl-filter odd? '(0 1 2 3 4)) '(1 3)) (equal? (pl-filter odd? '(0 1 2 3 . 4)) '(1 3 . 4)) (equal? (pl-filter even? '(0 1 2 3 . 4)) '(0 2 . 4)) (equal? (pl-map (No-sentinel) add1 '(0 1 2 3 . 4)) '(1 2 3 4)) (equal? (pl-map (Some-sentinel 5) add1 '(0 1 2 3 . 4)) '(1 2 3 4 . 5)) (equal? (pl-map (Some-sentinel #f) add1 '(0 1 2 3)) '(1 2 3 4 . #f)) (pl-map (Some-sentinel #t) add1 #f) (equal? (pl-reverse (Some-sentinel #f) '(0 1 2 3 . 4)) '(3 2 1 0 . #f)) (equal? (pl-reverse (No-sentinel) '(0 1 2 3 . 4)) '(3 2 1 0)) (equal? (pl-reverse (No-sentinel) '(0 1 2 3)) '(3 2 1 0)) (equal? (pl-reverse (Some-sentinel #f) '(0 1 2 3)) '(3 2 1 0 . #f)) (equal? (pl-append (No-sentinel) '(0 1) #f) '(0 1)) (equal? (pl-append (Some-sentinel #f) '(0 1)) '(0 1 . #f)) (equal? (pl-append (Some-sentinel #t) '(0 1) '(2 3) #f) '(0 1 2 3 . #t)) (equal? (pl-append (No-sentinel)'(0 1 . #f) '(2 3)) '(0 1 2 3)) (equal? (pl-append (No-sentinel)'(0 1) '(2 3) '(4 5)) '(0 1 2 3 4 5)) (equal? (pl-append (No-sentinel)'(0 1 . #f) '(2 3 . #t) '(4 5)) '(0 1 2 3 4 5)) (equal? (pl-append (Some-sentinel #f) '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) '(0 1 2 3 4 5 . #f)) (equal? (pl-append (Some-sentinel #f) '(0 1 . #t) '(2 3 . #t) '(4 5) #t) '(0 1 2 3 4 5 . #f)) (= (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 . #f)) (equal? (pl-adjoin 4 '(0 1 2 3 #f)) '(4 0 1 2 3 #f)) (equal? (pl-adjoin 1 '(0 1 2 3)) '(0 1 2 3)) (equal? (pl-adjoin 1 '()) '(1)) (equal? (pl-remove-dups '(0 1 2 3 2 . 2)) '(0 1 3 2 . 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 (Some-sentinel #f) '(1 (2 3) . #t)) '(1 2 3 . #f)) (equal? (pl-flatten (No-sentinel) '(1 (2 (3 . #f) . #t) . #f)) '(1 2 3)) (pl-flatten (Some-sentinel #t) #f) (null? (pl-flatten (No-sentinel) #f)) (equal? (pl-collect (Some-sentinel #t) (add1 x) (x '(0 1 2 3 . #f))) ; map '(1 2 3 4 . #t)) (equal? (pl-collect (No-sentinel) (add1 x) (x '(0 1 2 3))) ; map '(1 2 3 4)) (equal? (pl-collect (Some-sentinel #t) x (x '(0 1 2 3 4 5 . #f) (odd? x))) ; filter '(1 3 5 . #t)) (equal? (pl-collect (No-sentinel) x (x '(0 1 2 3 4 5) (odd? x))) ; filter '(1 3 5)) (equal? (pl-collect (No-sentinel) (* 10 n) (n '(0 1 2 3 4 5) (positive? n) (even? n))) '(20 40)) (equal? (pl-collect (No-sentinel) (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 (Some-sentinel #t) (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) . #t)) ) (compound-test (PSEUDOLISTS) (pseudolists?) )