cos.lsp 3.65 KB
 pfdietz committed Feb 10, 2004 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 committed Aug 12, 2009 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)))) `````` pfdietz committed Feb 10, 2004 15 16 17 18 `````` t) (deftest cos.2 (loop for x = (- (random 2000.0s0) 1000.0s0) `````` sds committed Aug 12, 2009 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))) `````` pfdietz committed Feb 10, 2004 25 26 27 28 `````` t) (deftest cos.3 (loop for x = (- (random 2000.0f0) 1000.0f0) `````` sds committed Aug 12, 2009 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))) `````` pfdietz committed Feb 10, 2004 35 36 37 38 `````` t) (deftest cos.4 (loop for x = (- (random 2000.0d0) 1000.0d0) `````` sds committed Aug 12, 2009 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))) `````` pfdietz committed Feb 10, 2004 45 46 47 48 `````` t) (deftest cos.5 (loop for x = (- (random 2000.0l0) 1000.0l0) `````` sds committed Aug 12, 2009 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))) `````` pfdietz committed Feb 10, 2004 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 committed Aug 12, 2009 80 81 `````` unless (approx= (cos i) (cos (coerce i 'single-float))) collect i) `````` pfdietz committed Feb 10, 2004 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 committed Aug 12, 2009 118 119 120 121 `````` for i = (- (random 20) 10) for y = (cos (complex r i)) repeat 1000 always (numberp y)) `````` pfdietz committed Feb 10, 2004 122 123 124 125 `````` t) (deftest cos.21 (loop for r = (- (random 2000.0s0) 1000.0s0) `````` sds committed Aug 12, 2009 126 127 128 129 `````` for i = (- (random 20.0s0) 10.0s0) for y = (cos (complex r i)) repeat 1000 always (numberp y)) `````` pfdietz committed Feb 10, 2004 130 131 132 133 `````` t) (deftest cos.22 (loop for r = (- (random 2000.0f0) 1000.0f0) `````` sds committed Aug 12, 2009 134 135 136 137 `````` for i = (- (random 20.0f0) 10.0f0) for y = (cos (complex r i)) repeat 1000 always (numberp y)) `````` pfdietz committed Feb 10, 2004 138 139 140 141 `````` t) (deftest cos.23 (loop for r = (- (random 2000.0d0) 1000.0d0) `````` sds committed Aug 12, 2009 142 143 144 145 `````` for i = (- (random 20.0d0) 10.0d0) for y = (cos (complex r i)) repeat 1000 always (numberp y)) `````` pfdietz committed Feb 10, 2004 146 147 148 149 `````` t) (deftest cos.24 (loop for r = (- (random 2000.0l0) 1000.0l0) `````` sds committed Aug 12, 2009 150 151 152 153 `````` for i = (- (random 20.0l0) 10.0l0) for y = (cos (complex r i)) repeat 1000 always (numberp y)) `````` pfdietz committed Feb 10, 2004 154 155 `````` t) `````` pfdietz committed Feb 12, 2004 156 157 158 ``````;;; FIXME ;;; More accuracy tests here `````` pfdietz committed Feb 10, 2004 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 `````` pfdietz committed May 06, 2005 170 `````` (check-type-error #'cos #'numberp) `````` pfdietz committed Feb 10, 2004 171 172 `````` nil) ``````