phase.lsp 2.37 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 21:15:54 2003
;;;; Contains: Tests of PHASE

6

7 8

(deftest phase.error.1
9 10
  (signals-error (phase) program-error)
  t)
11 12

(deftest phase.error.2
13 14
  (signals-error (phase 0 0) program-error)
  t)
15 16

(deftest phase.error.3
pfdietz's avatar
pfdietz committed
17
  (check-type-error #'phase #'numberp)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  nil)

(deftest phase.1
  (eqlt (phase 0) 0.0f0)
  t)

(deftest phase.2
  (eqlt (phase 1) 0.0f0)
  t)

(deftest phase.3
  (eqlt (phase 1/2) 0.0f0)
  t)

(deftest phase.4
  (eqlt (phase 100.0f0) 0.0f0)
  t)

(deftest phase.5
  (eqlt (phase 100.0s0) 0.0s0)
  t)

(deftest phase.6
  (eqlt (phase 100.0d0) 0.0d0)
  t)

(deftest phase.7
  (eqlt (phase 100.0l0) 0.0l0)
  t)

(deftest phase.8
  (eqlt (phase -1) (coerce pi 'single-float))
  t)

(deftest phase.9
  (eqlt (phase -1/2) (coerce pi 'single-float))
  t)

(deftest phase.10
  (let ((p1 (phase #c(0 1)))
sds's avatar
sds committed
58
        (p2 (phase #c(0.0f0 1.0f0))))
59
    (and (eql p1 p2)
sds's avatar
sds committed
60
         (approx= p1 (coerce (/ pi 2) 'single-float))))
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  t)

(deftest phase.11
  (let ((p (phase #c(0.0d0 1.0d0))))
    (approx= p (coerce (/ pi 2) 'double-float)))
  t)

(deftest phase.12
  (let ((p (phase #c(0.0s0 1.0s0))))
    (approx= p (coerce (/ pi 2) 'single-float)))
  t)

(deftest phase.13
  (let ((p (phase #c(0.0l0 1.0l0))))
    (approx= p (/ pi 2)))
  t)

(deftest phase.14
  (let ((p1 (phase #c(1 1)))
sds's avatar
sds committed
80
        (p2 (phase #c(1.0f0 1.0f0))))
81
    (and (eql p1 p2)
sds's avatar
sds committed
82 83
         (approx= p1 (coerce (/ pi 4) 'single-float)
                  (* 2 single-float-epsilon))))
84 85 86 87
  t)

(deftest phase.15
  (let ((p (phase #c(1.0d0 1.0d0))))
88
    (approx= p (coerce (/ pi 4) 'double-float)
sds's avatar
sds committed
89
             (* 2 double-float-epsilon)))
90 91 92 93
  t)

(deftest phase.16
  (let ((p (phase #c(1.0s0 1.0s0))))
94
    (approx= p (coerce (/ pi 4) 'single-float)
sds's avatar
sds committed
95
             (* 2 short-float-epsilon)))
96 97 98 99
  t)

(deftest phase.17
  (let ((p (phase #c(1.0l0 1.0l0))))
100
    (approx= p (/ pi 4) (* 2 long-float-epsilon)))
101
  t)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

;;; Negative zeros
(deftest phase.18
  (or (eqlt -0.0s0 0.0s0)
      (approx= (phase #c(-1.0 -0.0)) (coerce (- pi) 'short-float)))
  t)

(deftest phase.19
  (or (eqlt -0.0f0 0.0f0)
      (approx= (phase #c(-1.0 -0.0)) (coerce (- pi) 'single-float)))
  t)

(deftest phase.20
  (or (eqlt -0.0d0 0.0d0)
      (approx= (phase #c(-1.0 -0.0)) (coerce (- pi) 'double-float)))
  t)

(deftest phase.21
  (or (eqlt -0.0l0 0.0l0)
      (approx= (phase #c(-1.0 -0.0)) (coerce (- pi) 'long-float)))
  t)