summaryrefslogtreecommitdiff
path: root/deprecated-cl/tests,approx.lisp
blob: 678ff8cfbd3470c25fa4b659403e4030be7168c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(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 central-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
              (central-derivative-at f x delta)
              f-prime-at-x
              accepted-delta))))

(test fwd-derivative-at
      :description "forward 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
              (forward-derivative-at f x delta)
              f-prime-at-x
              accepted-delta))))

(test bwd-derivative-at
      :description "backward 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
              (backward-derivative-at f x delta)
              f-prime-at-x
              accepted-delta))))