cis.lsp 1.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 18:42:15 2003
;;;; Contains: Tests of CIS

(in-package :cl-test)

(compile-and-load "numbers-aux.lsp")

(deftest cis.error.1
11 12
  (signals-error (cis) program-error)
  t)
13 14

(deftest cis.error.2
15 16
  (signals-error (cis 0 nil) program-error)
  t)
17 18

(deftest cis.1
pfdietz's avatar
pfdietz committed
19 20
  (let ((result (cis 0)))
    (or (=t result 1)
sds's avatar
sds committed
21
        (eqlt #c(1.0 0.0))))
22 23 24 25
  t)

(deftest cis.2
  (loop for x in '(0.0s0 0.0f0 0.0d0 0.0l0)
sds's avatar
sds committed
26 27 28 29 30
        for vals = (multiple-value-list (cis x))
        for c = (car vals)
        unless (and (= (length vals) 1)
                    (eql c (complex (float 1 x) x)))
        collect (cons x vals))
31 32 33 34
  nil)

(deftest cis.3
  (loop for x = (random (* 2 pi))
sds's avatar
sds committed
35 36 37 38 39 40
        for c = (cis x)
        repeat 1000
        unless (and (complexp c)
                    (approx= (imagpart c) (sin x))
                    (approx= (realpart c) (cos x)))
        collect (list x c (cos x) (sin x)))
41 42 43 44
  nil)

(deftest cis.4
  (loop for x = (random (coerce (* 2 pi) 'single-float))
sds's avatar
sds committed
45 46 47 48 49 50
        for c = (cis x)
        repeat 1000
        unless (and (complexp c)
                    (approx= (imagpart c) (sin x))
                    (approx= (realpart c) (cos x)))
        collect (list x c (cos x) (sin x)))
51
  nil)