logior.lsp 2.01 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Sep  9 06:08:21 2003
;;;; Contains: Tests of LOGIOR

6

7

8

9

10 11
;;; Error tests

12
(deftest logior.error.1
pfdietz's avatar
pfdietz committed
13
  (check-type-error #'logior #'integerp)
14 15 16
  nil)

(deftest logior.error.2
pfdietz's avatar
pfdietz committed
17
  (check-type-error #'(lambda (x) (logior 0 x)) #'integerp)
18 19
  nil)

20
;;; Non-error tests
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

(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*
sds's avatar
sds committed
36
        always (eql x (logior x)))
37 38 39 40
  t)

(deftest logior.5
  (loop for x in *integers*
sds's avatar
sds committed
41
        always (eql -1 (logior x (lognot x))))
42 43 44 45
  t)

(deftest logior.6
  (loop for x = (random-fixnum)
sds's avatar
sds committed
46 47 48 49
        for xc = (lognot x)
        repeat 1000
        unless (eql -1 (logior x xc))
        collect x)
50 51 52 53
  nil)

(deftest logior.7
  (loop for x = (random-from-interval (ash 1 (random 200)))
sds's avatar
sds committed
54 55 56 57 58 59 60 61 62 63 64 65
        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))
66 67 68 69
  nil)

(deftest logior.8
  (loop for i from 1 to (min 256 (1- call-arguments-limit))
sds's avatar
sds committed
70 71 72
        for args = (nconc (make-list (1- i) :initial-element 0)
                          (list -21231))
        always (eql (apply #'logior args) -21231))
73 74 75 76 77 78
  t)

(deftest logior.order.1
  (let ((i 0) a b)
    (values
     (logior (progn (setf a (incf i)) #b11010)
sds's avatar
sds committed
79
             (progn (setf b (incf i)) #b10110))
80 81 82 83 84 85 86
     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)
sds's avatar
sds committed
87 88
             (progn (setf b (incf i))  #b10110)
             (progn (setf c (incf i)) #b110101))
89 90 91 92
     i a b c))
  #b110111 3 1 2 3)