cosh.lsp 2.21 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Feb 11 06:54:15 2004
;;;; Contains: Tests of COSH

6

pfdietz's avatar
pfdietz committed
7 8 9 10

(deftest cosh.1
  (let ((result (cosh 0)))
    (or (eqlt result 1)
sds's avatar
sds committed
11
        (eqlt result 1.0)))
pfdietz's avatar
pfdietz committed
12 13 14 15
  t)

(deftest cosh.2
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
16 17 18 19 20
        for zero = (coerce 0 type)
        for one = (coerce 1 type)
        unless (equal (multiple-value-list (cosh zero))
                      (list one))
        collect type)
pfdietz's avatar
pfdietz committed
21 22 23 24
  nil)

(deftest cosh.3
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
25 26 27 28 29
        for zero = (coerce 0 `(complex ,type))
        for one = (coerce 1 `(complex ,type))
        unless (equal (multiple-value-list (cosh zero))
                      (list one))
        collect type)
pfdietz's avatar
pfdietz committed
30 31 32 33
  nil)

(deftest cosh.4
  (loop for den = (1+ (random 10000))
sds's avatar
sds committed
34 35 36 37 38 39 40 41
        for num = (random (* 10 den))
        for x = (/ num den)
        for rlist = (multiple-value-list (cosh x))
        for y = (car rlist)
        repeat 1000
        unless (and (null (cdr rlist))
                    (numberp y))
        collect (list x rlist))
pfdietz's avatar
pfdietz committed
42 43 44 45
  nil)

(deftest cosh.5
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
46 47 48 49 50 51 52 53 54
        nconc
        (loop
         for x = (- (random (coerce 20 type)) 10)
         for rlist = (multiple-value-list (cosh x))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y type))
         collect (list x rlist)))
pfdietz's avatar
pfdietz committed
55 56 57 58
  nil)

(deftest cosh.6
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
59 60 61 62 63 64 65 66 67 68
        nconc
        (loop
         for x1 = (- (random (coerce 20 type)) 10)
         for x2 = (- (random (coerce 20 type)) 10)
         for rlist = (multiple-value-list (cosh (complex x1 x2)))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y `(complex ,type)))
         collect (list x1 x2 rlist)))
pfdietz's avatar
pfdietz committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  nil)

;;; FIXME
;;; Add accuracy tests here

;;; Error tests

(deftest cosh.error.1
  (signals-error (cosh) program-error)
  t)

(deftest cosh.error.2
  (signals-error (cosh 1.0 1.0) program-error)
  t)

(deftest cosh.error.3
85
  (check-type-error #'cosh #'numberp)
pfdietz's avatar
pfdietz committed
86 87 88 89 90 91
  nil)





sds's avatar
sds committed
92 93 94



pfdietz's avatar
pfdietz committed
95