cos.lsp 3.65 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Feb  9 20:53:42 2004
;;;; Contains: Tests of COS

(in-package :cl-test)

(deftest cos.1
  (loop for i from -1000 to 1000
sds's avatar
sds committed
10 11 12 13 14
        for rlist = (multiple-value-list (cos i))
        for y = (car rlist)
        always (and (null (cdr rlist))
                    (<= -1 y 1)
                    (or (rationalp y) (typep y 'single-float))))
15 16 17 18
  t)

(deftest cos.2
  (loop for x = (- (random 2000.0s0) 1000.0s0)
sds's avatar
sds committed
19 20 21 22 23 24
        for rlist = (multiple-value-list (cos x))
        for y = (car rlist)
        repeat 1000
        always (and (null (cdr rlist))
                    (<= -1 y 1)
                    (typep y 'short-float)))
25 26 27 28
  t)

(deftest cos.3
  (loop for x = (- (random 2000.0f0) 1000.0f0)
sds's avatar
sds committed
29 30 31 32 33 34
        for rlist = (multiple-value-list (cos x))
        for y = (car rlist)
        repeat 1000
        always (and (null (cdr rlist))
                    (<= -1 y 1)
                    (typep y 'single-float)))
35 36 37 38
  t)

(deftest cos.4
  (loop for x = (- (random 2000.0d0) 1000.0d0)
sds's avatar
sds committed
39 40 41 42 43 44
        for rlist = (multiple-value-list (cos x))
        for y = (car rlist)
        repeat 1000
        always (and (null (cdr rlist))
                    (<= -1 y 1)
                    (typep y 'double-float)))
45 46 47 48
  t)

(deftest cos.5
  (loop for x = (- (random 2000.0l0) 1000.0l0)
sds's avatar
sds committed
49 50 51 52 53 54
        for rlist = (multiple-value-list (cos x))
        for y = (car rlist)
        repeat 1000
        always (and (null (cdr rlist))
                    (<= -1 y 1)
                    (typep y 'long-float)))
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  t)

(deftest cos.6
  (let ((r (cos 0)))
    (or (eqlt r 1) (eqlt r 1.0)))
  t)

(deftest cos.7
  (cos 0.0s0)
  1.0s0)

(deftest cos.8
  (cos 0.0)
  1.0)

(deftest cos.9
  (cos 0.0d0)
  1.0d0)

(deftest cos.10
  (cos 0.0l0)
  1.0l0)

(deftest cos.11
  (loop for i from 1 to 100
sds's avatar
sds committed
80 81
        unless (approx= (cos i) (cos (coerce i 'single-float)))
        collect i)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  nil)

(deftest cos.12
  (approx= (cos (coerce (/ pi 2) 'single-float)) 0.0)
  t)

(deftest cos.13
  (approx= (cos (coerce (/ pi -2) 'single-float)) 0.0)
  t)

(deftest cos.14
  (approx= (cos (coerce (/ pi 2) 'short-float)) 0s0)
  t)

(deftest cos.15
  (approx= (cos (coerce (/ pi -2) 'short-float)) 0s0)
  t)

(deftest cos.16
  (approx= (cos (coerce (/ pi 2) 'double-float)) 0d0)
  t)

(deftest cos.17
  (approx= (cos (coerce (/ pi -2) 'double-float)) 0d0)
  t)

(deftest cos.18
  (approx= (cos (coerce (/ pi 2) 'long-float)) 0l0)
  t)

(deftest cos.19
  (approx= (cos (coerce (/ pi -2) 'long-float)) 0l0)
  t)

(deftest cos.20
  (loop for r = (- (random 2000) 1000)
sds's avatar
sds committed
118 119 120 121
        for i = (- (random 20) 10)
        for y = (cos (complex r i))
        repeat 1000
        always (numberp y))
122 123 124 125
  t)

(deftest cos.21
  (loop for r = (- (random 2000.0s0) 1000.0s0)
sds's avatar
sds committed
126 127 128 129
        for i = (- (random 20.0s0) 10.0s0)
        for y = (cos (complex r i))
        repeat 1000
        always (numberp y))
130 131 132 133
  t)

(deftest cos.22
  (loop for r = (- (random 2000.0f0) 1000.0f0)
sds's avatar
sds committed
134 135 136 137
        for i = (- (random 20.0f0) 10.0f0)
        for y = (cos (complex r i))
        repeat 1000
        always (numberp y))
138 139 140 141
  t)

(deftest cos.23
  (loop for r = (- (random 2000.0d0) 1000.0d0)
sds's avatar
sds committed
142 143 144 145
        for i = (- (random 20.0d0) 10.0d0)
        for y = (cos (complex r i))
        repeat 1000
        always (numberp y))
146 147 148 149
  t)

(deftest cos.24
  (loop for r = (- (random 2000.0l0) 1000.0l0)
sds's avatar
sds committed
150 151 152 153
        for i = (- (random 20.0l0) 10.0l0)
        for y = (cos (complex r i))
        repeat 1000
        always (numberp y))
154 155
  t)

156 157 158
;;; FIXME
;;; More accuracy tests here

159 160 161 162 163 164 165 166 167 168 169
;;; Error tests

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

(deftest cos.error.2
  (signals-error (cos 0.0 0.0) program-error)
  t)

(deftest cos.error.3
170
  (check-type-error #'cos #'numberp)
171 172
  nil)