diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-09-27 09:53:37 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-09-27 09:53:37 -0600 |
commit | 1a8c81d07efe55c5a6909aff32359d4b8866af1c (patch) | |
tree | dbaf949a4d20226560d97ef9b48dbdcd71b7ad1a /tests | |
parent | 5e85a662d21081bc27adc1142759659cca59cd62 (diff) | |
download | cmath-1a8c81d07efe55c5a6909aff32359d4b8866af1c.tar.gz cmath-1a8c81d07efe55c5a6909aff32359d4b8866af1c.zip |
keep unit tests but make directory structure more consistent with requirements i did not read
Diffstat (limited to 'tests')
-rw-r--r-- | tests/approx.lisp | 24 | ||||
-rw-r--r-- | tests/maceps.lisp | 27 | ||||
-rw-r--r-- | tests/suite.lisp | 10 | ||||
-rw-r--r-- | tests/table.lisp | 31 | ||||
-rw-r--r-- | tests/vector.lisp | 31 |
5 files changed, 123 insertions, 0 deletions
diff --git a/tests/approx.lisp b/tests/approx.lisp new file mode 100644 index 0000000..2fd8124 --- /dev/null +++ b/tests/approx.lisp @@ -0,0 +1,24 @@ +(defpackage lizfcm/tests.approx + (:use :cl + :fiveam + :lizfcm.approx + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.approx) + +(def-suite approx-suite + :in lizfcm-test-suite) +(in-suite approx-suite) + +(test derivative-at + :description "derivative at is within bounds" + (let ((f (lambda (x) (* x x))) + (x 2) + (accepted-delta 0.02) + (f-prime-at-x 4) + (delta 0.01)) + (is (within-range-p + (derivative-at f x delta) + f-prime-at-x + accepted-delta)))) diff --git a/tests/maceps.lisp b/tests/maceps.lisp new file mode 100644 index 0000000..cd5ced9 --- /dev/null +++ b/tests/maceps.lisp @@ -0,0 +1,27 @@ +(defpackage lizfcm/tests.maceps + (:use :cl + :fiveam + :lizfcm.approx + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.maceps) + +(def-suite maceps-suite + :in lizfcm-test-suite) +(in-suite maceps-suite) + +(test maceps + :description "double precision provides precision about (mac eps of single precision) squared" + (let* ((maceps-computation-double (compute-maceps (lambda (x) x) + 1.0d0 + 1.0d0)) + (maceps-computation-single (compute-maceps (lambda (x) x) + 1.0 + 1.0)) + (last-double-h (cadar (last maceps-computation-double))) + (last-single-h (cadar (last maceps-computation-single)))) + (is (within-range-p + (- last-double-h (* last-single-h last-single-h)) + 0 + last-single-h)))) diff --git a/tests/suite.lisp b/tests/suite.lisp new file mode 100644 index 0000000..e23cfaf --- /dev/null +++ b/tests/suite.lisp @@ -0,0 +1,10 @@ +(in-package :cl-user) +(defpackage lizfcm/tests + (:use :cl + :fiveam) + (:export :run! + :lizfcm-test-suite)) +(in-package :lizfcm/tests) + +(def-suite lizfcm-test-suite + :description "The ultimate parent test suite") diff --git a/tests/table.lisp b/tests/table.lisp new file mode 100644 index 0000000..33d4e86 --- /dev/null +++ b/tests/table.lisp @@ -0,0 +1,31 @@ +(defpackage lizfcm/tests.table + (:use :cl + :fiveam + :lizfcm.utils + :lizfcm/tests) + (:export :approx-suite)) +(in-package :lizfcm/tests.table) + +(def-suite table-suite + :in lizfcm-test-suite) +(in-suite table-suite) + +(defun fib (n) + (cond ((< n 2) n) + (t (+ (fib (- n 1)) (fib (- n 2)))))) + +(test table-of-fib-vals + :description "table generates correctly" + (let* ((headers '("n" "fib(n)")) + (n-values '((1) (2) (3) (4))) + (expected `(("n" "fib(n)") + (1 ,(fib 1)) + (2 ,(fib 2)) + (3 ,(fib 3)) + (4 ,(fib 4)))) + (tabled (lizfcm.utils:table (:headers headers + :domain-order (n) + :domain-values n-values) + (fib n)))) + (is (equal expected tabled)))) + diff --git a/tests/vector.lisp b/tests/vector.lisp new file mode 100644 index 0000000..3ffe5a8 --- /dev/null +++ b/tests/vector.lisp @@ -0,0 +1,31 @@ +(defpackage lizfcm/tests.vector + (:use :cl + :fiveam + :lizfcm.vector + :lizfcm.utils + :lizfcm/tests) + (:export :vector-suite)) +(in-package :lizfcm/tests.vector) + +(def-suite vector-suite + :in lizfcm-test-suite) +(in-suite vector-suite) + +(test p-norm + :description "computes p-norm" + (let ((v '(1 1)) + (length (sqrt 2)) + (2-norm (p-norm 2))) + (is (within-range-p (funcall 2-norm v) + length + 0.00001)))) + +(test vector-distance + :description "computes distance via norm" + (let ((v1 '(0 0)) + (v2 '(1 1)) + (dist (sqrt 2))) + (is (within-range-p (distance v1 v2 (p-norm 2)) + dist + 0.00001)))) + |