complex.lsp 1.48 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 19:56:29 2003
;;;; Contains: Tests of COMPLEX

(in-package :cl-test)

8 9
;;; Error tests

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

(deftest complex.error.2
15 16 17 18
  (signals-error (complex 1 1 nil) program-error)
  t)

;;; Non-error tests
19 20 21

(deftest complex.1
  (loop for x in *rationals*
sds's avatar
sds committed
22 23
        for c = (complex x)
        always (eql c x))
24 25 26 27
  t)

(deftest complex.2
  (loop for x in *floats*
sds's avatar
sds committed
28 29 30 31
        for c = (complex x)
        always (and (complexp c)
                    (eql x (realpart c))
                    (eql (float 0 x) (imagpart c))))
32 33 34 35
  t)

(deftest complex.3
  (loop for x in *rationals*
sds's avatar
sds committed
36 37 38 39 40 41
        for c = (complex 0 x)
        unless (or (zerop x)
                   (and (complexp c)
                        (eql (realpart c) 0)
                        (eql (imagpart c) x)))
        collect (list c x))
42 43 44 45
  nil)

(deftest complex.4
  (loop for x in *floats*
sds's avatar
sds committed
46 47 48 49
        for c = (complex 0 x)
        always (and (complexp c)
                    (eql (float 0 x) (realpart c))
                    (eql x (imagpart c))))
50
  t)
pfdietz's avatar
pfdietz committed
51 52 53 54 55

;;; Tests of some properties of complex numbers

(deftest complex.5
  (loop for c in *complexes*
sds's avatar
sds committed
56 57 58 59 60
        unless (loop for type in '(short-float single-float double-float long-float)
                     always (if (typep (realpart c) type)
                                (typep (imagpart c) type)
                              (not (typep (imagpart c) type))))
        collect c)
pfdietz's avatar
pfdietz committed
61
  nil)