dpb.lsp 2.37 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Sep 11 20:43:54 2003
;;;; Contains: Tests of DPB

6

7

8 9
;;; Error tests

10
(deftest dpb.error.1
11 12
  (signals-error (dpb) program-error)
  t)
13 14

(deftest dpb.error.2
15 16
  (signals-error (dpb 1) program-error)
  t)
17 18

(deftest dpb.error.3
19 20
  (signals-error (dpb 1 (byte 1 0)) program-error)
  t)
21 22

(deftest dpb.error.4
23 24 25 26
  (signals-error (dpb 1 (byte 1 0) 0 nil) program-error)
  t)

;;; Non-error tests
27 28 29

(deftest dpb.1
  (loop for pos = (random 32)
sds's avatar
sds committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43
        for size = (random 32)
        for newbyte = (random (ash 1 (+ pos size)))
        for val = (random (1+ (random (ash 1 (+ pos size)))))
        for result = (dpb newbyte (byte size pos) val)
        repeat 100
        unless
        (loop for i from 0 to (+ pos size)
              always (if (or (< i pos)
                             (>= i (+ pos size)))
                         (if (logbitp i val) (logbitp i result)
                           (not (logbitp i result)))
                       (if (logbitp (- i pos) newbyte) (logbitp i result)
                           (not (logbitp i result)))))
        collect (list pos size newbyte val result))
44 45 46 47
  nil)

(deftest dpb.2
  (loop for pos = (random 1000)
sds's avatar
sds committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
        for size = (random 1000)
        for newbyte = (random (ash 1 (+ pos size)))
        for val = (random (1+ (random (ash 1 (+ pos size)))))
        for result = (dpb newbyte (byte size pos) val)
        repeat 100
        unless
        (loop for i from 0 to (+ pos size)
              always (if (or (< i pos)
                             (>= i (+ pos size)))
                         (if (logbitp i val) (logbitp i result)
                           (not (logbitp i result)))
                       (if (logbitp (- i pos) newbyte) (logbitp i result)
                           (not (logbitp i result)))))
        collect (list pos size newbyte val result))
62 63 64 65
  nil)

(deftest dpb.3
  (loop for x = (random-fixnum)
sds's avatar
sds committed
66 67 68 69
        for y = (random-fixnum)
        for pos = (random 32)
        repeat 100
        always (= (dpb x (byte 0 pos) y) y))
70 71 72 73 74
  t)

(deftest dpb.4
  (let ((bound (ash 1 200)))
    (loop for x = (random-from-interval bound)
sds's avatar
sds committed
75 76 77 78
          for y = (random-from-interval bound)
          for pos = (random 200)
          repeat 100
          always (= (dpb x (byte 0 pos) y) y)))
79 80 81 82
  t)

(deftest dpb.5
  (loop for i of-type fixnum from -1000 to 1000
sds's avatar
sds committed
83
        always (eql (dpb -1 (byte 0 0) i) i))
84
  t)