Commit 2c8f3375 authored by pfdietz's avatar pfdietz

Initial versions of tests for 1+, 1-, and abs.

parent e8ca479f
;-*- 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)
......@@ -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")
......
;-*- 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)
;-*- 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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment