diff --git a/ansi-tests/abs.lsp b/ansi-tests/abs.lsp new file mode 100644 index 0000000000000000000000000000000000000000..33cdc9018e81d0c3600b2ea15a1d20f4c5f920e3 --- /dev/null +++ b/ansi-tests/abs.lsp @@ -0,0 +1,174 @@ +;-*- Mode: Lisp -*- +;;;; Author: Paul Dietz +;;;; Created: Mon Sep 1 20:16:42 2003 +;;;; Contains: Tests of ABS + +(in-package :cl-test) + +(compile-and-load "numbers-aux.lsp") + +(deftest abs.error.1 + (classify-error (abs)) + program-error) + +(deftest abs.error.2 + (classify-error (abs 0 0)) + program-error) + +(deftest abs.error.3 + (classify-error (abs 0 nil nil)) + program-error) + +(deftest abs.1 + (loop for x in *numbers* + for a = (abs x) + always (and (realp a) (not (minusp a)))) + t) + +(deftest abs.2 + (loop for x = (random-fixnum) + for a = (abs x) + repeat 10000 + unless (if (plusp x) (eql x a) (eql (- x) a)) + collect (list x a)) + nil) + +(deftest abs.3 + (let ((bound (ash 1 300))) + (loop for x = (random-from-interval bound) + for a = (abs x) + repeat 10000 + unless (if (plusp x) (eql x a) (eql (- x) a)) + collect (list x a))) + nil) + +(deftest abs.4 + (loop for num = (random-fixnum) + for den = (random-fixnum) + for den2 = (if (zerop den) 1 den) + for r = (/ num den) + for a = (abs r) + repeat 10000 + unless (if (>= r 0) (eql r a) (eql (- r) a)) + collect (list num den2 r a)) + nil) + +(deftest abs.5 + (let ((bound (ash 1 210))) + (loop + for num = (random-from-interval bound) + for den = (random-from-interval bound) + for den2 = (if (zerop den) 1 den) + for r = (/ num den) + for a = (abs r) + repeat 10000 + unless (if (>= r 0) (eql r a) (eql (- r) a)) + collect (list num den2 r a))) + nil) + +(deftest abs.6 + (let ((bound (float (ash 1 11) 1.0s0))) + (loop + for x = (random-from-interval bound) + for a = (abs x) + repeat 10000 + unless (if (minusp x) + (eql (- x) a) + (eql x a)) + collect (list x a))) + nil) + +(deftest abs.7 + (let ((bound (float (ash 1 22) 1.0f0))) + (loop + for x = (random-from-interval bound) + for a = (abs x) + repeat 10000 + unless (if (minusp x) + (eql (- x) a) + (eql x a)) + collect (list x a))) + nil) + +(deftest abs.8 + (let ((bound (float (ash 1 48) 1.0d0))) + (loop + for x = (random-from-interval bound) + for a = (abs x) + repeat 10000 + unless (if (minusp x) + (eql (- x) a) + (eql x a)) + collect (list x a))) + nil) + +(deftest abs.9 + (let ((bound (float (ash 1 48) 1.0l0))) + (loop + for x = (random-from-interval bound) + for a = (abs x) + repeat 10000 + unless (if (minusp x) + (eql (- x) a) + (eql x a)) + collect (list x a))) + nil) + +;;; The example on the abs page says that (abs -0.0) should be -0,0. +;;; However, FABS on the x86 returns 0.0 for that. Since the examples +;;; in the hyperspec are not normative, the following four tests +;;; have been commented out. + +;;; (deftest abs.10 +;;; (abs -0.0s0) +;;; -0.0s0) +;;; +;;; (deftest abs.11 +;;; (abs -0.0f0) +;;; -0.0f0) +;;; +;;; (deftest abs.12 +;;; (abs -0.0d0) +;;; -0.0d0) +;;; +;;; (deftest abs.13 +;;; (abs -0.0l0) +;;; -0.0l0) + +;;; Complex numbers + +(deftest abs.14 + (let ((result (abs #c(3 4)))) + (=t result 5)) + t) + +(deftest abs.15 + (let ((result (abs #c(-3 4)))) + (=t result 5)) + t) + +(deftest abs.16 + (let ((result (abs #c(3 -4)))) + (=t result 5)) + t) + +(deftest abs.17 + (let ((result (abs #c(-3 -4)))) + (=t result 5)) + t) + +(deftest abs.18 + (abs #c(3.0s0 4.0s0)) + 5.0s0) + +(deftest abs.19 + (abs #c(3.0f0 -4.0f0)) + 5.0f0) + +(deftest abs.20 + (abs #c(-3.0d0 4.0d0)) + 5.0d0) + +(deftest abs.21 + (abs #c(-3.0l0 4.0l0)) + 5.0l0) diff --git a/ansi-tests/load-numbers.lsp b/ansi-tests/load-numbers.lsp index 7fd8566af864bff8b370d0e67e75e48b15b33be5..232be5632eceb1faff1c66afc8db258178080634 100644 --- a/ansi-tests/load-numbers.lsp +++ b/ansi-tests/load-numbers.lsp @@ -27,6 +27,9 @@ (load "plus.lsp") (load "minus.lsp") (load "divide.lsp") +(load "oneplus.lsp") +(load "oneminus.lsp") +(load "abs.lsp") (load "rational.lsp") (load "rationalize.lsp") diff --git a/ansi-tests/oneminus.lsp b/ansi-tests/oneminus.lsp new file mode 100644 index 0000000000000000000000000000000000000000..677518d3a35c4f3f906149ab010d900a2ce40467 --- /dev/null +++ b/ansi-tests/oneminus.lsp @@ -0,0 +1,166 @@ +;-*- 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") + +(deftest 1-.error.1 + (classify-error (1-)) + program-error) + +(deftest 1-.error.2 + (classify-error (1- 0 0)) + program-error) + +(deftest 1-.error.3 + (classify-error (1- 0 nil nil)) + program-error) + +(deftest 1-.1 + (loop for x = (random-fixnum) + for y = (1- x) + for z = (- x 1) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.2 + (loop for x = (random-from-interval (ash 1 1000)) + for y = (1- x) + for z = (- x 1) + repeat 1000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.3 + (loop for x = (random (1- most-positive-short-float)) + for y = (1- x) + for z = (- x 1.0s0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.4 + (loop for x = (random (1- most-positive-single-float)) + for y = (1- x) + for z = (- x 1.0f0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.5 + (loop for x = (random (1- most-positive-double-float)) + for y = (1- x) + for z = (- x 1.0d0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.6 + (loop for x = (random (1- most-positive-long-float)) + for y = (1- x) + for z = (- x 1.0l0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1-.7 + (loop for x = (random-fixnum) + for y = (random-fixnum) + for y2 = (if (zerop y) 1 y) + for r = (/ x y2) + for r1 = (1- r) + for r2 = (- r 1) + repeat 10000 + unless (eql r1 r2) + collect (list x y2 r1 r2)) + nil) + +(deftest 1-.8 + (let ((bound (ash 1 200))) + (loop for x = (random-from-interval bound) + 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 10000 + unless (eql r1 r2) + collect (list x y2 r1 r2))) + nil) + +;;; Complex numbers +(deftest 1-.9 + (loop for xr = (random-fixnum) + for xi = (random-fixnum) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1)) + nil) + + +(deftest 1-.10 + (let ((bound (ash 1 100))) + (loop for xr = (random-from-interval bound) + for xi = (random-from-interval bound) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1-.11 + (let ((bound (1- most-positive-short-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1-.12 + (let ((bound (1- most-positive-single-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1-.13 + (let ((bound (1- most-positive-double-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1-.14 + (let ((bound (1- most-positive-long-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1- xc) + repeat 10000 + unless (eql xc1 (complex (- xr 1) xi)) + collect (list xr xi xc xc1))) + nil) diff --git a/ansi-tests/oneplus.lsp b/ansi-tests/oneplus.lsp new file mode 100644 index 0000000000000000000000000000000000000000..490e804e8d7b72bcc4d235b61688def7fbc35c6f --- /dev/null +++ b/ansi-tests/oneplus.lsp @@ -0,0 +1,166 @@ +;-*- 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 + (classify-error (1+)) + program-error) + +(deftest 1+.error.2 + (classify-error (1+ 0 0)) + program-error) + +(deftest 1+.error.3 + (classify-error (1+ 0 nil nil)) + program-error) + +(deftest 1+.1 + (loop for x = (random-fixnum) + for y = (1+ x) + for z = (+ x 1) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.2 + (loop for x = (random-from-interval (ash 1 1000)) + for y = (1+ x) + for z = (+ x 1) + repeat 1000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.3 + (loop for x = (random (1- most-positive-short-float)) + for y = (1+ x) + for z = (+ x 1.0s0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.4 + (loop for x = (random (1- most-positive-single-float)) + for y = (1+ x) + for z = (+ x 1.0f0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.5 + (loop for x = (random (1- most-positive-double-float)) + for y = (1+ x) + for z = (+ x 1.0d0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.6 + (loop for x = (random (1- most-positive-long-float)) + for y = (1+ x) + for z = (+ x 1.0l0) + repeat 10000 + unless (eql y z) + collect (list x y z)) + nil) + +(deftest 1+.7 + (loop for x = (random-fixnum) + for y = (random-fixnum) + for y2 = (if (zerop y) 1 y) + for r = (/ x y2) + for r1 = (1+ r) + for r2 = (+ r 1) + repeat 10000 + unless (eql r1 r2) + collect (list x y2 r1 r2)) + nil) + +(deftest 1+.8 + (let ((bound (ash 1 200))) + (loop for x = (random-from-interval bound) + 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 10000 + unless (eql r1 r2) + collect (list x y2 r1 r2))) + nil) + +;;; Complex numbers +(deftest 1+.9 + (loop for xr = (random-fixnum) + for xi = (random-fixnum) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1)) + nil) + + +(deftest 1+.10 + (let ((bound (ash 1 100))) + (loop for xr = (random-from-interval bound) + for xi = (random-from-interval bound) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1+.11 + (let ((bound (1- most-positive-short-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1+.12 + (let ((bound (1- most-positive-single-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1+.13 + (let ((bound (1- most-positive-double-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1))) + nil) + +(deftest 1+.14 + (let ((bound (1- most-positive-long-float))) + (loop for xr = (random bound) + for xi = (random bound) + for xc = (complex xr xi) + for xc1 = (1+ xc) + repeat 10000 + unless (eql xc1 (complex (+ xr 1) xi)) + collect (list xr xi xc xc1))) + nil)