;;; -*- Mode: Lisp -*- ;;; ;;; $Header: /home/gene/library/website/docsrc/jmt/RCS/test.lisp,v 395.1 2008/04/20 17:25:47 gene Exp $ ;;; ;;; Copyright (c) 2004 by Gene Michael Stover. All rights reserved. ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU Lesser General Public License as ;;; published by the Free Software Foundation; either version 2.1 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 Lesser General Public ;;; License along with this program; if not, write to the Free Software ;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ;;; USA ;;; Programs to test "./jmt.lisp". ;;; To run all the test programs, evaluate "(check *tests*)". ;;; You can also run the test programs individually, like this: ;;; "(test0001)". (defvar *tests* nil) (setq *tests* nil) (defmacro deftest (name &rest args-doc-body) `(progn (setq *tests* (append *tests* (list ',name))) (defun ,name ,@args-doc-body))) (defun run-test (test-fn) (format t "~&~A" test-fn) (let ((rc (funcall test-fn))) (unless rc (format t "~&*** failed ***")) rc)) (defun check (lst) "Executes all the tests in LST until they all execute or one of them fails." (do ((x lst (rest x))) ((or (endp x) (not (run-test (first x))))))) (deftest test0000 () "Null test. Always succeeds." t) (deftest test0001 () "Test that we can call MT-GENRAND without crashing." (mt-genrand) t) (deftest test0002 () "Test that we can call MT-RANDOM with N = 10 without crashing." (mt-random 10) t) (deftest test0003 () "Test that we can call MT-RANDOM with N = 1.0 without crashing." (mt-random 1.0) t) (deftest test0004 () "Test that MT-RANDOM always returns 0 <= R <= LIMIT for a LIMIT of 10 & where 'always' is sort of a statistical thing: We actually call MT-RANDOM just 10,000 times." (do ((count 10000) (limit 10) (i 0 (1+ i)) (r 0 (mt-random limit))) ((or (>= i count) (< r 0) (< limit r)) (cond ((and (<= 0 r) (< r limit)) t) ; good (t (format t "~&error:") (format t " ~A returned ~D," 'mt-random r) (if (< r 0) (format t " which is less than zero & should not be.") (format t " which is ~A ~D & should be less." (if (= r limit) "equal to" "greater than") limit)) (format t "~&(~A is ~A.)" 'i i) nil))))) (deftest test0005 () "Test that we can call MT-RANDOM with a limit that's a bignum without crashing." (mt-random (1+ (expt 2 65))) t) (deftest test0006 () "Like TEST0004 but uses a bignum for the limit." (do ((count 10000) (limit (1+ (expt 2 65))) (i 0 (1+ i)) (r 0 (mt-random limit))) ((or (>= i count) (< r 0) (< limit r)) (cond ((and (<= 0 r) (< r limit)) t) ; good (t (format t "~&error:") (format t " ~A returned ~D," 'mt-random r) (if (< r 0) (format t " which is less than zero & should not be.") (format t " which is ~A ~D & should be less." (if (= r limit) "equal to" "greater than") limit)) (format t "~&(~A is ~A.)" 'i i) nil))))) (deftest test0007 () "Test that MT-RANDOM doesn't crash when the limit is a floating point number." (mt-random 17.5) t) (deftest test0008 () "Like TEST0004 but the limit is a floating point number." (do ((count 10000) (limit 17.0) (i 0 (1+ i)) (r 0 (mt-random limit))) ((or (>= i count) (< r 0) (< limit r)) (cond ((and (<= 0 r) (< r limit)) t) ; good (t (format t "~&error:") (format t " ~A returned ~D," 'mt-random r) (if (< r 0) (format t " which is less than zero & should not be.") (format t " which is ~A ~D & should be less." (if (= r limit) "equal to" "greater than") limit)) (format t "~&(~A is ~A.)" 'i i) nil))))) ;;; --- end of file ---