signum.lsp 2.45 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Sep  4 22:29:09 2003
;;;; Contains: Tests of SIGNUM

(in-package :cl-test)

(deftest signum.error.1
9 10
  (signals-error (signum) program-error)
  t)
pfdietz's avatar
pfdietz committed
11 12

(deftest signum.error.2
13 14
  (signals-error (signum 1 1) program-error)
  t)
pfdietz's avatar
pfdietz committed
15 16

(deftest signum.error.3
17 18
  (signals-error (signum 1 nil) program-error)
  t)
pfdietz's avatar
pfdietz committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

(deftest signum.1
  (signum 0)
  0)

(deftest signum.2
  (signum 123)
  1)

(deftest signum.3
  (signum -123123)
  -1)

(deftest signum.4
  (loop for i in *rationals*
sds's avatar
sds committed
34 35 36 37 38 39
        for s = (signum i)
        unless (cond
                ((zerop i) (eql s 0))
                ((plusp i) (eql s 1))
                (t (eql s -1)))
        collect (list i s))
pfdietz's avatar
pfdietz committed
40 41 42 43
  nil)

(deftest signum.5
  (loop for x in '(0.0s0 0.0f0 0.0d0 0.0l0)
sds's avatar
sds committed
44 45 46 47 48 49 50 51 52
        for one = (float 1 x)
        for y = (float 13122 x)
        for s1 = (signum x)
        for s2 = (signum y)
        for s3 = (signum (- y))
        unless (and (eql s1 x)
                    (eql s2 one)
                    (eql s3 (- one)))
        collect (list x one y s1 s2 s3))
pfdietz's avatar
pfdietz committed
53 54 55 56 57 58 59 60 61
  nil)

(deftest signum.6
  (loop
   for tp in '(short-float single-float double-float long-float)
   for z = (coerce 0 tp)
   for mz = (- z)
   nconc
   (loop for x in (list z mz)
sds's avatar
sds committed
62 63 64 65 66 67
         nconc
         (loop for y in (list z mz)
               for c = (complex z mz)
               for s = (signum c)
               unless (eql c s)
               collect (list c s))))
pfdietz's avatar
pfdietz committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  nil)

(deftest signum.7
  (loop
   for tp in '(short-float single-float double-float long-float)
   for z = (coerce 0 tp)
   for one = (coerce 1 tp)
   for onem = (coerce -1 tp)
   for c1 = (complex one z)
   for c2 = (complex onem z)
   for c3 = (complex z one)
   for c4 = (complex z onem)
   unless (eql c1 (signum c1))
   collect (list c1 (signum c1))
   unless (eql c2 (signum c2))
   collect (list c2 (signum c2))
   unless (eql c3 (signum c3))
   collect (list c3 (signum c3))
   unless (eql c4 (signum c4))
   collect (list c4 (signum c4)))
  nil)

(deftest signum.8
  (let* ((c (complex 0 1))
sds's avatar
sds committed
92
         (s (signum c)))
pfdietz's avatar
pfdietz committed
93
    (or (eqlt c s)
sds's avatar
sds committed
94
        (eqlt s #c(0.0 1.0))))
pfdietz's avatar
pfdietz committed
95 96 97 98
  t)

(deftest signum.9
  (let* ((c (complex 0 -1))
sds's avatar
sds committed
99
         (s (signum c)))
pfdietz's avatar
pfdietz committed
100
    (or (eqlt c s)
sds's avatar
sds committed
101
        (eqlt s #c(0.0 -1.0))))
pfdietz's avatar
pfdietz committed
102 103 104 105
  t)

(deftest signum.10
  (let* ((c (complex 3/5 4/5))
sds's avatar
sds committed
106
         (s (signum c)))
pfdietz's avatar
pfdietz committed
107
    (or (eqlt c s)
sds's avatar
sds committed
108
        (eqlt s (complex (float 3/5) (float 4/5)))))
pfdietz's avatar
pfdietz committed
109 110 111
  t)

(deftest signum.11
112
  (let ((i 0)) (values (signum (the (integer 1 1) (incf i))) i))
pfdietz's avatar
pfdietz committed
113 114
  1 1)