2021-04-02 20:01:43 +02:00
|
|
|
(let ((lst (list 1 2 3)))
|
|
|
|
(write "# lst = ") (write-line lst)
|
|
|
|
(expect "Length of list is 3" (= (length lst) 3))
|
|
|
|
(expect "First element is 1" (= (first lst) 1))
|
|
|
|
(expect "Second element is 2" (= (second lst) 2))
|
|
|
|
(expect "Third element is 3" (= (nth 2 lst) 3))
|
2021-04-02 20:18:42 +02:00
|
|
|
(expect "Equal to itself" (equal lst lst))
|
|
|
|
(expect "Equal to identical list" (equal lst (list 1 2 3)))
|
2021-04-02 20:53:12 +02:00
|
|
|
(expect "Not equal to different list" (not (equal lst (list 2 3 4))))
|
2021-04-02 20:18:42 +02:00
|
|
|
(expect "Reduce with +" (= (reduce + lst) 6))
|
|
|
|
(expect "Map doubling values" (equal (map (lambda (x) (* x 2)) lst) (list 2 4 6)))
|
2021-04-02 20:01:43 +02:00
|
|
|
)
|
2021-04-02 20:53:12 +02:00
|
|
|
|
|
|
|
(expect "equal tests recursively 1"
|
|
|
|
(equal (list (list 1) (list 2)) (list (list 1) (list 2))))
|
|
|
|
|
|
|
|
(expect "equal tests recursively 2"
|
|
|
|
(not (equal (list (list 1) (list 2)) (list (list 1) (list 3)))))
|
2021-04-03 18:05:59 +02:00
|
|
|
|
|
|
|
(expect "Length of empty list is 0"
|
|
|
|
(zerop (length (list))))
|
|
|
|
|
|
|
|
(expect "cons adds elements to the front"
|
|
|
|
(equal (list 1 2) (cons 1 (list 2))))
|
|
|
|
|
|
|
|
(let ((lst (list 5 1 2)))
|
|
|
|
(expect "car gives first element"
|
|
|
|
(= 5 (car lst)))
|
|
|
|
(expect "cdr gives rest of list"
|
|
|
|
(equal (list 1 2) (cdr lst))))
|
2021-04-03 18:09:20 +02:00
|
|
|
|
|
|
|
(expect "short notation equals list created with list function"
|
|
|
|
(equal '(1 2) (list 1 2)))
|
|
|
|
|
|
|
|
(expect "short notation can create empty lists"
|
|
|
|
(zerop (length '())))
|