lognot.lsp 981 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Sep  9 06:16:20 2003
;;;; Contains: Tests of LOGNOT

(in-package :cl-test)

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

10 11
;;; Error tests

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

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

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

;;; Non-error tests
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

(deftest lognot.1
  (lognot 0)
  -1)

(deftest lognot.2
  (lognot -1)
  0)

(deftest lognot.3
  (lognot 123)
  -124)

(deftest lognot.4
  (loop for x = (random-from-interval (ash 1 (random 200)))
sds's avatar
sds committed
40 41 42 43 44 45 46 47
        for z = (lognot x)
        repeat 1000
        unless (and (if (>= x 0) (< z 0) (>= z 0))
                    (loop for i from 1 to 210
                          always (if (not (logbitp i x))
                                     (logbitp i z)
                                   (not (logbitp i z)))))
        collect (list x z))
48
  nil)