* fixed and wrote test for lambda and function as arg case

* added license to userlib tests
* added map impl to userlib
* userlib tests now run and pass
* all args are evaluated individually
This commit is contained in:
Ava Apples Affine 2023-03-20 16:22:51 -07:00
parent 8a91560921
commit dcb2969b0a
Signed by: affine
GPG key ID: 3A4645B8CF806069
7 changed files with 148 additions and 40 deletions

View file

@ -1,11 +1,30 @@
#!/bin/relish
;; relish: versatile lisp shell
;; Copyright (C) 2021 Aidan Hahn
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; USERLIB-TESTS
;; this file implements unit tests for handwritten userlib functions
(def passed
(def passed
'prints if a test has passed'
(test)
(echo (concat "PASSED: " test)))
(def failed
(def failed
'prints if a test has failed'
(test)
(echo (concat "FAILED: " test)))
@ -14,30 +33,32 @@
(('set updates var'
(quote
(let ((test-val 0))
(set test-val 3)
(set (q test-val) 3)
(eq? test-val 3))))
('prepend prepends to list'
(quote
(let ((list (2 3 4))
(list (prepend 1 list))
(list-head (head list)))
(list-head (pop list)))
(eq? (car list-head) 1))))
('map applies function across list'
(quote
(let ((list (1 2 3))
(adder (lambda (x) (add 1 x))))
(eq? (map adder list) (2 3 4)))))
;; add more test cases here
))
(def test-iter 'iterates over test cases'
(head test-cases))
;; run all test cases, print output
(while (gt? (len (cdr test-iter))
0)
(let ((test (car test-iter))
(remaining (cdr test-iter))
(test-name (car test))
(test-body (cdr test)))
(if (eval test-body)
(passed test-name)
(failed test-name))
(def test-iter '' (head remaining))))
(let ((test-iter (pop test-cases)))
(while (gt? (len test-iter) 1)
(let ((test (car test-iter))
(remaining (cdr test-iter))
(test-name (car test))
(test-body (cdr test)))
(if (eval test-body)
(passed test-name)
(failed test-name))
(set (q test-iter) (pop remaining)))))