Commit e9017ff3 by Liam Healy

Replace random/gaussian tests with GSL tests

The tests for #'ugaussian-p, #'ugaussian-q, #'ugaussian-pinv, #'ugaussian-qinv are automatically converted from the GSL tests instead of converted from the examples.
parent 14968147
;; Convert the GSL tests
;; Liam Healy 2010-05-22 13:03:53EDT convert.lisp
;; Time-stamp: <2010-05-22 16:18:38EDT convert.lisp>
;; Time-stamp: <2010-05-22 16:43:04EDT convert.lisp>
;;; This file is not normally loaded; it is only used to convert the
;;; GSL tests in C to CL tests. It requires cl-ppcre and iterate.
;;; GSL tests in C to CL tests. It requires cl-ppcre, lisp-util, and iterate.
;;; (convert-tests-in-file "/home/liam/mathematics/gsl/cdf/test.c")
(in-package :gsl)
......@@ -14,29 +15,33 @@
The first character of the string should be
open paren, and the last the close paren."
(cons 'assert-to-tolerance
(read-from-string
(remove
#\, ; Get rid of commas
(cl-ppcre:regex-replace ; Replace function name
"\\((\\w*)\\W*\\((.*\\))"
(cl-ppcre:regex-replace-all ; Floats without exponents become double-floats
"(\\.\\d*)(,|\\))"
(cl-ppcre:regex-replace-all ; Floats with "e" exponent become double-floats
"(\\d|\\.)e(\\d|\\+|\\-)"
(cl-ppcre:regex-replace ; Replace tolerance
"TEST_(\\w*)"
string
"+TEST-\\{1}+")
"\\{1}d\\{2}")
"\\{1}d0\\{2}")
(lambda (match &rest registers)
(declare (ignore match))
(format
nil
"((~a ~a"
(symbol-name (gsl-lookup (first registers)))
(second registers)))
:simple-calls t)))))
(let ((ppcre-convert
(read-from-string
(remove
#\, ; Get rid of commas
(cl-ppcre:regex-replace ; Replace function name
"\\((\\w*)\\W*\\((.*\\))"
(cl-ppcre:regex-replace-all ; Floats without exponents become double-floats
"(\\.\\d*)(,|\\))"
(cl-ppcre:regex-replace-all ; Floats with "e" exponent become double-floats
"(\\d|\\.)e(\\d|\\+|\\-)"
(cl-ppcre:regex-replace ; Replace tolerance
"TEST_(\\w*)"
string
"+TEST-\\{1}+")
"\\{1}d\\{2}")
"\\{1}d0\\{2}")
(lambda (match &rest registers)
(declare (ignore match))
(format
nil
"((~a ~a"
(symbol-name (gsl-lookup (first registers)))
(second registers)))
:simple-calls t)))))
(if (and (numberp (lu:last1 ppcre-convert)) (zerop (lu:last1 ppcre-convert)))
(append (butlast ppcre-convert) (list '+dbl-epsilon+))
ppcre-convert))))
(defun GSL-test-form (string)
"Replace the full C form with the TEST macro by just the argument."
......
......@@ -19,45 +19,114 @@
(in-package :gsl)
(LISP-UNIT:DEFINE-TEST GAUSSIAN
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST
(LIST 1.3391860811867589d0 -0.8810099183143839d0
16.744084062537738d0 7.336411072925795d0
9.975246316020124d0 -12.775020810027664d0
-23.967152827332075d0 -6.79280164729211d0
-0.3909131843358723d0 8.935555455208181d0
-0.17647794589783283d0))
(MULTIPLE-VALUE-LIST
(LET ((RNG (MAKE-RANDOM-NUMBER-GENERATOR +MT19937+ 0)))
(LOOP FOR I FROM 0 TO 10 COLLECT
(sample rng :gaussian :sigma 10.0d0)))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.039894228040143274d0)
(MULTIPLE-VALUE-LIST (GAUSSIAN-PDF 0.0d0 10.0d0)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST
(LIST 7.648734260124924d0 -11.307312946196086d0
4.523361654215173d0 -4.5181725947577185d0
13.64676540828912d0 3.553650119391929d0
-5.567035948404032d0 10.097727863788887d0
2.519120940798607d0 -9.024585521868676d0
-9.463283369593537d0))
(MULTIPLE-VALUE-LIST
(LET ((RNG (MAKE-RANDOM-NUMBER-GENERATOR +MT19937+ 0)))
(LOOP FOR I FROM 0 TO 10 COLLECT
(sample rng :gaussian-ziggurat :sigma 10.0d0)))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.9772498680518208d0)
(MULTIPLE-VALUE-LIST (UGAUSSIAN-P 2.0d0)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.022750131948179212d0)
(MULTIPLE-VALUE-LIST (UGAUSSIAN-Q 2.0d0)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL (LIST 2.0d0)
(MULTIPLE-VALUE-LIST
(UGAUSSIAN-PINV
0.9772498680518208d0)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL (LIST 2.0d0)
(MULTIPLE-VALUE-LIST
(UGAUSSIAN-QINV
0.02275013194817921d0))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST
(LIST 1.3391860811867589d0 -0.8810099183143839d0
16.744084062537738d0 7.336411072925795d0
9.975246316020124d0 -12.775020810027664d0
-23.967152827332075d0 -6.79280164729211d0
-0.3909131843358723d0 8.935555455208181d0
-0.17647794589783283d0))
(MULTIPLE-VALUE-LIST
(LET ((RNG (MAKE-RANDOM-NUMBER-GENERATOR +MT19937+ 0)))
(LOOP FOR I FROM 0 TO 10 COLLECT
(sample rng :gaussian :sigma 10.0d0)))))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST 0.039894228040143274d0)
(MULTIPLE-VALUE-LIST (GAUSSIAN-PDF 0.0d0 10.0d0)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LIST
(LIST 7.648734260124924d0 -11.307312946196086d0
4.523361654215173d0 -4.5181725947577185d0
13.64676540828912d0 3.553650119391929d0
-5.567035948404032d0 10.097727863788887d0
2.519120940798607d0 -9.024585521868676d0
-9.463283369593537d0))
(MULTIPLE-VALUE-LIST
(LET ((RNG (MAKE-RANDOM-NUMBER-GENERATOR +MT19937+ 0)))
(LOOP FOR I FROM 0 TO 10 COLLECT
(sample rng :gaussian-ziggurat :sigma 10.0d0)))))
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 0.0d0) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 1.d-32) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 1.d-16) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 1.d-8) 0.5000000039894228d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 0.5d0) 0.6914624612740131d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 0.7d0) 0.758036347776927d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 5.0d0) 0.9999997133484281d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 10.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 30.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 40.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P 1.d10) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -1.d-32) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -1.d-16) 0.49999999999999994d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -1.d-8) 0.4999999960105772d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -0.5d0) 0.3085375387259869d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -0.7d0) 0.241963652223073d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -5.0d0) 2.866515718791939d-7 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -10.0d0) 7.619853024160525d-24 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -30.0d0) 4.906713927148187d-198 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-P -1.d10) 0.0d0 +DBL-EPSILON+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 0.0d0) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 1.d-32) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 1.d-16) 0.49999999999999994d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 1.d-8) 0.4999999960105772d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 0.5d0) 0.3085375387259869d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 0.7d0) 0.241963652223073d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 5.0d0) 2.866515718791939d-7 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 10.0d0) 7.619853024160525d-24 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 30.0d0) 4.906713927148187d-198 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q 1.d10) 0.0d0 +DBL-EPSILON+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -1.d-32) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -1.d-16) 0.5d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -1.d-8) 0.5000000039894228d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -0.5d0) 0.6914624612740131d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -0.7d0) 0.758036347776927d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -5.0d0) 0.9999997133484281d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -10.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -30.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -40.0d0) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-Q -1.d10) 1.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.9999997133d0) 5.0d0 1.d-4)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.9999683288d0) 4.0d0 1.d-6)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.998650102d0) 3.0d0 1.d-8)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.977249868051821d0) 2.0d0 1.d-14)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.841344746068543d0) 1.0d0 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.691462461274013d0) 0.5d0 +TEST-TOL2+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.655421741610324d0) 0.4d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.617911422188953d0) 0.3d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.579259709439103d0) 0.2d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.539827837277029d0) 0.1d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.5d0) 0.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.460172162722971d0) -0.1d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.420740290560897d0) -0.2d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.382088577811047d0) -0.3d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.344578258389676d0) -0.4d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.308537538725987d0) -0.5d0 +TEST-TOL2+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.158655253931457d0) -1.0d0 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.022750131948179d0) -2.0d0 1.d-14)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 0.001349898d0) -3.0d0 1.d-8)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 3.16712d-5) -4.0d0 1.d-6)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 2.86648d-7) -5.0d0 1.d-4)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-PINV 7.61985302416052d-24) -10.0d0 1.d-4)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 7.61985302416052d-24) 10.0d0 1.d-4)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 2.86648d-7) 5.0d0 1.d-4)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 3.16712d-5) 4.0d0 1.d-6)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.001349898d0) 3.0d0 1.d-8)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.022750131948179d0) 2.0d0 1.d-14)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.158655253931457d0) 1.0d0 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.308537538725987d0) 0.5d0 +TEST-TOL2+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.344578258389676d0) 0.4d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.382088577811047d0) 0.3d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.420740290560897d0) 0.2d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.460172162722971d0) 0.1d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.5d0) 0.0d0 +TEST-TOL0+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.539827837277029d0) -0.1d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.579259709439103d0) -0.2d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.617911422188953d0) -0.3d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.655421741610324d0) -0.4d0 +TEST-TOL1+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.691462461274013d0) -0.5d0 +TEST-TOL2+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.841344746068543d0) -1.0d0 +TEST-TOL3+)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.977249868051821d0) -2.0d0 1.d-14)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.998650102d0) -3.0d0 1.d-8)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.9999683288d0) -4.0d0 1.d-6)
(ASSERT-TO-TOLERANCE (UGAUSSIAN-QINV 0.9999997133d0) -5.0d0 1.d-4))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment