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

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

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

File size: 1.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Sep  9 05:52:31 2003
4;;;; Contains: Tests of LOGANDC2
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9
10;;; Error tests
11
12(deftest logandc2.error.1
13  (check-type-error #'(lambda (x) (logandc2 x 0)) #'integerp)
14  nil)
15
16(deftest logandc2.error.2
17  (check-type-error #'(lambda (x) (logandc2 0 x)) #'integerp)
18  nil)
19
20(deftest logandc2.error.3
21  (signals-error (logandc2) program-error)
22  t)
23
24(deftest logandc2.error.4
25  (signals-error (logandc2 0) program-error)
26  t)
27
28(deftest logandc2.error.5
29  (signals-error (logandc2 1 2 3) program-error)
30  t)
31
32;;; Non-error tests
33
34(deftest logandc2.1
35  (logandc2 0 0)
36  0)
37
38(deftest logandc2.2
39  (logandc2 -1 0)
40  -1)
41
42(deftest logandc2.3
43  (logandc2 (1+ most-positive-fixnum) 0)
44  #.(1+ most-positive-fixnum))
45
46(deftest logandc2.4
47  (loop for x in *integers*
48        always (and (eql x (logandc2 x 0))
49                    (eql 0 (logandc2 x x))
50                    (eql x (logandc2 x (lognot x)))
51                    (eql (lognot x) (logandc2 (lognot x) x))))
52  t)
53
54(deftest logandc2.5
55  (loop for x = (random-fixnum)
56        for xc = (lognot x)
57        repeat 1000
58        unless (eql x (logandc2 x xc))
59        collect x)
60  nil)
61
62(deftest logandc2.6
63  (loop for x = (random-from-interval (ash 1 (random 200)))
64        for y = (random-from-interval (ash 1 (random 200)))
65        for z = (logandc2 x y)
66        repeat 1000
67        unless (and (if (and (< x 0) (>= y 0))
68                        (< z 0)
69                      (>= z 0))
70                    (loop for i from 1 to 210
71                          always (if (and (not (logbitp i y))
72                                          (logbitp i x))
73                                     (logbitp i z)
74                                   (not (logbitp i z)))))
75        collect (list x y z))
76  nil)
77
78(deftest logandc2.order.1
79  (let ((i 0) a b)
80    (values
81     (logandc2 (progn (setf a (incf i)) -1)
82               (progn (setf b (incf i)) 0))
83     i a b))
84  -1 2 1 2)
Note: See TracBrowser for help on using the repository browser.