tan.lsp 3.15 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Feb  9 20:55:40 2004
;;;; Contains: Tests of TAN

6

7 8 9

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

(deftest tan.2
  (loop for x = (- (random 2000.0s0) 1000.0s0)
sds's avatar
sds committed
18 19 20
        for y = (safe-tan x 0.0s0)
        repeat 1000
        always (typep y 'short-float))
21 22 23 24
  t)

(deftest tan.3
  (loop for x = (- (random 2000.0f0) 1000.0f0)
sds's avatar
sds committed
25 26 27
        for y = (safe-tan x 0.0)
        repeat 1000
        always (typep y 'single-float))
28 29 30 31
  t)

(deftest tan.4
  (loop for x = (- (random 2000.0d0) 1000.0d0)
sds's avatar
sds committed
32 33 34
        for y = (safe-tan x 0.0d0)
        repeat 1000
        always (typep y 'double-float))
35 36 37 38
  t)

(deftest tan.5
  (loop for x = (- (random 2000.0l0) 1000.0l0)
sds's avatar
sds committed
39 40 41
        for y = (safe-tan 0.0l0)
        repeat 1000
        always (typep y 'long-float))
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  t)

(deftest tan.6
  (let ((r (tan 0)))
    (or (eqlt r 0) (eqlt r 0.0)))
  t)

(deftest tan.7
  (tan 0.0s0)
  0.0s0)

(deftest tan.8
  (tan 0.0)
  0.0)

(deftest tan.9
  (tan 0.0d0)
  0.0d0)

(deftest tan.10
  (tan 0.0l0)
  0.0l0)

(deftest tan.11
  (loop for i from 1 to 100
sds's avatar
sds committed
67 68
        unless (approx= (tan i) (tan (coerce i 'single-float)))
        collect i)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  nil)

(deftest tan.12
  (approx= (tan (coerce (/ pi 4) 'single-float)) 1.0)
  t)

(deftest tan.13
  (approx= (tan (coerce (/ pi -4) 'single-float)) -1.0)
  t)

(deftest tan.14
  (approx= (tan (coerce (/ pi 4) 'short-float)) 1s0)
  t)

(deftest tan.15
  (approx= (tan (coerce (/ pi -4) 'short-float)) -1s0)
  t)

(deftest tan.16
  (approx= (tan (coerce (/ pi 4) 'double-float)) 1d0)
  t)

(deftest tan.17
  (approx= (tan (coerce (/ pi -4) 'double-float)) -1d0)
  t)

(deftest tan.18
  (approx= (tan (coerce (/ pi 4) 'long-float)) 1l0)
  t)

(deftest tan.19
  (approx= (tan (coerce (/ pi -4) 'long-float)) -1l0)
  t)

(deftest tan.20
  (loop for r = (- (random 2000) 1000)
sds's avatar
sds committed
105 106 107 108
        for i = (- (random 20) 10)
        for y = (safe-tan (complex r i))
        repeat 1000
        always (numberp y))
109 110 111 112
  t)

(deftest tan.21
  (loop for r = (- (random 2000.0s0) 1000.0s0)
sds's avatar
sds committed
113 114 115 116
        for i = (- (random 20.0s0) 10.0s0)
        for y = (safe-tan (complex r i))
        repeat 1000
        always (numberp y))
117 118 119 120
  t)

(deftest tan.22
  (loop for r = (- (random 2000.0f0) 1000.0f0)
sds's avatar
sds committed
121 122 123 124
        for i = (- (random 20.0f0) 10.0f0)
        for y = (safe-tan (complex r i))
        repeat 1000
        always (numberp y))
125 126 127 128
  t)

(deftest tan.23
  (loop for r = (- (random 2000.0d0) 1000.0d0)
sds's avatar
sds committed
129 130 131 132
        for i = (- (random 20.0d0) 10.0d0)
        for y = (safe-tan (complex r i))
        repeat 1000
        always (numberp y))
133 134 135 136
  t)

(deftest tan.24
  (loop for r = (- (random 2000.0l0) 1000.0l0)
sds's avatar
sds committed
137 138 139 140
        for i = (- (random 20.0l0) 10.0l0)
        for y = (safe-tan (complex r i))
        repeat 1000
        always (numberp y))
141 142
  t)

143 144 145
;;; FIXME
;;; More accuracy tests here

146 147 148 149 150 151 152 153 154 155 156
;;; Error tests

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

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

(deftest tan.error.3
157
  (check-type-error #'tan #'numberp)
158
  nil)