Commit 3e3fe7c1 authored by pfdietz's avatar pfdietz

Initial checkin of tests for LOGAND,...,LOGXOR.

parent 70942059
......@@ -61,6 +61,18 @@
(load "parse-integer.lsp")
(load "boole.lsp")
(load "logand.lsp")
(load "logandc1.lsp")
(load "logandc2.lsp")
(load "logeqv.lsp")
(load "logior.lsp")
(load "lognand.lsp")
(load "lognor.lsp")
(load "logorc1.lsp")
(load "logorc2.lsp")
(load "lognot.lsp")
(load "logxor.lsp")
(load "rational.lsp")
(load "rationalize.lsp")
......
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Mon Sep 8 21:23:22 2003
;;;; Contains: Tests of LOGAND
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logand.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logand ',x))) 'type-error))
collect x)
nil)
(deftest logand.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logand 0 ',x))) 'type-error))
collect x)
nil)
(deftest logand.1
(logand)
-1)
(deftest logand.2
(logand 1231)
1231)
(deftest logand.3
(logand -198)
-198)
(deftest logand.4
(loop for x in *integers*
always (eql x (logand x)))
t)
(deftest logand.5
(loop for x in *integers*
always (eql 0 (logand x (lognot x))))
t)
(deftest logand.6
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql 0 (logand x xc))
collect x)
nil)
(deftest logand.7
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logand x y)
repeat 1000
unless (and (if (and (< x 0) (< y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (and (logbitp i x)
(logbitp i y))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logand.8
(loop for i from 1 to (min 256 (1- call-arguments-limit))
for args = (nconc (make-list (1- i) :initial-element -1)
(list 183))
always (eql (apply #'logand args) 183))
t)
(deftest logand.order.1
(let ((i 0) a b)
(values
(logand (progn (setf a (incf i)) #b11011)
(progn (setf b (incf i)) #b10110))
i a b))
#b10010 2 1 2)
(deftest logand.order.2
(let ((i 0) a b c)
(values
(logand (progn (setf a (incf i)) #b11011)
(progn (setf b (incf i)) #b10110)
(progn (setf c (incf i)) #b110101))
i a b c))
#b10000 3 1 2 3)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Mon Sep 8 21:47:22 2003
;;;; Contains: Tests of LOGANDC1
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logandc1.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logandc1 ',x 0))) 'type-error))
collect x)
nil)
(deftest logandc1.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logandc1 0 ',x))) 'type-error))
collect x)
nil)
(deftest logandc1.error.3
(classify-error (logandc1))
program-error)
(deftest logandc1.error.4
(classify-error (logandc1 0))
program-error)
(deftest logandc1.error.5
(classify-error (logandc1 1 2 3))
program-error)
(deftest logandc1.1
(logandc1 0 0)
0)
(deftest logandc1.2
(logandc1 0 -1)
-1)
(deftest logandc1.3
(logandc1 0 123)
123)
(deftest logandc1.4
(loop for x in *integers*
always (and (eql x (logandc1 0 x))
(eql 0 (logandc1 x x))
(eql x (logandc1 (lognot x) x))
(eql (lognot x) (logandc1 x (lognot x)))))
t)
(deftest logandc1.5
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql x (logandc1 xc x))
collect x)
nil)
(deftest logandc1.6
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logandc1 x y)
repeat 1000
unless (and (if (and (>= x 0) (< y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (and (not (logbitp i x))
(logbitp i y))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logandc1.order.1
(let ((i 0) a b)
(values
(logandc1 (progn (setf a (incf i)) 0)
(progn (setf b (incf i)) -1))
i a b))
-1 2 1 2)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 05:52:31 2003
;;;; Contains: Tests of LOGANDC2
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logandc2.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logandc2 ',x 0))) 'type-error))
collect x)
nil)
(deftest logandc2.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logandc2 0 ',x))) 'type-error))
collect x)
nil)
(deftest logandc2.error.3
(classify-error (logandc2))
program-error)
(deftest logandc2.error.4
(classify-error (logandc2 0))
program-error)
(deftest logandc2.error.5
(classify-error (logandc2 1 2 3))
program-error)
(deftest logandc2.1
(logandc2 0 0)
0)
(deftest logandc2.2
(logandc2 -1 0)
-1)
(deftest logandc2.3
(logandc2 (1+ most-positive-fixnum) 0)
#.(1+ most-positive-fixnum))
(deftest logandc2.4
(loop for x in *integers*
always (and (eql x (logandc2 x 0))
(eql 0 (logandc2 x x))
(eql x (logandc2 x (lognot x)))
(eql (lognot x) (logandc2 (lognot x) x))))
t)
(deftest logandc2.5
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql x (logandc2 x xc))
collect x)
nil)
(deftest logandc2.6
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logandc2 x y)
repeat 1000
unless (and (if (and (< x 0) (>= y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (and (not (logbitp i y))
(logbitp i x))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logandc2.order.1
(let ((i 0) a b)
(values
(logandc2 (progn (setf a (incf i)) -1)
(progn (setf b (incf i)) 0))
i a b))
-1 2 1 2)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 05:55:23 2003
;;;; Contains: Tests of LOGEQV
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logeqv.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logeqv ',x))) 'type-error))
collect x)
nil)
(deftest logeqv.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logeqv 0 ',x))) 'type-error))
collect x)
nil)
(deftest logeqv.1
(logeqv)
-1)
(deftest logeqv.2
(logeqv 1231)
1231)
(deftest logeqv.3
(logeqv -198)
-198)
(deftest logeqv.4
(loop for x in *integers*
always (eql x (logeqv x)))
t)
(deftest logeqv.5
(loop for x in *integers*
always (eql 0 (logeqv x (lognot x))))
t)
(deftest logeqv.6
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql 0 (logeqv x xc))
collect x)
nil)
(deftest logeqv.7
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logeqv x y)
repeat 1000
unless (and (if (or (and (< x 0) (< y 0))
(and (>= x 0) (>= y 0)))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (or (and (logbitp i x)
(logbitp i y))
(and (not (logbitp i x))
(not (logbitp i y))))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logeqv.8
(loop for i from 1 to (min 256 (1- call-arguments-limit))
for args = (nconc (make-list (1- i) :initial-element -1)
(list 7131))
always (eql (apply #'logeqv args) 7131))
t)
(deftest logeqv.order.1
(let ((i 0) a b)
(values
(logeqv (progn (setf a (incf i)) #b11011)
(progn (setf b (incf i)) (lognot #b10110)))
i a b))
#b1101 2 1 2)
(deftest logeqv.order.2
(let ((i 0) a b c)
(values
(logeqv (progn (setf a (incf i)) #b11011)
(progn (setf b (incf i)) #b10110)
(progn (setf c (incf i)) #b110101))
i a b c))
#b111000 3 1 2 3)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 06:08:21 2003
;;;; Contains: Tests of LOGIOR
(in-package :cl-test)
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logior.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logior ',x))) 'type-error))
collect x)
nil)
(deftest logior.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logior 0 ',x))) 'type-error))
collect x)
nil)
(deftest logior.1
(logior)
0)
(deftest logior.2
(logior 1231)
1231)
(deftest logior.3
(logior -198)
-198)
(deftest logior.4
(loop for x in *integers*
always (eql x (logior x)))
t)
(deftest logior.5
(loop for x in *integers*
always (eql -1 (logior x (lognot x))))
t)
(deftest logior.6
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql -1 (logior x xc))
collect x)
nil)
(deftest logior.7
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logior x y)
repeat 1000
unless (and (if (or (< x 0) (< y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (or (logbitp i x)
(logbitp i y))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logior.8
(loop for i from 1 to (min 256 (1- call-arguments-limit))
for args = (nconc (make-list (1- i) :initial-element 0)
(list -21231))
always (eql (apply #'logior args) -21231))
t)
(deftest logior.order.1
(let ((i 0) a b)
(values
(logior (progn (setf a (incf i)) #b11010)
(progn (setf b (incf i)) #b10110))
i a b))
#b11110 2 1 2)
(deftest logior.order.2
(let ((i 0) a b c)
(values
(logior (progn (setf a (incf i)) #b10011)
(progn (setf b (incf i)) #b10110)
(progn (setf c (incf i)) #b110101))
i a b c))
#b110111 3 1 2 3)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 06:11:12 2003
;;;; Contains: Tests of LOGNAND
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest lognand.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lognand ',x 0))) 'type-error))
collect x)
nil)
(deftest lognand.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lognand 0 ',x))) 'type-error))
collect x)
nil)
(deftest lognand.error.3
(classify-error (lognand))
program-error)
(deftest lognand.error.4
(classify-error (lognand 0))
program-error)
(deftest lognand.error.5
(classify-error (lognand 1 2 3))
program-error)
(deftest lognand.1
(lognand 0 0)
-1)
(deftest lognand.2
(lognand 0 -1)
-1)
(deftest lognand.3
(lognand -1 123)
-124)
(deftest lognand.4
(loop for x in *integers*
always (and (eql -1 (lognand 0 x))
(eql (lognot x) (lognand x x))
(eql -1 (lognand (lognot x) x))
(eql -1 (lognand x (lognot x)))))
t)
(deftest lognand.5
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql -1 (lognand xc x))
collect x)
nil)
(deftest lognand.6
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (lognand x y)
repeat 1000
unless (and (if (or (>= x 0) (>= y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (not (and (logbitp i x)
(logbitp i y)))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest lognand.order.1
(let ((i 0) a b)
(values
(lognand (progn (setf a (incf i)) -2)
(progn (setf b (incf i)) -3))
i a b))
3 2 1 2)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 06:14:35 2003
;;;; Contains: Tests of LOGNOR
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest lognor.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lognor ',x 0))) 'type-error))
collect x)
nil)
(deftest lognor.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lognor 0 ',x))) 'type-error))
collect x)
nil)
(deftest lognor.error.3
(classify-error (lognor))
program-error)
(deftest lognor.error.4
(classify-error (lognor 0))
program-error)
(deftest lognor.error.5
(classify-error (lognor 1 2 3))
program-error)
(deftest lognor.1
(lognor 0 0)
-1)
(deftest lognor.2
(lognor 0 -1)
0)
(deftest lognor.3
(lognor -1 123)
0)
(deftest lognor.4
(loop for x in *integers*
always (and (eql (lognot x) (lognor 0 x))
(eql (lognot x) (lognor x x))
(eql 0 (lognor (lognot x) x))
(eql 0 (lognor x (lognot x)))))
t)
(deftest lognor.5
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql 0 (lognor xc x))
collect x)
nil)
(deftest lognor.6
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (lognor x y)
repeat 1000
unless (and (if (and (>= x 0) (>= y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (not (or (logbitp i x)
(logbitp i y)))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest lognor.order.1
(let ((i 0) a b)
(values
(lognor (progn (setf a (incf i)) -2)
(progn (setf b (incf i)) -3))
i a b))
0 2 1 2)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 06:16:20 2003
;;;; Contains: Tests of LOGNOT
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest lognot.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lognot ',x))) 'type-error))
collect x)
nil)
(deftest lognot.error.2
(classify-error (lognot))
program-error)
(deftest lognot.error.3
(classify-error (lognot 0 0))
program-error)
(deftest lognot.1
(lognot 0)
-1)
(deftest lognot.2
(lognot -1)
0)
(deftest lognot.3
(lognot 123)
-124)
(deftest lognot.4
(loop for x = (random-from-interval (ash 1 (random 200)))
for z = (lognot x)
repeat 1000
unless (and (if (>= x 0) (< z 0) (>= z 0))
(loop for i from 1 to 210
always (if (not (logbitp i x))
(logbitp i z)
(not (logbitp i z)))))
collect (list x z))
nil)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Sep 9 06:23:43 2003
;;;; Contains: Tests of LOGORC1
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest logorc1.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logorc1 ',x 0))) 'type-error))
collect x)
nil)
(deftest logorc1.error.2
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (logorc1 0 ',x))) 'type-error))
collect x)
nil)
(deftest logorc1.error.3
(classify-error (logorc1))
program-error)
(deftest logorc1.error.4
(classify-error (logorc1 0))
program-error)
(deftest logorc1.error.5
(classify-error (logorc1 1 2 3))
program-error)
(deftest logorc1.1
(logorc1 0 0)
-1)
(deftest logorc1.2
(logorc1 0 -1)
-1)
(deftest logorc1.2a
(logorc1 -1 0)
0)
(deftest logorc1.3
(logorc1 123 0)
-124)
(deftest logorc1.4
(loop for x in *integers*
always (and (eql -1 (logorc1 0 x))
(eql x (logorc1 -1 x))
(eql -1 (logorc1 x x))
(eql x (logorc1 (lognot x) x))
(eql (lognot x) (logorc1 x (lognot x)))))
t)
(deftest logorc1.5
(loop for x = (random-fixnum)
for xc = (lognot x)
repeat 1000
unless (eql x (logorc1 xc x))
collect x)
nil)
(deftest logorc1.6
(loop for x = (random-from-interval (ash 1 (random 200)))
for y = (random-from-interval (ash 1 (random 200)))
for z = (logorc1 x y)
repeat 1000
unless (and (if (or (>= x 0) (< y 0))
(< z 0)
(>= z 0))
(loop for i from 1 to 210
always (if (or (not (logbitp i x))
(logbitp i y))
(logbitp i z)
(not (logbitp i z)))))
collect (list x y z))
nil)
(deftest logorc1.order.1