Skip to content
Snippets Groups Projects
Commit 44295dd3 authored by pfdietz's avatar pfdietz
Browse files

More LOGBITP tests, and a function to randomly test compiled LOG* functions with declarations.

parent f09cefad
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,22 @@ ...@@ -61,6 +61,22 @@
(notnot-mv (logbitp (1+ most-positive-fixnum) -1)) (notnot-mv (logbitp (1+ most-positive-fixnum) -1))
t) t)
(deftest logbitp.7
(loop for len = (random 100)
for i = (random-from-interval (ash 1 len))
for k = (random (1+ len))
repeat 1000
unless (if (ldb-test (byte 1 k) i)
(logbitp k i)
(not (logbitp k i)))
collect (list i k))
nil)
(deftest logbitp.8
(loop for k from 1 to 1000
always (logbitp k -1))
t)
(deftest logbitp.order.1 (deftest logbitp.order.1
(let ((i 0) a b) (let ((i 0) a b)
(values (values
......
...@@ -249,3 +249,35 @@ ...@@ -249,3 +249,35 @@
;;; Approximate equality function ;;; Approximate equality function
(defun approx= (x y &optional (eps (epsilon x))) (defun approx= (x y &optional (eps (epsilon x)))
(<= (abs (/ (- x y) (max (abs x) 1))) eps)) (<= (abs (/ (- x y) (max (abs x) 1))) eps))
(defun test-log-op-with-decls (op xlo xhi ylo yhi niters
&optional
(decls '((optimize (speed 3) (safety 1)
(debug 1)))))
"Test that a compiled form of the LOG* function OP computes
the expected result on two random integers drawn from the
types `(integer ,xlo ,xhi) and `(integer ,ylo ,yhi). Try
niters choices. Return a list of pairs on which the test fails."
(assert (symbolp op))
(assert (integerp xlo))
(assert (integerp xhi))
(assert (integerp ylo))
(assert (integerp yhi))
(assert (integerp niters))
(assert (<= xlo xhi))
(assert (<= ylo yhi))
(let* ((source
`(lambda (x y)
(declare (type (integer ,xlo ,xhi) x)
(type (integer ,ylo ,yhi) y)
,@ decls)
(,op x y)))
(fn (compile nil source)))
(loop for i below niters
for x = (random-from-interval xhi xlo)
for y = (random-from-interval yhi ylo)
unless (eql (funcall (the symbol op) x y)
(funcall fn x y))
collect (list x y))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment