source: trunk/source/tests/ansi-tests/logand.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.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Mon Sep  8 21:23:22 2003
4;;;; Contains: Tests of LOGAND
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9
10;;; Error tests
11
12(deftest logand.error.1
13  (check-type-error #'logand #'integerp)
14  nil)
15
16(deftest logand.error.2
17  (check-type-error #'(lambda (x) (logand 0 x)) #'integerp)
18  nil)
19
20(deftest logand.error.3
21  (check-type-error #'(lambda (x) (logand x 1)) #'integerp)
22  nil)
23
24;;; Non-error tests
25
26(deftest logand.1
27  (logand)
28  -1)
29
30(deftest logand.2
31  (logand 1231)
32  1231)
33
34(deftest logand.3
35  (logand -198)
36  -198)
37
38(deftest logand.4
39  (loop for x in *integers*
40        always (eql x (logand x)))
41  t)
42
43(deftest logand.5
44  (loop for x in *integers*
45        always (eql 0 (logand x (lognot x))))
46  t)
47
48(deftest logand.6
49  (loop for x = (random-fixnum)
50        for xc = (lognot x)
51        repeat 1000
52        unless (eql 0 (logand x xc))
53        collect x)
54  nil)
55
56(deftest logand.7
57  (loop for x = (random-from-interval (ash 1 (random 200)))
58        for y = (random-from-interval (ash 1 (random 200)))
59        for z = (logand x y)
60        repeat 1000
61        unless (and (if (and (< x 0) (< y 0))
62                        (< z 0)
63                      (>= z 0))
64                    (loop for i from 1 to 210
65                          always (if (and (logbitp i x)
66                                          (logbitp i y))
67                                     (logbitp i z)
68                                   (not (logbitp i z)))))
69        collect (list x y z))
70  nil)
71
72(deftest logand.8
73  (loop for i from 1 to (min 256 (1- call-arguments-limit))
74        for args = (nconc (make-list (1- i) :initial-element -1)
75                          (list 183))
76        always (eql (apply #'logand args) 183))
77  t)
78
79(deftest logand.9
80  (loop for i from -1 to 0 always
81        (loop for j from -1 to 0 always
82              (locally (declare (type (integer -1 0) i j))
83                       (eql (logand i j) (if (or (zerop i) (zerop j)) 0 -1)))))
84  t)
85
86(deftest logand.order.1
87  (let ((i 0) a b)
88    (values
89     (logand (progn (setf a (incf i)) #b11011)
90             (progn (setf b (incf i)) #b10110))
91     i a b))
92  #b10010 2 1 2)
93
94(deftest logand.order.2
95  (let ((i 0) a b c)
96    (values
97     (logand (progn (setf a (incf i))  #b11011)
98             (progn (setf b (incf i))  #b10110)
99             (progn (setf c (incf i)) #b110101))
100     i a b c))
101  #b10000 3 1 2 3)
Note: See TracBrowser for help on using the repository browser.