From 69c6dec7a7099ff15316977aabbd30a5ce921784 Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Wed, 14 Nov 2007 08:59:16 +0100 Subject: [PATCH] Fix up the numerical testing infrastructure. Both systems pass all tests. --- ls-demo.lisp | 5 +++-- unittests.lisp | 56 ++++++++++++++++++++++++-------------------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/ls-demo.lisp b/ls-demo.lisp index 7a24ad8..1e8803e 100644 --- a/ls-demo.lisp +++ b/ls-demo.lisp @@ -196,7 +196,7 @@ my-chol-decomp-test (binomial-pmf 1 3 0.4) ;;0.4320000000226171 (binomial-rand 5 3 0.4) ;;(2 2 0 1 2) -;;; OBJECT SYSTEM +;;;; OBJECT SYSTEM (in-package :ls-user) (defproto *test-proto*) @@ -205,7 +205,7 @@ my-chol-decomp-test (send *test-proto* :make-data) -;;; Testing +;;;; Testing (in-package :lisp-stat-unittests) (testsuites) @@ -215,6 +215,7 @@ my-chol-decomp-test ;;(failures) (describe (run-tests :suite 'lisp-stat-testsupport)) +(describe (run-tests :suite 'lisp-stat-testsupport2)) (testsuite-tests 'lisp-stat) (run-tests :suite 'lisp-stat) diff --git a/unittests.lisp b/unittests.lisp index fa43fd1..6faddf5 100644 --- a/unittests.lisp +++ b/unittests.lisp @@ -60,38 +60,32 @@ (defgeneric numerical= (a b &key tol)) (defmethod numerical= ((a real) (b real) &key (tol 0.00001)) ;; real)) - (print (format nil " equality pred for real a=~w real b=~w" a b)) + ;;(print (format nil " equality pred for real a=~w real b=~w" a b)) (< (abs (- a b)) tol)) +;; can we just worry about reals if integers are a subclass? (defmethod numerical= ((a integer) (b integer) &key (tol 0.1)) ;; real)) - (print (format nil " equality pred for int a=~w int b=~w" a b)) + ;;(print (format nil " equality pred for int a=~w int b=~w" a b)) (< (abs (- a b)) tol)) ;;(defmethod numerical= ((a complex) (b complex) &key (tol 0.00001)) ;; real)) ;; (< (abs (- a b)) tol)) -;; can we use sequence for both array and list? I think so. + (defmethod numerical= ((a sequence) (b sequence) &key (tol 0.00001)) (print (format nil "checking equality for list a ~w list b=~w" a b)) - (if (and (= (length a) (length b)) - (> (length a) 0) - (numerical= (car a) (car b) :tol tol)) - (progn - (numerical= (cdr a) (cdr b) :tol tol)) - nil)) -;; FIXME++++ This is too slow, a few too many comparisons. - -(numerical= (list 2.0 2.0 2.2) (list 2.1 2.0 2.2)) -(numerical= (list 2.1 2.0 2.2) (list 2.1 2.0 2.2)) - -(numerical= (list 2.1 2.0 2.2 4.2) (list 2.1 2.0 2.2 4.2)) -(numerical= (list 2.1 2.0 2.3 4.0) (list 2.1 2.0 2.2 4.0)) - -(let ((a (list 2.1 2.0 2.2 4.2)) - (b (list 2.0 2.1 2.2 4.2))) - (and (= (length a) (length b)) - (numerical= (car a) (car b)))) - + ;; using sequence for both array and lists -- need to check multi-dim arrays + ;; FIXME++++ This is too slow, too many comparisons! + (if (and (null a) (null b)) + t + (if (and (= (length a) (length b)) + (> (length a) 0) + (numerical= (car a) (car b) :tol tol)) + (progn + (if (= (length (cdr a)) 0) + t + (numerical= (cdr a) (cdr b) :tol tol))) + nil))) ;; (defmethod numerical= ((complex a) (complex b) &key (tol 0.00001)) ;; (defmethod numerical= ((list a) (list b) &key (tol 0.00001)) @@ -116,25 +110,23 @@ () (:tests (numerical=1 (ensure (numerical= 3 3.001 :tol 0.01))) + (numerical=1.1 (ensure (numerical= 2 2))) + (numerical=1.2 (ensure (not (numerical= 2 3)))) (numerical=2 (ensure (numerical= 3 3.01 :tol 0.01))) (numerical=3 (ensure (not (numerical= 3 3.1 :tol 0.01)))) (numerical=4 (ensure (numerical= nil nil :tol 0.01))) (numerical=5 (ensure (numerical= (list ) (list ) :tol 0.01))) (numerical=6 (ensure (numerical= (list 1.0) (list 1.0) :tol 0.01))) (numerical=7 (ensure (numerical= (list 1.0 1.0) (list 1.0 1.0) :tol 0.01))) - (numerical=8 (ensure (not (numerical= (list 1.0 1.0) + (numerical=7.5 (ensure-error (numerical= 1.0 (list 1.0 1.0) :tol 0.01))) + (numerical=8 (ensure (not (numerical= (list 2.0 2.0 2.2) (list 2.1 2.0 2.2))))) + (numerical=9 (ensure (numerical= (list 2.1 2.0 2.2) (list 2.1 2.0 2.2)) )) + (numerical=10 (ensure (numerical= (list 2.1 2.0 2.2 4.2) (list 2.1 2.0 2.2 4.2)))) + (numerical=11 (ensure (not (numerical= (list 2.1 2.0 2.3 4.0) (list 2.1 2.0 2.2 4.0))))) + (numerical=12 (ensure (not (numerical= (list 1.0 1.0) (list 1.0 1.1) :tol 0.01)))))) -(numerical= 2.0 2.0) -(numerical= 2.0 2.1) -(numerical= 2.0 2.1 :tol 0.5) -(numerical= 2 2) -(numerical= 2 3) -;;(numerical= 2.0 (list 2.1 2.0 2.2)) - - - (addtest (lisp-stat-lin-alg) cholesky-decomposition-1 (ensure-same -- 2.11.4.GIT