oneplus.lsp 4.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Sep  1 19:53:34 2003
;;;; Contains: Tests of 1+

(in-package :cl-test)

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

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

(deftest 1+.error.2
15 16
  (signals-error (1+ 0 0) program-error)
  t)
17 18

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

(deftest 1+.1
  (loop for x = (random-fixnum)
sds's avatar
sds committed
24 25 26 27 28
        for y = (1+ x)
        for z = (+ x 1)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
29 30 31 32
  nil)

(deftest 1+.2
  (loop for x = (random-from-interval (ash 1 1000))
sds's avatar
sds committed
33 34 35 36 37
        for y = (1+ x)
        for z = (+ x 1)
        repeat 1000
        unless (eql y z)
        collect (list x y z))
38 39 40 41
  nil)

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

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

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

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

(deftest 1+.7
  (loop for x = (random-fixnum)
sds's avatar
sds committed
78 79 80 81 82 83 84 85
        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))
86 87 88 89 90
  nil)

(deftest 1+.8
  (let ((bound (ash 1 200)))
    (loop for x = (random-from-interval bound)
sds's avatar
sds committed
91 92 93 94 95 96 97 98
          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)))
99 100 101 102 103
  nil)

;;; Complex numbers
(deftest 1+.9
  (loop for xr = (random-fixnum)
sds's avatar
sds committed
104 105 106 107 108 109
        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))
110 111 112 113 114 115
  nil)


(deftest 1+.10
  (let ((bound (ash 1 100)))
    (loop for xr = (random-from-interval bound)
sds's avatar
sds committed
116 117 118 119 120 121
          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)))
122 123 124 125 126
  nil)

(deftest 1+.11
  (let ((bound (1- most-positive-short-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
127 128 129 130 131 132
          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)))
133 134 135 136 137
  nil)

(deftest 1+.12
  (let ((bound (1- most-positive-single-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
138 139 140 141 142 143
          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)))
144 145 146 147 148
  nil)

(deftest 1+.13
  (let ((bound (1- most-positive-double-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
149 150 151 152 153 154
          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)))
155 156 157 158 159
  nil)

(deftest 1+.14
  (let ((bound (1- most-positive-long-float)))
    (loop for xr = (random bound)
sds's avatar
sds committed
160 161 162 163 164 165
          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)))
166
  nil)
167 168 169 170

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