run-tests.ss
#lang scheme
(require "main.ss"
         (planet schematics/schemeunit))

(check-true (empty? empty))
(check-false (empty? (cons 9 empty)))
(check-false (empty? 'your-mom))

(check-true (cons? (cons 9 empty)))
(check-false (cons? empty))
(check-false (cons? 'your-mom))

(check-true (list? empty))
(check-true (list? (cons 9 empty)))
(check-false (list? 'your-mom))

(check-equal? (first (cons 9 empty)) 9)
(check-equal? (rest (cons 9 empty)) empty)

(check-equal? (list-ref (cons 9 empty) 0) 9)
(check-equal? (list-set (cons 9 empty) 0 4)
              (cons 4 empty))

(check-equal? (list-ref (list 'a 'b 'c 'd 'e) 2) 'c)
(check-equal? (list-set (list 'a 'b 'c 'd 'e) 2 'f)
              (list 'a 'b 'f 'd 'e))

(let-values ([(v l) (list-ref/set (list 'a 'b 'c 'd 'e) 2 'f)])
  (check-equal? v 'c)
  (check-equal? l (list 'a 'b 'f 'd 'e)))

(check-equal? (list) empty)
(check-equal? (list 1 2 3) (cons 1 (cons 2 (cons 3 empty))))

(check-equal? (build-list 0 (lambda (i) i)) empty)
(check-equal? (build-list 5 (lambda (i) i))
              (list 0 1 2 3 4))
(check-equal? (build-list 5 add1)
              (list 1 2 3 4 5))

(check-equal? (map add1 empty) empty)
(check-equal? (map add1 (list 0 1 2 3 4))
              (list 1 2 3 4 5))

(check-equal? (foldl + 0 empty) 0)
(check-equal? (foldl + 0 (list 1 2 3)) 6)
(check-equal? (foldl cons empty empty) empty)
(check-equal? (foldl cons empty (list 0 1 2 3 4))
              (list 4 3 2 1 0))

(check-equal? (foldr + 0 empty) 0)
(check-equal? (foldr + 0 (list 1 2 3)) 6)
(check-equal? (foldr cons empty empty) empty)
(check-equal? (foldr cons empty (list 0 1 2 3 4))
              (list 0 1 2 3 4))

(check-exn exn? (λ () (cons 9 9)))
(check-exn exn? (λ () (first empty)))
(check-exn exn? (λ () (list-ref empty 0)))
(check-exn exn? (λ () (list-ref (cons 9 empty) 1)))
(check-exn exn? (λ () (list-set empty 0)))
(check-exn exn? (λ () (list-set (cons 9 empty) 1)))


(define (ra:foldl f b ls)
  (cond [(empty? ls) b]
        [else (ra:foldl f (f (first b) b) (rest ls))]))