source: trunk/source/tests/ansi-tests/search-bitvector.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: 5.2 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Aug 25 13:06:54 2002
4;;;; Contains: Tests for SEARCH on bit vectors
5
6(in-package :cl-test)
7
8(compile-and-load "search-aux.lsp")
9
10(deftest search-bitvector.1
11  (let ((target *searched-bitvector*)
12        (pat #*0))
13    (loop for i from 0 to (1- (length target))
14          for tail = (subseq target i)
15          always
16          (let ((pos (search pat tail)))
17            (search-check pat tail pos))))
18  t)
19
20(deftest search-bitvector.2
21  (let ((target *searched-bitvector*)
22        (pat #*0))
23    (loop for i from 1 to (length target)
24          always
25          (let ((pos (search pat target :end2 i :from-end t)))
26            (search-check pat target pos :end2 i :from-end t))))
27  t)
28
29(deftest search-bitvector.3
30  (let ((target *searched-bitvector*))
31    (loop for pat in *pattern-subbitvectors*
32          for pos = (search pat target)
33          unless (search-check pat target pos)
34          collect pat))
35  nil)
36
37(deftest search-bitvector.4
38  (let ((target *searched-bitvector*))
39    (loop for pat in *pattern-subbitvectors*
40          for pos = (search pat target :from-end t)
41          unless (search-check pat target pos :from-end t)
42          collect pat))
43  nil)
44
45(deftest search-bitvector.5
46  (let ((target *searched-bitvector*))
47    (loop for pat in *pattern-subbitvectors*
48          for pos = (search pat target :start2 25 :end2 75)
49          unless (search-check pat target pos :start2 25 :end2 75)
50          collect pat))
51  nil)
52
53(deftest search-bitvector.6
54  (let ((target *searched-bitvector*))
55    (loop for pat in *pattern-subbitvectors*
56          for pos = (search pat target :from-end t :start2 25 :end2 75)
57          unless (search-check pat target pos :from-end t
58                               :start2 25 :end2 75)
59          collect pat))
60  nil)
61
62(deftest search-bitvector.7
63  (let ((target *searched-bitvector*))
64    (loop for pat in *pattern-subbitvectors*
65          for pos = (search pat target :start2 20)
66          unless (search-check pat target pos :start2 20)
67          collect pat))
68  nil)
69
70(deftest search-bitvector.8
71  (let ((target *searched-bitvector*))
72    (loop for pat in *pattern-subbitvectors*
73          for pos = (search pat target :from-end t :start2 20)
74          unless (search-check pat target pos :from-end t
75                               :start2 20)
76          collect pat))
77  nil)
78
79(deftest search-bitvector.9
80  (let ((target *searched-bitvector*))
81    (loop for pat in (mapcar #'(lambda (x)
82                                 (map 'vector
83                                      #'(lambda (y)
84                                          (sublis '((a . 2) (b . 3)) y))
85                                      x))
86                             *pattern-sublists*)
87          for pos = (search pat target :start2 20 :key #'evenp)
88          unless (search-check pat target pos :start2 20 :key #'evenp)
89          collect pat))
90  nil)
91
92(deftest search-bitvector.10
93  (let ((target *searched-bitvector*))
94    (loop for pat in (mapcar #'(lambda (x)
95                                 (map 'vector
96                                      #'(lambda (y)
97                                          (sublis '((a . 2) (b . 3)) y))
98                                      x))
99                             *pattern-sublists*)
100          for pos = (search pat target :from-end t :start2 20 :key 'oddp)
101          unless (search-check pat target pos :from-end t
102                               :start2 20 :key 'oddp)
103          collect pat))
104  nil)
105
106(deftest search-bitvector.11
107  (let ((target *searched-bitvector*))
108    (loop for pat in *pattern-subbitvectors*
109          for pos = (search pat target :start2 20 :test (complement #'eql))
110          unless (search-check pat target pos :start2 20
111                               :test (complement #'eql))
112          collect pat))
113  nil)
114
115(deftest search-bitvector.12
116  (let ((target *searched-bitvector*))
117    (loop for pat in *pattern-subbitvectors*
118          for pos = (search pat target :from-end t :start2 20 :test-not #'eql)
119          unless (search-check pat target pos :from-end t
120                               :start2 20 :test (complement #'eql))
121          collect pat))
122  nil)
123
124(deftest search-bitvector.13
125  (let ((target *searched-bitvector*))
126    (loop for pat in *pattern-subbitvectors*
127          when (and (> (length pat) 0)
128                    (let ((pos (search pat target :start1 1
129                                       :test (complement #'eql))))
130                      (not (search-check pat target pos
131                                         :start1 1
132                                         :test (complement #'eql)))))
133          collect pat))
134  nil)
135
136(deftest search-bitvector.14
137  (let ((target *searched-bitvector*))
138    (loop for pat in *pattern-subbitvectors*
139          when (let ((len (length pat)))
140                 (and (> len 0)
141                      (let ((pos (search pat target :end1 (1- len)
142                                         :test (complement #'eql))))
143                      (not (search-check pat target pos
144                                         :end1 (1- len)
145                                         :test (complement #'eql))))))
146          collect pat))
147  nil)
148
149(deftest search-bitvector.15
150  (let ((a (make-array '(10) :initial-contents '(0 1 1 0 0 0 1 0 1 1)
151                       :fill-pointer 5
152                       :element-type 'bit)))
153    (values
154     (search #*0 a)
155     (search #*0 a :from-end t)
156     (search #*01 a)
157     (search #*01 a :from-end t)
158     (search #*010 a)
159     (search #*010 a :from-end t)))
160  0 4 0 0 nil nil)
161
162(deftest search-bitvector.16
163  (let ((pat (make-array '(3) :initial-contents '(0 1 0)
164                         :fill-pointer 1))
165        (a #*01100))
166    (values
167     (search pat a)
168     (search pat a :from-end t)
169     (progn
170       (setf (fill-pointer pat) 2)
171       (search pat a))
172     (search pat a :from-end t)
173     (progn
174       (setf (fill-pointer pat) 3)
175       (search pat a))
176     (search pat a :from-end t)))
177  0 4 0 0 nil nil)
178
179;; Order of test, test-not
180
181(deftest search-bitvector.17
182  (let ((pat #*10)
183        (target #*000011))
184    (search pat target :test #'<=))
185  4)
186
187(deftest search-bitvector.18
188  (let ((pat #*10)
189        (target #*000011))
190    (search pat target :test-not #'>))
191  4)
192
Note: See TracBrowser for help on using the repository browser.