Commit 75607030 authored by pfdietz's avatar pfdietz
Browse files

Added tests for sin, cos, and tan (more are needed.)

parent 2963e817
;-*- 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
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))))
t)
(deftest cos.2
(loop for x = (- (random 2000.0s0) 1000.0s0)
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)))
t)
(deftest cos.3
(loop for x = (- (random 2000.0f0) 1000.0f0)
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)))
t)
(deftest cos.4
(loop for x = (- (random 2000.0d0) 1000.0d0)
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)))
t)
(deftest cos.5
(loop for x = (- (random 2000.0l0) 1000.0l0)
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)))
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
unless (approx= (cos i) (cos (coerce i 'single-float)))
collect i)
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)
for i = (- (random 20) 10)
for y = (cos (complex r i))
repeat 1000
always (numberp y))
t)
(deftest cos.21
(loop for r = (- (random 2000.0s0) 1000.0s0)
for i = (- (random 20.0s0) 10.0s0)
for y = (cos (complex r i))
repeat 1000
always (numberp y))
t)
(deftest cos.22
(loop for r = (- (random 2000.0f0) 1000.0f0)
for i = (- (random 20.0f0) 10.0f0)
for y = (cos (complex r i))
repeat 1000
always (numberp y))
t)
(deftest cos.23
(loop for r = (- (random 2000.0d0) 1000.0d0)
for i = (- (random 20.0d0) 10.0d0)
for y = (cos (complex r i))
repeat 1000
always (numberp y))
t)
(deftest cos.24
(loop for r = (- (random 2000.0l0) 1000.0l0)
for i = (- (random 20.0l0) 10.0l0)
for y = (cos (complex r i))
repeat 1000
always (numberp y))
t)
;;; 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
(loop for x in *mini-universe*
unless (or (numberp x)
(eval `(signals-error (cos ',x) type-error)))
collect x)
nil)
......@@ -345,3 +345,9 @@
(min x1 x2) (max x1 x2)
(min y1 y2) (max y1 y2)
n2))))
(defun safe-tan (x &optional (default 0.0))
(handler-case
(let ((result (multiple-value-list (tan x))))
(assert (null (cdr result)))
(car result))
(arithmetic-error () default)))
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Mon Feb 9 20:20:46 2004
;;;; Contains: Tests for SIN
(in-package :cl-test)
(deftest sin.1
(loop for i from -1000 to 1000
for rlist = (multiple-value-list (sin i))
for y = (car rlist)
always (and (null (cdr rlist))
(<= -1 y 1)
(or (rationalp y) (typep y 'single-float))))
t)
(deftest sin.2
(loop for x = (- (random 2000.0s0) 1000.0s0)
for rlist = (multiple-value-list (sin x))
for y = (car rlist)
repeat 1000
always (and (null (cdr rlist))
(<= -1 y 1)
(typep y 'short-float)))
t)
(deftest sin.3
(loop for x = (- (random 2000.0f0) 1000.0f0)
for rlist = (multiple-value-list (sin x))
for y = (car rlist)
repeat 1000
always (and (null (cdr rlist))
(<= -1 y 1)
(typep y 'single-float)))
t)
(deftest sin.4
(loop for x = (- (random 2000.0d0) 1000.0d0)
for rlist = (multiple-value-list (sin x))
for y = (car rlist)
repeat 1000
always (and (null (cdr rlist))
(<= -1 y 1)
(typep y 'double-float)))
t)
(deftest sin.5
(loop for x = (- (random 2000.0l0) 1000.0l0)
for rlist = (multiple-value-list (sin x))
for y = (car rlist)
repeat 1000
always (and (null (cdr rlist))
(<= -1 y 1)
(typep y 'long-float)))
t)
(deftest sin.6
(let ((r (sin 0)))
(or (eqlt r 0) (eqlt r 0.0)))
t)
(deftest sin.7
(sin 0.0s0)
0.0s0)
(deftest sin.8
(sin 0.0)
0.0)
(deftest sin.9
(sin 0.0d0)
0.0d0)
(deftest sin.10
(sin 0.0l0)
0.0l0)
(deftest sin.11
(loop for i from 1 to 100
unless (approx= (sin i) (sin (coerce i 'single-float)))
collect i)
nil)
(deftest sin.12
(approx= (sin (coerce (/ pi 2) 'single-float)) 1.0)
t)
(deftest sin.13
(approx= (sin (coerce (/ pi -2) 'single-float)) -1.0)
t)
(deftest sin.14
(approx= (sin (coerce (/ pi 2) 'short-float)) 1.0s0)
t)
(deftest sin.15
(approx= (sin (coerce (/ pi -2) 'short-float)) -1.0s0)
t)
(deftest sin.16
(approx= (sin (coerce (/ pi 2) 'double-float)) 1.0d0)
t)
(deftest sin.17
(approx= (sin (coerce (/ pi -2) 'double-float)) -1.0d0)
t)
(deftest sin.18
(approx= (sin (coerce (/ pi 2) 'long-float)) 1.0l0)
t)
(deftest sin.19
(approx= (sin (coerce (/ pi -2) 'long-float)) -1.0l0)
t)
(deftest sin.20
(loop for r = (- (random 2000) 1000)
for i = (- (random 20) 10)
for y = (sin (complex r i))
repeat 1000
always (numberp y))
t)
(deftest sin.21
(loop for r = (- (random 2000.0s0) 1000.0s0)
for i = (- (random 20.0s0) 10.0s0)
for y = (sin (complex r i))
repeat 1000
always (numberp y))
t)
(deftest sin.22
(loop for r = (- (random 2000.0f0) 1000.0f0)
for i = (- (random 20.0f0) 10.0f0)
for y = (sin (complex r i))
repeat 1000
always (numberp y))
t)
(deftest sin.23
(loop for r = (- (random 2000.0d0) 1000.0d0)
for i = (- (random 20.0d0) 10.0d0)
for y = (sin (complex r i))
repeat 1000
always (numberp y))
t)
(deftest sin.24
(loop for r = (- (random 2000.0l0) 1000.0l0)
for i = (- (random 20.0l0) 10.0l0)
for y = (sin (complex r i))
repeat 1000
always (numberp y))
t)
;;; Error tests
(deftest sin.error.1
(signals-error (sin) program-error)
t)
(deftest sin.error.2
(signals-error (sin 0.0 0.0) program-error)
t)
(deftest sin.error.3
(loop for x in *mini-universe*
unless (or (numberp x)
(eval `(signals-error (sin ',x) type-error)))
collect x)
nil)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Mon Feb 9 20:55:40 2004
;;;; Contains: Tests of TAN
(in-package :cl-test)
(deftest tan.1
(loop for i from -1000 to 1000
for rlist = (multiple-value-list (tan i))
for y = (car rlist)
always (and (null (cdr rlist))
(or (rationalp y) (typep y 'single-float))))
t)
(deftest tan.2
(loop for x = (- (random 2000.0s0) 1000.0s0)
for y = (safe-tan x 0.0s0)
repeat 1000
always (typep y 'short-float))
t)
(deftest tan.3
(loop for x = (- (random 2000.0f0) 1000.0f0)
for y = (safe-tan x 0.0)
repeat 1000
always (typep y 'single-float))
t)
(deftest tan.4
(loop for x = (- (random 2000.0d0) 1000.0d0)
for y = (safe-tan x 0.0d0)
repeat 1000
always (typep y 'double-float))
t)
(deftest tan.5
(loop for x = (- (random 2000.0l0) 1000.0l0)
for y = (safe-tan 0.0l0)
repeat 1000
always (typep y 'long-float))
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
unless (approx= (tan i) (tan (coerce i 'single-float)))
collect i)
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)
for i = (- (random 20) 10)
for y = (safe-tan (complex r i))
repeat 1000
always (numberp y))
t)
(deftest tan.21
(loop for r = (- (random 2000.0s0) 1000.0s0)
for i = (- (random 20.0s0) 10.0s0)
for y = (safe-tan (complex r i))
repeat 1000
always (numberp y))
t)
(deftest tan.22
(loop for r = (- (random 2000.0f0) 1000.0f0)
for i = (- (random 20.0f0) 10.0f0)
for y = (safe-tan (complex r i))
repeat 1000
always (numberp y))
t)
(deftest tan.23
(loop for r = (- (random 2000.0d0) 1000.0d0)
for i = (- (random 20.0d0) 10.0d0)
for y = (safe-tan (complex r i))
repeat 1000
always (numberp y))
t)
(deftest tan.24
(loop for r = (- (random 2000.0l0) 1000.0l0)
for i = (- (random 20.0l0) 10.0l0)
for y = (safe-tan (complex r i))
repeat 1000
always (numberp y))
t)
;;; 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
(loop for x in *mini-universe*
unless (or (numberp x)
(eval `(signals-error (tan ',x) type-error)))
collect x)
nil)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment