logbitp.lsp 1.8 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Sep  9 07:02:00 2003
;;;; Contains: Tests of LOGBITP

6

7

8

9

10 11
;;; Error tests

12
(deftest logbitp.error.1
13 14
  (signals-error (logbitp) program-error)
  t)
15 16

(deftest logbitp.error.2
17 18
  (signals-error (logbitp 0) program-error)
  t)
19 20

(deftest logbitp.error.3
21 22
  (signals-error (logbitp 0 0 0) program-error)
  t)
23 24

(deftest logbitp.error.4
pfdietz's avatar
pfdietz committed
25 26
  (check-type-error #'(lambda (x) (logbitp x 0)) (typef 'unsigned-byte))
  nil)
27 28

(deftest logbitp.error.5
pfdietz's avatar
pfdietz committed
29
  (check-type-error #'(lambda (x) (logbitp 0 x)) #'integerp)
30 31
  nil)

32 33
;;; Non-error tests

34 35
(deftest logbitp.1
  (loop for x in *integers*
sds's avatar
sds committed
36 37
        unless (if (logbitp 0 x) (oddp x) (evenp x))
        collect x)
38 39 40 41
  nil)

(deftest logbitp.2
  (loop for len from 0 to 300
sds's avatar
sds committed
42 43 44 45 46
        for i = (ash 1 len)
        always (and (logbitp len i)
                    (loop for j from 0 to 300
                          always (or (eql j len)
                                     (not (logbitp j i))))))
47 48 49 50
  t)

(deftest logbitp.3
  (logbitp most-positive-fixnum 0)
51
  nil)
sds's avatar
sds committed
52

53 54 55 56 57 58
(deftest logbitp.4
  (notnot-mv (logbitp most-positive-fixnum -1))
  t)

(deftest logbitp.5
  (logbitp (1+ most-positive-fixnum) 0)
59
  nil)
sds's avatar
sds committed
60

61 62 63 64
(deftest logbitp.6
  (notnot-mv (logbitp (1+ most-positive-fixnum) -1))
  t)

65 66
(deftest logbitp.7
  (loop for len = (random 100)
sds's avatar
sds committed
67 68 69 70 71 72 73
        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))
74 75 76 77
  nil)

(deftest logbitp.8
  (loop for k from 1 to 1000
sds's avatar
sds committed
78
        always (logbitp k -1))
79 80
  t)

81 82 83 84
(deftest logbitp.order.1
  (let ((i 0) a b)
    (values
     (logbitp (progn (setf a (incf i)) 2)
sds's avatar
sds committed
85
              (progn (setf b (incf i)) #b111010))
86 87 88 89 90 91
     i a b))
  nil 2 1 2)




sds's avatar
sds committed
92 93