oneminus.lsp 4.07 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Sep  1 20:14:34 2003
;;;; Contains: Tests of 1-

(in-package :cl-test)

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

10 11
;;; Error tests

12
(deftest 1-.error.1
13 14
  (signals-error (1-) program-error)
  t)
15 16

(deftest 1-.error.2
17 18
  (signals-error (1- 0 0) program-error)
  t)
19 20

(deftest 1-.error.3
21 22 23 24
  (signals-error (1- 0 nil nil) program-error)
  t)

;;; Non-error tests
25 26 27

(deftest 1-.1
  (loop for x = (random-fixnum)
sds's avatar
sds committed
28 29 30 31 32
        for y = (1- x)
        for z = (- x 1)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
33 34 35 36
  nil)

(deftest 1-.2
  (loop for x = (random-from-interval (ash 1 1000))
sds's avatar
sds committed
37 38 39 40 41
        for y = (1- x)
        for z = (- x 1)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
42 43 44 45
  nil)

(deftest 1-.3
  (loop for x = (random (1- most-positive-short-float))
sds's avatar
sds committed
46 47 48 49 50
        for y = (1- x)
        for z = (- x 1.0s0)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
51 52 53 54
  nil)

(deftest 1-.4
  (loop for x = (random (1- most-positive-single-float))
sds's avatar
sds committed
55 56 57 58 59
        for y = (1- x)
        for z = (- x 1.0f0)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
60 61 62 63
  nil)

(deftest 1-.5
  (loop for x = (random (1- most-positive-double-float))
sds's avatar
sds committed
64 65 66 67 68
        for y = (1- x)
        for z = (- x 1.0d0)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
69 70 71 72
  nil)

(deftest 1-.6
  (loop for x = (random (1- most-positive-long-float))
sds's avatar
sds committed
73 74 75 76 77
        for y = (1- x)
        for z = (- x 1.0l0)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
78 79 80 81
  nil)

(deftest 1-.7
  (loop for x = (random-fixnum)
sds's avatar
sds committed
82 83 84 85 86 87 88 89
        for y = (random-fixnum)
        for y2 = (if (zerop y) 1 y)
        for r = (/ x y2)
        for r1 = (1- r)
        for r2 = (- r 1)
        repeat 1000
        unless (eql r1 r2)
        collect (list x y2 r1 r2))
90 91 92 93 94
  nil)

(deftest 1-.8
  (let ((bound (ash 1 200)))
    (loop for x = (random-from-interval bound)
sds's avatar
sds committed
95 96 97 98 99 100 101 102
          for y = (random-from-interval bound)
          for y2 = (if (zerop y) 1 y)
          for r = (/ x y2)
          for r1 = (1- r)
          for r2 = (- r 1)
          repeat 1000
          unless (eql r1 r2)
          collect (list x y2 r1 r2)))
103 104 105 106 107
  nil)

;;; Complex numbers
(deftest 1-.9
  (loop for xr = (random-fixnum)
sds's avatar
sds committed
108 109 110 111 112 113
        for xi = (random-fixnum)
        for xc = (complex xr xi)
        for xc1 = (1- xc)
        repeat 1000
        unless (eql xc1 (complex (- xr 1) xi))
        collect (list xr xi xc xc1))
114 115 116 117 118 119
  nil)


(deftest 1-.10
  (let ((bound (ash 1 100)))
    (loop for xr = (random-from-interval bound)
sds's avatar
sds committed
120 121 122 123 124 125
          for xi = (random-from-interval bound)
          for xc = (complex xr xi)
          for xc1 = (1- xc)
          repeat 1000
          unless (eql xc1 (complex (- xr 1) xi))
          collect (list xr xi xc xc1)))
126 127 128 129 130
  nil)

(deftest 1-.11
  (let ((bound (1- most-positive-short-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
131 132 133 134 135 136
          for xi = (random bound)
          for xc = (complex xr xi)
          for xc1 = (1- xc)
          repeat 1000
          unless (eql xc1 (complex (- xr 1) xi))
          collect (list xr xi xc xc1)))
137 138 139 140 141
  nil)

(deftest 1-.12
  (let ((bound (1- most-positive-single-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
142 143 144 145 146 147
          for xi = (random bound)
          for xc = (complex xr xi)
          for xc1 = (1- xc)
          repeat 1000
          unless (eql xc1 (complex (- xr 1) xi))
          collect (list xr xi xc xc1)))
148 149 150 151 152
  nil)

(deftest 1-.13
  (let ((bound (1- most-positive-double-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
153 154 155 156 157 158
          for xi = (random bound)
          for xc = (complex xr xi)
          for xc1 = (1- xc)
          repeat 1000
          unless (eql xc1 (complex (- xr 1) xi))
          collect (list xr xi xc xc1)))
159 160 161 162 163
  nil)

(deftest 1-.14
  (let ((bound (1- most-positive-long-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
164 165 166 167 168 169
          for xi = (random bound)
          for xc = (complex xr xi)
          for xc1 = (1- xc)
          repeat 1000
          unless (eql xc1 (complex (-  xr 1) xi))
          collect (list xr xi xc xc1)))
170
  nil)
171 172 173 174

(deftest 1-.15
  (macrolet ((%m (z) z)) (1- (expand-in-current-env (%m 2))))
  1)