logeqv.lsp 2.27 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Sep  9 05:55:23 2003
;;;; Contains: Tests of LOGEQV

(in-package :cl-test)

(compile-and-load "numbers-aux.lsp")

10 11
;;; Error tests

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

(deftest logeqv.error.2
pfdietz's avatar
pfdietz committed
17
  (check-type-error #'(lambda (x) (logeqv 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 logeqv.1
  (logeqv)
  -1)

(deftest logeqv.2
  (logeqv 1231)
  1231)

(deftest logeqv.3
  (logeqv -198)
  -198)

(deftest logeqv.4
  (loop for x in *integers*
sds's avatar
sds committed
36
        always (eql x (logeqv x)))
37 38 39 40
  t)

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

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

(deftest logeqv.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 66 67 68
        for y = (random-from-interval (ash 1 (random 200)))
        for z = (logeqv x y)
        repeat 1000
        unless (and (if (or (and (< x 0) (< y 0))
                            (and (>= x 0) (>= y 0)))
                        (< z 0)
                      (>= z 0))
                    (loop for i from 1 to 210
                          always (if (or (and (logbitp i x)
                                              (logbitp i y))
                                         (and (not (logbitp i x))
                                              (not (logbitp i y))))
                                     (logbitp i z)
                                   (not (logbitp i z)))))
        collect (list x y z))
69 70 71 72
  nil)

(deftest logeqv.8
  (loop for i from 1 to (min 256 (1- call-arguments-limit))
sds's avatar
sds committed
73 74 75 76
        for args = (nconc (make-list (1- i) :initial-element -1)
                          (list 7131))
        always (eql (apply #'logeqv args) 7131))
  t)
77 78 79 80 81

(deftest logeqv.order.1
  (let ((i 0) a b)
    (values
     (logeqv (progn (setf a (incf i)) #b11011)
sds's avatar
sds committed
82
             (progn (setf b (incf i)) (lognot #b10110)))
83 84
     i a b))
  #b1101 2 1 2)
sds's avatar
sds committed
85

86 87 88 89 90

(deftest logeqv.order.2
  (let ((i 0) a b c)
    (values
     (logeqv (progn (setf a (incf i))  #b11011)
sds's avatar
sds committed
91 92
             (progn (setf b (incf i))  #b10110)
             (progn (setf c (incf i)) #b110101))
93 94
     i a b c))
  #b111000 3 1 2 3)