2
;;;; Author: Paul Dietz
3
;;;; Created: Mon Sep 8 20:21:19 2003
4
;;;; Contains: Tests of BOOLE and associated constants
8
(compile-and-load "numbers-aux.lsp")
10
(defparameter *boole-val-names*
11
'(boole-1 boole-2 boole-and boole-andc1 boole-andc2
12
boole-c1 boole-c2 boole-clr boole-eqv boole-ior
13
boole-nand boole-nor boole-orc1 boole-orc2 boole-set boole-xor))
15
(defparameter *boole-vals*
16
(list boole-1 boole-2 boole-and boole-andc1 boole-andc2
17
boole-c1 boole-c2 boole-clr boole-eqv boole-ior boole-nand
18
boole-nor boole-orc1 boole-orc2 boole-set boole-xor))
20
(defparameter *boole-fns*
21
(list #'(lambda (x y) (declare (ignore y)) x)
22
#'(lambda (x y) (declare (ignore x)) y)
26
#'(lambda (x y) (declare (ignore y)) (lognot x))
27
#'(lambda (x y) (declare (ignore x)) (lognot y))
38
(deftest boole.error.1
39
(signals-error (boole) program-error)
42
(deftest boole.error.2
43
(signals-error (boole boole-1) program-error)
46
(deftest boole.error.3
47
(signals-error (boole boole-1 1) program-error)
50
(deftest boole.error.4
51
(signals-error (boole boole-1 1 2 nil) program-error)
54
(deftest boole.error.5
55
(let ((bad (loop for i from 1 until (not (member i *boole-vals*)))))
56
(eval `(signals-error (boole ,bad 1 1) type-error)))
59
(deftest boole.error.6
60
(loop for n in *boole-val-names*
61
unless (eval `(signals-error (boole ,n nil 1) type-error))
65
(deftest boole.error.7
66
(loop for n in *boole-val-names*
67
unless (eval `(signals-error (boole ,n 1 nil) type-error))
72
(loop for v in *boole-vals*
73
for fn of-type function in *boole-fns*
74
for n in *boole-val-names*
76
(loop for x = (random-fixnum)
77
for y = (random-fixnum)
78
for result1 = (funcall (the function fn) x y)
79
for vals = (multiple-value-list (boole v x y))
80
for result2 = (car vals)
82
unless (and (= (length vals) 1) (eql result1 result2))
83
collect (list n x y result1 result2)))
87
(loop for v in *boole-vals*
88
for fn of-type function in *boole-fns*
89
for n in *boole-val-names*
91
(loop for x = (random-from-interval 1000000000000000)
92
for y = (random-from-interval 1000000000000000)
93
for result1 = (funcall (the function fn) x y)
94
for vals = (multiple-value-list (boole v x y))
95
for result2 = (car vals)
97
unless (and (= (length vals) 1) (eql result1 result2))
98
collect (list n x y result1 result2)))
102
(loop for n in *boole-val-names*
103
for fn of-type function in *boole-fns*
104
for fn2 = (compile nil `(lambda (x y) (declare (type fixnum x y))
107
(loop for x = (random-fixnum)
108
for y = (random-fixnum)
109
for result1 = (funcall (the function fn) x y)
110
for vals = (multiple-value-list (funcall fn2 x y))
111
for result2 = (car vals)
113
unless (and (= (length vals) 1) (eql result1 result2))
114
collect (list n x y result1 result2)))
117
;;; Order of evaluation
118
(deftest boole.order.1
122
(progn (setf a (incf i)) boole-and)
123
(progn (setf b (incf i)) #b1101)
124
(progn (setf c (incf i)) #b11001))
128
;;; Constants are constants
130
(deftest boole.constants.1
131
(eqlt (length *boole-vals*)
132
(length (remove-duplicates *boole-vals*)))
135
(deftest boole.constants.2
136
(remove-if #'constantp *boole-val-names*)
139
(deftest boole.constants.3
140
(remove-if #'boundp *boole-val-names*)