log.lsp 3.43 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Feb 11 19:53:33 2004
;;;; Contains: Tests of LOG

(in-package :cl-test)

(deftest log.1
  (let ((result (log 1)))
    (or (eqlt result 0)
sds's avatar
sds committed
11
        (eqlt result 0.0)))
pfdietz's avatar
pfdietz committed
12 13 14 15 16 17 18 19
  t)

(deftest log.2
  (mapcar #'log '(1.0s0 1.0f0 1.0d0 1.0l0))
  (0.0s0 0.0f0 0.0d0 0.0l0))

(deftest log.3
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
20 21 22 23 24 25 26 27 28
        nconc
        (loop
         for x = (+ (random (coerce 1 type)) (/ 1 1000))
         for rlist = (multiple-value-list (log x))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y type))
         collect (list x rlist)))
pfdietz's avatar
pfdietz committed
29 30 31 32
  nil)

(deftest log.4
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
33 34 35 36 37 38 39 40 41
        nconc
        (loop
         for x = (1+ (random (coerce 1000000 type)))
         for rlist = (multiple-value-list (log x))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y type))
         collect (list x rlist)))
pfdietz's avatar
pfdietz committed
42 43 44 45
  nil)

(deftest log.5
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
46 47 48 49 50 51 52 53 54 55 56
        for zero = (coerce 0 type)
        nconc
        (loop
         for x = (- (random (coerce 1 type)))
         for rlist = (and (/= x zero) (multiple-value-list (log x)))
         for y = (car rlist)
         repeat 1000
         unless (or (= x zero)
                    (and (null (cdr rlist))
                         (typep y `(complex ,type))))
         collect (list x rlist)))
pfdietz's avatar
pfdietz committed
57 58 59 60
  nil)

(deftest log.6
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
61 62 63 64 65 66 67 68 69 70 71
        for zero = (coerce 0 type)
        nconc
        (loop
         for x = (- (random (coerce 1000000 type)))
         for rlist = (and (/= x zero) (multiple-value-list (log x)))
         for y = (car rlist)
         repeat 1000
         unless (or (= x zero)
                    (and (null (cdr rlist))
                         (typep y `(complex ,type))))
         collect (list x rlist)))
pfdietz's avatar
pfdietz committed
72 73 74 75
  nil)

(deftest log.7
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
76 77 78 79 80 81 82 83 84 85 86 87 88
        for zero = (coerce 0 type)
        nconc
        (loop
         for x1 = (- (random (coerce 2000 type)) 1000)
         for x2 = (1+ (random (coerce 1000 type)))
         for rlist = (and (/= x1 zero)
                          (multiple-value-list (log (complex x1 x2))))
         for y = (car rlist)
         repeat 1000
         unless (or (= x1 zero)
                    (and (null (cdr rlist))
                         (typep y `(complex ,type))))
         collect (list x1 x2 rlist)))
pfdietz's avatar
pfdietz committed
89 90 91 92
  nil)

(deftest log.8
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
93 94 95 96 97 98 99 100 101 102 103 104 105
        for zero = (coerce 0 type)
        nconc
        (loop
         for x1 = (- (random (coerce 2000 type)) 1000)
         for x2 = (- -1 (random (coerce 1000 type)))
         for rlist = (and (/= x1 zero)
                          (multiple-value-list (log (complex x1 x2))))
         for y = (car rlist)
         repeat 1000
         unless (or (= x1 zero)
                    (and (null (cdr rlist))
                         (typep y `(complex ,type))))
         collect (list x1 x2 rlist)))
pfdietz's avatar
pfdietz committed
106 107 108 109
  nil)

;;; FIXME
;;; Add tests for two-arg calls
sds's avatar
sds committed
110

pfdietz's avatar
pfdietz committed
111 112 113 114 115 116 117 118 119 120 121 122 123
;;; FIXME
;;; More accuracy tests here

;;; Error tests

(deftest log.error.1
  (signals-error (log) program-error)
  t)

(deftest log.error.2
  (signals-error (log 1.0 2.0 3.0) program-error)
  t)