source: trunk/source/tests/ansi-tests/dpb.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 2.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Sep 11 20:43:54 2003
4;;;; Contains: Tests of DPB
5
6(in-package :cl-test)
7
8;;; Error tests
9
10(deftest dpb.error.1
11  (signals-error (dpb) program-error)
12  t)
13
14(deftest dpb.error.2
15  (signals-error (dpb 1) program-error)
16  t)
17
18(deftest dpb.error.3
19  (signals-error (dpb 1 (byte 1 0)) program-error)
20  t)
21
22(deftest dpb.error.4
23  (signals-error (dpb 1 (byte 1 0) 0 nil) program-error)
24  t)
25
26;;; Non-error tests
27
28(deftest dpb.1
29  (loop for pos = (random 32)
30        for size = (random 32)
31        for newbyte = (random (ash 1 (+ pos size)))
32        for val = (random (1+ (random (ash 1 (+ pos size)))))
33        for result = (dpb newbyte (byte size pos) val)
34        repeat 100
35        unless
36        (loop for i from 0 to (+ pos size)
37              always (if (or (< i pos)
38                             (>= i (+ pos size)))
39                         (if (logbitp i val) (logbitp i result)
40                           (not (logbitp i result)))
41                       (if (logbitp (- i pos) newbyte) (logbitp i result)
42                           (not (logbitp i result)))))
43        collect (list pos size newbyte val result))
44  nil)
45
46(deftest dpb.2
47  (loop for pos = (random 1000)
48        for size = (random 1000)
49        for newbyte = (random (ash 1 (+ pos size)))
50        for val = (random (1+ (random (ash 1 (+ pos size)))))
51        for result = (dpb newbyte (byte size pos) val)
52        repeat 100
53        unless
54        (loop for i from 0 to (+ pos size)
55              always (if (or (< i pos)
56                             (>= i (+ pos size)))
57                         (if (logbitp i val) (logbitp i result)
58                           (not (logbitp i result)))
59                       (if (logbitp (- i pos) newbyte) (logbitp i result)
60                           (not (logbitp i result)))))
61        collect (list pos size newbyte val result))
62  nil)
63
64(deftest dpb.3
65  (loop for x = (random-fixnum)
66        for y = (random-fixnum)
67        for pos = (random 32)
68        repeat 100
69        always (= (dpb x (byte 0 pos) y) y))
70  t)
71
72(deftest dpb.4
73  (let ((bound (ash 1 200)))
74    (loop for x = (random-from-interval bound)
75          for y = (random-from-interval bound)
76          for pos = (random 200)
77          repeat 100
78          always (= (dpb x (byte 0 pos) y) y)))
79  t)
80
81(deftest dpb.5
82  (loop for i of-type fixnum from -1000 to 1000
83        always (eql (dpb -1 (byte 0 0) i) i))
84  t)
Note: See TracBrowser for help on using the repository browser.