Commit f42d6f00 authored by Liam Healy's avatar Liam Healy

Tests in separate system gsll-tests

Tests are now separated from examples and defined in a new system
gsll-tests.  Change name of condition 'input-error from 'EDOM.
parent 9b15d4b5
;; Definition of GSLL system
;; Liam Healy
;; Time-stamp: <2008-11-16 13:29:58EST gsll-tests.asd>
;; $Id$
(asdf:defsystem "gsll-tests"
:name "gsll-tests"
:description "Regression (unit) tests for GNU Scientific Library for Lisp."
:version "0"
:author "Liam M. Healy"
:licence "LLGPL v3, FDL"
:depends-on (gsll)
:components
((:module test-unit
:components
;; http://www.cs.northwestern.edu/academics/courses/325/readings/lisp-unit.html
((:file "lisp-unit")
(:file "additional-definitions" :depends-on (lisp-unit))))
(:module tests
:depends-on (test-unit)
:components
((:file "absolute-deviation")
(:file "absolute-sum")
(:file "airy")
(:file "autocorrelation")
(:file "axpy")
(:file "bernoulli")
(:file "bessel")
(:file "beta")
(:file "binomial")
(:file "blas-copy")
(:file "blas-swap")
(:file "cauchy")
(:file "cdot")
(:file "chebyshev")
(:file "chi-squared")
(:file "clausen")
(:file "column")
(:file "combination")
(:file "coulomb")
(:file "coupling")
(:file "covariance")
(:file "dawson")
(:file "debye")
(:file "dilogarithm")
(:file "dirichlet")
(:file "discrete")
(:file "dot")
(:file "eigensystems")
(:file "elementary")
(:file "elliptic-functions")
(:file "elliptic-integrals")
(:file "error-functions")
(:file "euclidean-norm")
(:file "exponential-functions")
(:file "exponential-integrals")
(:file "exponential")
(:file "exponential-power")
(:file "fdist")
(:file "fermi-dirac")
(:file "flat")
(:file "gamma")
(:file "gamma-randist")
(:file "gaussian-bivariate")
(:file "gaussian")
(:file "gaussian-tail")
(:file "gegenbauer")
(:file "geometric")
(:file "givens")
(:file "gumbel1")
(:file "gumbel2")
(:file "higher-moments")
(:file "histogram")
(:file "hypergeometric")
(:file "hypergeometric-randist")
(:file "index-max")
(:file "inverse-matrix-product")
(:file "laguerre")
(:file "lambert")
(:file "landau")
(:file "laplace")
(:file "legendre")
(:file "levy")
(:file "logarithmic")
(:file "logarithm")
(:file "logistic")
(:file "lognormal")
(:file "lu")
(:file "mathematical")
(:file "matrix-copy")
(:file "matrix-div")
(:file "matrix-max-index")
(:file "matrix-max")
(:file "matrix-mean")
(:file "matrix-min-index")
(:file "matrix-minmax-index")
(:file "matrix-minmax")
(:file "matrix-m-")
(:file "matrix-m+")
(:file "matrix-mult")
(:file "matrix-product-hermitian")
(:file "matrix-product")
(:file "matrix-product-symmetric")
(:file "matrix-product-triangular")
(:file "matrix-set-all-m+")
(:file "matrix-set-zero")
(:file "matrix-standard-deviation")
(:file "matrix-standard-deviation-with-fixed-mean")
(:file "matrix-standard-deviation-with-mean")
(:file "matrix-swap")
(:file "matrix-transpose-copy")
(:file "matrix-transpose")
(:file "matrix-variance")
(:file "matrix-variance-with-fixed-mean")
(:file "matrix-variance-with-mean")
(:file "median-percentile")
(:file "monte-carlo")
(:file "multinomial")
(:file "negative-binomial")
(:file "numerical-differentiation")
(:file "numerical-integration")
(:file "pareto")
(:file "permutation")
(:file "poisson")
(:file "polynomial")
(:file "power")
(:file "psi")
(:file "quasi-random-number-generators")
(:file "random-number-generators")
(:file "rayleigh")
(:file "rayleigh-tail")
(:file "row")
(:file "scale")
(:file "set-basis")
(:file "setf-column")
(:file "setf-row")
(:file "set-identity")
(:file "shuffling-sampling")
(:file "sort-matrix-largest")
(:file "sort-matrix")
(:file "sort-matrix-smallest")
(:file "sort-vector-index")
(:file "sort-vector-largest-index")
(:file "sort-vector-largest")
(:file "sort-vector")
(:file "sort-vector-smallest-index")
(:file "sort-vector-smallest")
(:file "spherical-vector")
(:file "swap-columns")
(:file "swap-elements")
(:file "swap-row-column")
(:file "swap-rows")
(:file "synchrotron")
(:file "tdist")
(:file "transport")
(:file "trigonometry")
(:file "vector-copy")
(:file "vector-div")
(:file "vector-max-index")
(:file "vector-max")
(:file "vector-mean")
(:file "vector-min-index")
(:file "vector-minmax-index")
(:file "vector-minmax")
(:file "vector-m-")
(:file "vector-m+")
(:file "vector-mult")
(:file "vector-reverse")
(:file "vector-set-all-m+")
(:file "vector-set-zero")
(:file "vector-standard-deviation")
(:file "vector-standard-deviation-with-fixed-mean")
(:file "vector-standard-deviation-with-mean")
(:file "vector-swap")
(:file "vector-variance")
(:file "vector-variance-with-fixed-mean")
(:file "vector-variance-with-mean")
(:file "weibull")
(:file "zeta")))))
;; Definition of GSLL system ;; Definition of GSLL system
;; Liam Healy ;; Liam Healy
;; Time-stamp: <2008-11-15 13:41:12EST gsll.asd> ;; Time-stamp: <2008-11-16 12:14:14EST gsll.asd>
;; $Id$ ;; $Id$
(asdf:defsystem "gsll" (asdf:defsystem "gsll"
...@@ -22,10 +22,7 @@ ...@@ -22,10 +22,7 @@
:depends-on (init conditions element-types number-conversion)) :depends-on (init conditions element-types number-conversion))
(:file "defmfun" :depends-on (init element-types interface)) (:file "defmfun" :depends-on (init element-types interface))
(:file "callback" :depends-on (init)) (:file "callback" :depends-on (init))
;; http://www.cs.northwestern.edu/academics/courses/325/readings/lisp-unit.html (:file "generate-examples" :depends-on (init))))
(:file "lisp-unit")
(:file "tests" :depends-on (init lisp-unit))
(:file "generate-tests" :depends-on (tests))))
(:module floating-point (:module floating-point
:depends-on (init) :depends-on (init)
:components :components
......
;; Histogram probability distribution. ;; Histogram probability distribution.
;; Liam Healy, Mon Jan 1 2007 - 17:51 ;; Liam Healy, Mon Jan 1 2007 - 17:51
;; Time-stamp: <2008-08-17 09:37:15EDT probability-distribution.lisp> ;; Time-stamp: <2008-11-16 13:26:02EST probability-distribution.lisp>
;; $Id$ ;; $Id$
(in-package :gsl) (in-package :gsl)
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
:documentation ; FDL :documentation ; FDL
"Initialize the probability distribution pdf with the contents "Initialize the probability distribution pdf with the contents
of the histogram. If any of the bins are negative then an of the histogram. If any of the bins are negative then an
EDOM error is signalled because a probability distribution input-domain error is signalled because a probability distribution
cannot contain negative values.") cannot contain negative values.")
(defmfun pdf-init-2 (pdf histogram) (defmfun pdf-init-2 (pdf histogram)
...@@ -71,14 +71,14 @@ ...@@ -71,14 +71,14 @@
:documentation ; FDL :documentation ; FDL
"Initialize the probability distribution pdf with the contents "Initialize the probability distribution pdf with the contents
of the histogram. If any of the bins are negative then an of the histogram. If any of the bins are negative then an
EDOM error is signalled because a probability distribution input-domain error is signalled because a probability distribution
cannot contain negative values.") cannot contain negative values.")
(export 'pdf-init) (export 'pdf-init)
(defun pdf-init (pdf histogram) ; FDL (defun pdf-init (pdf histogram) ; FDL
"Initialize the probability distribution pdf with the contents "Initialize the probability distribution pdf with the contents
of the histogram. If any of the bins are negative then an of the histogram. If any of the bins are negative then an
EDOM error is signalled because a probability distribution input-domain error is signalled because a probability distribution
cannot contain negative values." cannot contain negative values."
(histo-1d2d pdf pdf-init (histogram))) (histo-1d2d pdf pdf-init (histogram)))
......
;; Updating and accessing histogram elements. ;; Updating and accessing histogram elements.
;; Liam Healy, Mon Jan 1 2007 - 14:43 ;; Liam Healy, Mon Jan 1 2007 - 14:43
;; Time-stamp: <2008-10-25 18:24:41EDT updating-accessing.lisp> ;; Time-stamp: <2008-11-16 13:26:01EST updating-accessing.lisp>
;; $Id$ ;; $Id$
(in-package :gsl) (in-package :gsl)
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
If x lies in the valid range of the histogram then the function If x lies in the valid range of the histogram then the function
returns zero to indicate success. If x is less than the lower returns zero to indicate success. If x is less than the lower
limit of the histogram then the function issues a warning :EDOM, and limit of the histogram then the function issues a warning input-domain, and
none of bins are modified. Similarly, if the value of x is greater none of bins are modified. Similarly, if the value of x is greater
than or equal to the upper limit of the histogram then the function than or equal to the upper limit of the histogram then the function
issues a warning :EDOM, and none of the bins are modified. The error issues a warning input-domain, and none of the bins are modified. The error
handler is not called, however, since it is often necessary to compute handler is not called, however, since it is often necessary to compute
histograms for a small range of a larger dataset, ignoring the values histograms for a small range of a larger dataset, ignoring the values
outside the range of interest.") outside the range of interest.")
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
:documentation ; FDL :documentation ; FDL
"Return the contents of the i-th bin of the histogram. "Return the contents of the i-th bin of the histogram.
If i lies outside the valid range of indices for the If i lies outside the valid range of indices for the
histogram then an error (:EDOM) is signalled.") histogram then an error (input-domain) is signalled.")
(defmfun range (histogram i) (defmfun range (histogram i)
"gsl_histogram_get_range" "gsl_histogram_get_range"
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
the coordinate of the upper limit are excluded and fall in the the coordinate of the upper limit are excluded and fall in the
neighboring higher bin, if it exists). neighboring higher bin, if it exists).
If i lies outside the valid range of indices for If i lies outside the valid range of indices for
the histogram, then the error :EDOM is signalled.") the histogram, then the error input-domain is signalled.")
(defmfun max-range (histogram) (defmfun max-range (histogram)
"gsl_histogram_max" "gsl_histogram_max"
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
range, and will return the correct bin immediately in this range, and will return the correct bin immediately in this
case. If the value is found in the range of the histogram case. If the value is found in the range of the histogram
then the function returns the index. If value lies outside then the function returns the index. If value lies outside
the valid range of the histogram then the error :EDOM is the valid range of the histogram then the error input-domain is
signalled.") signalled.")
#| #|
......
;; GSL errors ;; GSL errors
;; Liam Healy Sat Mar 4 2006 - 18:33 ;; Liam Healy Sat Mar 4 2006 - 18:33
;; Time-stamp: <2008-08-31 22:52:09EDT conditions.lisp> ;; Time-stamp: <2008-11-16 13:26:03EST conditions.lisp>
;; $Id$ ;; $Id$
(in-package :gsl) (in-package :gsl)
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
(setf *errorno-keyword* (acons ,number ',keyword *errorno-keyword*)) (setf *errorno-keyword* (acons ,number ',keyword *errorno-keyword*))
(export ',keyword))) (export ',keyword)))
(define-gsl-condition EDOM 1 "Input domain error") (define-gsl-condition input-domain 1 "Input domain error")
(define-gsl-condition ERANGE 2 "Output range error") (define-gsl-condition ERANGE 2 "Output range error")
(define-gsl-condition EFAULT 3 "Invalid pointer") (define-gsl-condition EFAULT 3 "Invalid pointer")
(define-gsl-condition EINVAL 4 "Invalid argument") (define-gsl-condition EINVAL 4 "Invalid argument")
......
;; Make tests and examples ;; Define examples.
;; Liam Healy 2008-09-07 21:00:48EDT generate-tests.lisp ;; Liam Healy 2008-09-07 21:00:48EDT generate-tests.lisp
;; Time-stamp: <2008-11-15 13:29:28EST generate-tests.lisp> ;; Time-stamp: <2008-11-16 12:13:10EST generate-examples.lisp>
;; $Id: $ ;; $Id: $
;;; Througout the GSLL interface definition files are #'save-test ;;; Define examples that can be displayed by users with the function
;;; forms. These serve to define both examples and tests. Getting an ;;; #'examples and can be used to generate regression (unit) tests.
;;; example involves calling (examples) to get a list of names, then ;;; The latter has been done in the gsll-tests system.
;;; the calling the function with a particular name to get the
;;; examples, e.g.
;;; (examples)
;;; (examples 'matrix-m+)
;;; To do all the tests,
;;; (lisp-unit:run-tests)
;;; The files that define the tests are in tests/. These files are
;;; generated automatically and checked into the repository; they
;;; shouldn't be changed very often. Rarely, it may be necessary to
;;; generate such a file. In this case, #'write-test-to-file recreates
;;; the file, e.g.
;;; (write-test-to-file 'matrix-m+ "test/")
(in-package :gsl) (in-package :gsl)
(export 'examples) (export 'examples)
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Data pool ;;;; Defining examples
;;;;**************************************************************************** ;;;;****************************************************************************
(defun numerical-serialize (form)
(if (typep form 'list)
(cons 'list (mapcar #'numerical-serialize form))
form))
;;; (make-test '(legendre-conicalP-half 3.5d0 10.0d0))
(defun make-test (form)
"Make a test for lisp-unit."
(let ((vals (multiple-value-list (ignore-errors (eval form)))))
(if (typep (second vals) 'condition)
`(lisp-unit::assert-error
',(type-of (second vals))
,form)
`(lisp-unit::assert-numerical-equal
,(numerical-serialize vals)
(multiple-value-list ,form)))))
(defparameter *all-generated-tests* nil) (defparameter *all-generated-tests* nil)
(defmacro save-test (name &rest forms) (defmacro save-test (name &rest forms)
...@@ -71,52 +40,6 @@ ...@@ -71,52 +40,6 @@
(loop for (key value) on *all-generated-tests* by #'cddr (loop for (key value) on *all-generated-tests* by #'cddr
collect key))) collect key)))
(defun create-test (test-name)
"Find the saved test by name and create it, with the generated results."
(append
`(lisp-unit:define-test ,test-name)
(mapcar #'make-test (getf *all-generated-tests* test-name))))
(defun write-test-to-file (test path)
"Write the test to a file with the same name under path.
Use this function with caution; it will replace an existing
test file and thus the opportunity for regression test will be lost."
(let ((pathname (merge-pathnames (format nil "~(~a~).lisp" test) path))
(*read-default-float-format* 'single-float))
(with-open-file
(stream pathname :direction :output :if-exists :rename)
(format
stream
";; Regression test ~a for GSLL, automatically generated~%~%" test)
(format stream "(in-package :gsl)~%~%")
(format t "Writing test ~a to file ~a~&" test pathname)
(format stream "~s~%~%" (create-test test)))))
;;; This is commented out because it shouldn't be run. It will
;;; regenerate all tests, so there will be no regression tests to
;;; previous versions.
#+(or)
(defun write-tests (path)
"Write all the tests to the appropriate file."
(iter
(for (key val) on *all-generated-tests* by #'cddr)
(write-test-to-file key path)))
#|
;;; Obsolete; to put all tests in one file.
(defun write-tests-to-file (filename)
"Write all the saved tests with expected results to the file."
(with-open-file (stream filename :direction :output :if-exists :supersede)
(format stream ";; Regression tests for GSLL, automatically generated~%~%")
(format stream "(in-package :gsl)~%~%")
(loop for (test-name forms) on *all-generated-tests* by #'cddr
do
(format t "Writing test ~a to file~&" test-name)
(format stream "~s~%~%" (create-test test-name)))))
|#
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Data pool ;;;; Data pool
;;;;**************************************************************************** ;;;;****************************************************************************
......
;; Cholesky Decomposition ;; Cholesky Decomposition
;; Liam Healy, Wed May 3 2006 - 16:38 ;; Liam Healy, Wed May 3 2006 - 16:38
;; Time-stamp: <2008-08-11 22:49:09EDT cholesky.lisp> ;; Time-stamp: <2008-11-16 13:26:42EST cholesky.lisp>
;; $Id$ ;; $Id$
(in-package :gsl) (in-package :gsl)
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
L. The upper triangular part of the input matrix contains L. The upper triangular part of the input matrix contains
L^T, the diagonal terms being identical for both L and L^T, the diagonal terms being identical for both L and
L^T. If the matrix is not positive-definite then the L^T. If the matrix is not positive-definite then the
decomposition will fail, returning the error EDOM.") decomposition will fail, returning the error input-domain.")
(defmfun cholesky-solve (A x b) (defmfun cholesky-solve (A x b)
"gsl_linalg_cholesky_solve" "gsl_linalg_cholesky_solve"
......
;; Numerical differentiation. ;; Numerical differentiation.
;; Liam Healy Mon Nov 12 2007 - 22:07 ;; Liam Healy Mon Nov 12 2007 - 22:07
;; Time-stamp: <2008-10-25 12:00:36EDT numerical-differentiation.lisp> ;; Time-stamp: <2008-11-15 22:31:32EST numerical-differentiation.lisp>
;; $Id$ ;; $Id$
(in-package :gsl) (in-package :gsl)
...@@ -122,77 +122,4 @@ ...@@ -122,77 +122,4 @@
(forward-derivative deriv-f6 10.0d0 1.0d-4) (forward-derivative deriv-f6 10.0d0 1.0d-4)
(backward-derivative deriv-f6 10.0d0 1.0d-4)) (backward-derivative deriv-f6 10.0d0 1.0d-4))
(LISP-UNIT:DEFINE-TEST NUMERICAL-DIFFERENTIATION
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.718281828441488 4.123659913167868e-10)
(MULTIPLE-VALUE-LIST
(CENTRAL-DERIVATIVE DERIV-F1 1.0 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.7182817825298398 9.540320743340577e-7)
(MULTIPLE-VALUE-LIST
(FORWARD-DERIVATIVE DERIV-F1 1.0 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.7182818293827378 9.086969640080628e-7)
(MULTIPLE-VALUE-LIST
(BACKWARD-DERIVATIVE DERIV-F1 1.0 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.474341649024533 3.3922603135575853e-11)
(MULTIPLE-VALUE-LIST
(CENTRAL-DERIVATIVE DERIV-F2 0.1 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.47434164943235285 9.102230432046565e-8)
(MULTIPLE-VALUE-LIST
(FORWARD-DERIVATIVE DERIV-F2 0.1 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.4743416462049176 8.787851752748856e-8)
(MULTIPLE-VALUE-LIST
(BACKWARD-DERIVATIVE DERIV-F2 0.1 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.9941773945923913 6.730277498876722e-10)
(MULTIPLE-VALUE-LIST
(CENTRAL-DERIVATIVE DERIV-F3 0.45 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.994177385772526 1.6952086150997503e-6)
(MULTIPLE-VALUE-LIST
(FORWARD-DERIVATIVE DERIV-F3 0.45 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.9941775182635064 1.568063267060477e-6)
(MULTIPLE-VALUE-LIST
(BACKWARD-DERIVATIVE DERIV-F3 0.45 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST -0.7788007830653751 1.7227267499194736e-10)
(MULTIPLE-VALUE-LIST
(CENTRAL-DERIVATIVE DERIV-F4 0.5 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST -0.7788007884386108 2.530006603059119e-7)
(MULTIPLE-VALUE-LIST
(FORWARD-DERIVATIVE DERIV-F4 0.5 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST -0.7788007743421791 2.503617930568489e-7)
(MULTIPLE-VALUE-LIST
(BACKWARD-DERIVATIVE DERIV-F4 0.5 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.0 6.66133814775094e-20)
(MULTIPLE-VALUE-LIST
(CENTRAL-DERIVATIVE DERIV-F5 0.0 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST -2.6337311035821125e-26 1.606762230663824e-11)
(MULTIPLE-VALUE-LIST
(FORWARD-DERIVATIVE DERIV-F5 0.0 1.e-4)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 2.6337311035821125e-26 1.606762230663824e-11)
(MULTIPLE-VALUE-LIST