source: trunk/source/tests/ansi-tests/search-vector.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: 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 vectors
5
6(in-package :cl-test)
7
8(compile-and-load "search-aux.lsp")
9
10(deftest search-vector.1
11  (let ((target *searched-vector*)
12        (pat #(a)))
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-vector.2
21  (let ((target *searched-vector*)
22        (pat #(a)))
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-vector.3
30  (let ((target *searched-vector*))
31    (loop for pat in *pattern-subvectors*
32          for pos = (search pat target)
33          unless (search-check pat target pos)
34          collect pat))
35  nil)
36
37(deftest search-vector.4
38  (let ((target *searched-vector*))
39    (loop for pat in *pattern-subvectors*
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-vector.5
46  (let ((target *searched-vector*))
47    (loop for pat in *pattern-subvectors*
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-vector.6
54  (let ((target *searched-vector*))
55    (loop for pat in *pattern-subvectors*
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-vector.7
63  (let ((target *searched-vector*))
64    (loop for pat in *pattern-subvectors*
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-vector.8
71  (let ((target *searched-vector*))
72    (loop for pat in *pattern-subvectors*
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-vector.9
80  (let ((target (map 'vector #'(lambda (x) (sublis '((a . 1) (b . 2)) x))
81                     *searched-list*)))
82    (loop for pat in (mapcar #'(lambda (x)
83                                 (map 'vector
84                                      #'(lambda (y)
85                                          (sublis '((a . 3) (b . 4)) y))
86                                      x))
87                             *pattern-sublists*)
88          for pos = (search pat target :start2 20 :key #'evenp)
89          unless (search-check pat target pos :start2 20 :key #'evenp)
90          collect pat))
91  nil)
92
93(deftest search-vector.10
94  (let ((target (map 'vector #'(lambda (x) (sublis '((a . 1) (b . 2)) x))
95                     *searched-list*)))
96    (loop for pat in (mapcar #'(lambda (x)
97                                 (map 'vector
98                                      #'(lambda (y)
99                                          (sublis '((a . 3) (b . 4)) y))
100                                      x))
101                             *pattern-sublists*)
102          for pos = (search pat target :from-end t :start2 20 :key 'oddp)
103          unless (search-check pat target pos :from-end t
104                               :start2 20 :key 'oddp)
105          collect pat))
106  nil)
107
108(deftest search-vector.11
109  (let ((target *searched-vector*))
110    (loop for pat in *pattern-subvectors*
111          for pos = (search pat target :start2 20 :test (complement #'eql))
112          unless (search-check pat target pos :start2 20
113                               :test (complement #'eql))
114          collect pat))
115  nil)
116
117(deftest search-vector.12
118  (let ((target *searched-vector*))
119    (loop for pat in *pattern-subvectors*
120          for pos = (search pat target :from-end t :start2 20 :test-not #'eql)
121          unless (search-check pat target pos :from-end t
122                               :start2 20 :test (complement #'eql))
123          collect pat))
124  nil)
125
126(deftest search-vector.13
127  (let ((target *searched-vector*))
128    (loop for pat in *pattern-subvectors*
129          when (and (> (length pat) 0)
130                    (let ((pos (search pat target :start1 1
131                                       :test (complement #'eql))))
132                      (not (search-check pat target pos
133                                         :start1 1
134                                         :test (complement #'eql)))))
135          collect pat))
136  nil)
137
138(deftest search-vector.14
139  (let ((target *searched-vector*))
140    (loop for pat in *pattern-subvectors*
141          when (let ((len (length pat)))
142                 (and (> len 0)
143                      (let ((pos (search pat target :end1 (1- len)
144                                         :test (complement #'eql))))
145                      (not (search-check pat target pos
146                                         :end1 (1- len)
147                                         :test (complement #'eql))))))
148          collect pat))
149  nil)
150
151(deftest search-vector.15
152  (let ((a (make-array '(10) :initial-contents '(a b b a a a b a b b)
153                       :fill-pointer 5)))
154    (values
155     (search '(a) a)
156     (search '(a) a :from-end t)
157     (search '(a b) a)
158     (search '(a b) a :from-end t)
159     (search '(a b a) a)
160     (search '(a b a) a :from-end t)))
161  0 4 0 0 nil nil)
162
163(deftest search-vector.16
164  (let ((pat (make-array '(3) :initial-contents '(a b a)
165                         :fill-pointer 1))
166        (a #(a b b a a)))
167    (values
168     (search pat a)
169     (search pat a :from-end t)
170     (progn
171       (setf (fill-pointer pat) 2)
172       (search pat a))
173     (search pat a :from-end t)
174     (progn
175       (setf (fill-pointer pat) 3)
176       (search pat a))
177     (search pat a :from-end t)))
178  0 4 0 0 nil nil)
179
180;; Order of test, test-not
181
182(deftest search-vector.17
183  (let ((pat #(10))
184        (target #(1 4 6 10 15 20)))
185    (search pat target :test #'<))
186  4)
187
188(deftest search-vector.18
189  (let ((pat #(10))
190        (target #(1 4 6 10 15 20)))
191    (search pat target :test-not #'>=))
192  4)
Note: See TracBrowser for help on using the repository browser.