UNSLISP/tests.scm

77 lines
2.2 KiB
Scheme

;;; Copyright (C) Peter McGoron 2024
;;; 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, version 3 of the License.
;;;
;;; 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 <https://www.gnu.org/licenses/>.
;;; Test harness.
;;; Each test is a name and a function with no arguments. The function
;;; returns #t for success, #f for undefined failure, and a string for
;;; known failure.
;;;
;;; TODO: Return test results as a list.
(load "util.scm")
(define verbose? #t)
(define run-tests
(lambda (tests)
(letrec
((run-test
(lambda (name test)
(if verbose?
(begin
(display "running: ")
(display name)
(newline))
#f)
(let ((result (test)))
(if (not result)
"undefined failure"
result))))
(loop
(lambda (rest)
(if (null? rest)
#t
(let ((descr (car rest)))
(let ((return (run-test
(car descr)
(cdr descr))))
(if (not (eq? return #t))
return
(loop (cdr rest)))))))))
(loop tests))))
(define report-tests
(lambda (tests)
(let ((res (run-tests tests)))
(if (eq? res #t)
(display "passed")
(begin
(display "failed: ")
(display res))))
(newline)))
(load "doubly-linked-list.scm")
(display "running doubly linked list tests: ")
(newline)
(report-tests %dl:tests)
(load "set.scm")
(display "running string BST-AVL tests")
(newline)
(report-tests %set:tests)
(load "trie.scm")
(display "char trie")
(newline)
(report-tests %trie:tests)