source: trunk/source/tests/ansi-tests/logcount.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: 1.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Sep 11 23:12:56 2003
4;;;; Contains: Tests of LOGCOUNT
5
6(in-package :cl-test)
7
8;;; Error tests
9
10(deftest logcount.error.1
11  (signals-error (logcount) program-error)
12  t)
13
14(deftest logcount.error.2
15  (signals-error (logcount 0 nil) program-error)
16  t)
17
18(deftest logcount.error.3
19  (check-type-error #'logcount #'integerp)
20  nil)
21
22;;; Non-error tests
23
24(deftest logcount.1
25  (logcount 0)
26  0)
27
28(deftest logcount.2
29  (logcount 1)
30  1)
31
32(deftest logcount.3
33  (logcount 2)
34  1)
35
36(deftest logcount.4
37  (logcount 3)
38  2)
39
40(deftest logcount.5
41  (logcount -1)
42  0)
43
44(deftest logcount.6
45  (loop for x = (random-fixnum)
46        repeat 100
47        always (eql (logcount x) (logcount (lognot x))))
48  t)
49
50(deftest logcount.7
51  (let ((bound (ash 1 300)))
52    (loop for x = (random-from-interval bound)
53          repeat 100
54          always (eql (logcount x) (logcount (lognot x)))))
55  t)
56
57(deftest logcount.8
58  (loop for y = (random (1+ most-positive-fixnum))
59        repeat 100
60        unless
61        (let ((cnt 0)
62              (x y))
63          (loop while (> x 0)
64                do
65                (when (oddp x) (incf cnt))
66                (setf x (ash x -1)))
67          (eql cnt (logcount y)))
68        collect y)
69  nil)
70
71
Note: See TracBrowser for help on using the repository browser.