Commit 151d1932 authored by pfdietz's avatar pfdietz

Add randomized tests for BIT-* operations

parent e643ef0c
......@@ -100,6 +100,9 @@ Got: 0
41. Add tests for MOD, REM
42. Add randomized tests for BIT-* functions (requested by piso on #lisp)
(partially done; tests on simple bit vectors going to a new bit vector
have been added; should add in-place versions and operations on non-simple
bit-vectors and non-vector arrays)
43. Add tests for structs that defining subtypes using :include doesn't change
the parent type(s). (This came up in ABCL.)
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-and.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-and.fold.1 (bit-and #*01101 #*01011))
;;; Randomized tests
(deftest bit-and.random.1
(bit-random-test-fn #'bit-and #'logand)
nil)
;;; Error tests
(deftest bit-and.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-andc1.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-andc1.fold.1 (bit-andc1 #*10010 #*01011))
;;; Random tests
(deftest bit-andc1.random.1
(bit-random-test-fn #'bit-andc1 #'logandc1)
nil)
;;; Error tests
(deftest bit-andc1.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-andc2.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-andc2.fold.1 (bit-andc2 #*01101 #*10100))
;;; Random tests
(deftest bit-andc2.random.1
(bit-random-test-fn #'bit-andc2 #'logandc2)
nil)
;;; Error tests
(deftest bit-andc2.error.1
......
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Jul 24 19:25:39 2005
;;;; Contains: Aux file for BIT-* tests
(in-package :cl-test)
(defun bit-random-test-fn (bit-fn log-fn &key (reps 5000) (maxlen 100))
(assert (typep maxlen '(integer (0))))
(assert (typep reps 'unsigned-byte))
(loop for len = (random maxlen)
for twos = (make-list len :initial-element 2)
for v1 = (map 'bit-vector #'random twos)
for v2 = (map 'bit-vector #'random twos)
for result = (funcall bit-fn v1 v2)
repeat reps
unless (and (= (length result) len)
(every #'(lambda (result-bit v1-bit v2-bit)
(= result-bit (logand 1 (funcall log-fn v1-bit v2-bit))))
result v1 v2))
collect (list len v1 v2 result)))
......@@ -6,6 +6,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-eqv.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -231,6 +233,12 @@
(def-fold-test bit-eqv.fold.1 (bit-eqv #*01101 #*10100))
;;; Random tests
(deftest bit-eqv.random.1
(bit-random-test-fn #'bit-eqv #'logeqv)
nil)
;;; Error tests
(deftest bit-eqv.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-ior.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-ior.fold.1 (bit-ior #*00101 #*10100))
;;; Random tests
(deftest bit-ior.random.1
(bit-random-test-fn #'bit-ior #'logior)
nil)
;;; Error tests
(deftest bit-ior.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-nand.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-nand.fold.1 (bit-nand #*00101 #*10100))
;;; Random tests
(deftest bit-nand.random.1
(bit-random-test-fn #'bit-nand #'lognand)
nil)
;;; Error tests
(deftest bit-nand.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-nor.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-nor.fold.1 (bit-nor #*00101 #*10100))
;;; Random tests
(deftest bit-nor.random.1
(bit-random-test-fn #'bit-nor #'lognor)
nil)
;;; Error tests
(deftest bit-nor.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-orc1.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -234,6 +236,12 @@
(values (%f) (let ((bv (%f))) (setf (elt bv 0) 0) bv) (%f)))
#*10101 #*00101 #*10101)
;;; Random tests
(deftest bit-orc1.random.1
(bit-random-test-fn #'bit-orc1 #'logorc1)
nil)
;;; Error tests
(deftest bit-orc1.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-orc2.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -234,6 +236,12 @@
(values (%f) (let ((bv (%f))) (setf (elt bv 0) 0) bv) (%f)))
#*10101 #*00101 #*10101)
;;; Random tests
(deftest bit-orc2.random.1
(bit-random-test-fn #'bit-orc2 #'logorc2)
nil)
;;; Error tests
(deftest bit-orc2.error.1
......
......@@ -5,6 +5,8 @@
(in-package :cl-test)
(compile-and-load "bit-aux.lsp")
(deftest bit-xor.1
(let* ((s1 (make-array nil :initial-element 0 :element-type 'bit))
(s2 (make-array nil :initial-element 0 :element-type 'bit)))
......@@ -230,6 +232,12 @@
(def-fold-test bit-xor.fold.1 (bit-xor #*00101 #*10100))
;;; Random tests
(deftest bit-xor.random.1
(bit-random-test-fn #'bit-xor #'logxor)
nil)
;;; Error tests
(deftest bit-xor.error.1
......
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