1
0
mirror of synced 2026-05-02 22:33:48 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/12-5-2-COS.TEST

63 lines
1.6 KiB
Plaintext

;; Function To Be Tested: COS
;;
;; Source: Guy L Steele's CLTL
;; Section: 12.5.2 Trigonometric and Related Functions
;; Page: 207
;;
;; Created By: Kelly Roach and John Park
;;
;; Creation Date: July 12,1986
;;
;; Last Update: Oct 3, 1986
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>12-5-2-COS.TEST
;;
;;
;; Syntax: (COS RADIANS)
;;
;; Function Description:
;; SIN returns the sine of the argument, COS the cosine,
;; and TAN the tangent. The argument is in radians.
;; The argument may be complex.
;;
;; Argument(s): RADIANS - a real
;;
;; Returns: a number
;;
(do-test-group (cos-setup
:before (progn
(setq cos-tolerance 0.00001)
(setq cos-test-cases
'(0 (/ PI 6) (/ PI 3) (/ PI 2) (/(* 2 PI) 3) (/(* 5 PI) 6)
PI (/(* 7 PI) 6) (/(* 4 PI) 3)(/(* 3 PI) 2) (/(* 5 PI) 3)
(/(* 11 PI) 6) (* 2 PI)))
(setq expected-value
'(1.0 (/(sqrt 3) 2) 0.5 0.0 -0.5 (-(/(sqrt 3) 2)) -1.0
(-(/(sqrt 3) 2)) -0.5 0.0 0.5 (/(sqrt 3) 2) 1.0))
(defun cos-test (pairs) ; pairs: paired result (calulated vs result)
(cond ((or (zerop (car pairs)) (zerop (cdr pairs)))
(zerop (cdr pairs)))
(t (< (abs (/ (- (car pairs) (cdr pairs)) (cdr pairs)))
cos-tolerance))))
))
(do-test pi-const-exist? (and (boundp 'pi) (numberp pi)))
(do-test cos-test
(and (setq calculated-result (mapcar #'cos
(mapcar #'eval cos-test-cases)))
(setq expected-result (mapcar #'eval expected-value))
(setq calculated-expected
(pairlis calculated-result expected-result))
(setq test-result (mapcar #'cos-test calculated-expected))
(notany 'null test-result))))
STOP