source: trunk/source/tests/ansi-tests/find.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: 20.2 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Aug 23 07:49:49 2002
4;;;; Contains: Tests for FIND
5
6(in-package :cl-test)
7
8(deftest find-list.1
9  (find 'c '(a b c d e c a))
10  c)
11
12(deftest find-list.2
13  (find 'c '(a b c d e c a) :from-end t)
14  c)
15
16(deftest find-list.3
17  (loop for i from 0 to 7 collect
18        (find 'c '(a b c d e c a) :start i))
19  (c c c c c c nil nil))
20
21(deftest find-list.4
22  (loop for i from 0 to 7 collect
23        (find 'c '(a b c d e c a) :start i :end nil))
24  (c c c c c c nil nil))
25
26(deftest find-list.5
27  (loop for i from 7 downto 0 collect
28        (find 'c '(a b c d e c a) :end i))
29  (c c c c c nil nil nil))
30
31(deftest find-list.6
32  (loop for i from 0 to 7 collect
33        (find 'c '(a b c d e c a) :start i :from-end t))
34  (c c c c c c nil nil))
35
36(deftest find-list.7
37  (loop for i from 0 to 7 collect
38        (find 'c '(a b c d e c a) :start i :end nil :from-end t))
39  (c c c c c c nil nil))
40
41(deftest find-list.8
42  (loop for i from 7 downto 0 collect
43        (find 'c '(a b c d e c a) :end i :from-end t))
44  (c c c c c nil nil nil))
45
46(deftest find-list.9
47  (loop for i from 0 to 6 collect
48        (loop for j from (1+ i) to 7
49              collect
50              (find 'c '(a b c d e c a) :start i :end j)))
51  ((nil nil c c c c c)
52   (nil c c c c c)
53   (c c c c c)
54   (nil nil c c)
55   (nil c c)
56   (c c)
57   (nil)))
58
59(deftest find-list.10
60  (loop for i from 0 to 6 collect
61        (loop for j from (1+ i) to 7
62              collect
63              (find 'c '(a b c d e c a) :start i :end j :from-end t)))
64  ((nil nil c c c c c)
65   (nil c c c c c)
66   (c c c c c)
67   (nil nil c c)
68   (nil c c)
69   (c c)
70   (nil)))
71
72(deftest find-list.11
73  (find 5 '(1 2 3 4 5 6 4 8) :key #'1+)
74  4)
75
76(deftest find-list.12
77  (find 5 '(1 2 3 4 5 6 4 8) :key '1+)
78  4)
79
80(deftest find-list.13
81  (find 5 '(1 2 3 4 5 6 4 8) :key #'1+ :from-end t)
82  4)
83
84(deftest find-list.14
85  (find 'a '(a a b a c e d a f a) :test (complement #'eql))
86  b)
87
88(deftest find-list.15
89  (find 'a '(a a b a c e d a f a) :test (complement #'eql)
90            :from-end t)
91  f)
92
93(deftest find-list.16
94  (find 'a '(a a b a c e d a f a) :test-not #'eql)
95  b)
96
97(deftest find-list.17
98  (find 'a '(a a b a c e d a f a) :test-not 'eql
99            :from-end t)
100  f)
101
102(deftest find-list.18
103  (find 'a '(a a b a c e d a f a) :test-not 'eql)
104  b)
105
106(deftest find-list.19
107  (find 'a '(a a b a c e d a f a) :test-not #'eql
108            :from-end t)
109  f)
110
111(deftest find-list.20
112  (find 'a '(a a b a c e d a f a) :test-not #'eql)
113  b)
114
115(deftest find-list.21
116  (find 'a '(a a b a c e d a f a) :test #'eql
117            :start 2)
118  a)
119
120(deftest find-list.22
121  (find 'a '(a a b a c e d a f a) :test #'eql
122            :start 2 :end nil)
123  a)
124
125(deftest find-list.23
126  (find 'a '(a a b a c e d a f a) :test-not #'eql
127            :start 0 :end 5)
128  b)
129
130(deftest find-list.24
131  (find 'a '(a a b a c e d a f a) :test-not #'eql
132            :start 0 :end 5 :from-end t)
133  c)
134
135(deftest find-list.25
136  (find "ab" '("a" #(#\b #\a) #(#\a #\b #\c) #(#\a #\b) #(#\d #\e) f) :test #'equalp)
137  #(#\a #\b))
138
139(deftest find-list.26
140  (find 'a '((c) (b a) (a b c) (a b) (d e) f) :key #'car)
141  (a b c))
142
143(deftest find-list.27
144  (find 'a '((c) (b a) (a b c) (z) (a b) (d e) f) :key #'car
145            :start 3)
146  (a b))
147
148(deftest find-list.28
149  (find 'a '((c) (b a) (a b c) (z) (a b) (d e) (f)) :key #'car
150            :start 2 :from-end t)
151  (a b))
152
153(deftest find-list.29
154  (find 10 '(1 2 3 8 20 3 1 21 3) :test #'<)
155  20)
156
157(deftest find-list.30
158  (find 10 '(1 2 3 8 20 3 1 21 3) :test-not #'>=)
159  20)
160
161;;; Tests on vectors
162
163(deftest find-vector.1
164  (find 'c #(a b c d e c a))
165  c)
166
167(deftest find-vector.1a
168  (find 'z #(a b c d e c a))
169  nil)
170
171(deftest find-vector.2
172  (find 'c #(a b c d e c a) :from-end t)
173  c)
174
175(deftest find-vector.2a
176  (find 'z #(a b c d e c a) :from-end t)
177  nil)
178
179(deftest find-vector.3
180  (loop for i from 0 to 7 collect
181        (find 'c #(a b c d e c a) :start i))
182  (c c c c c c nil nil))
183
184(deftest find-vector.4
185  (loop for i from 0 to 7 collect
186        (find 'c #(a b c d e c a) :start i :end nil))
187  (c c c c c c nil nil))
188
189(deftest find-vector.5
190  (loop for i from 7 downto 0 collect
191        (find 'c #(a b c d e c a) :end i))
192  (c c c c c nil nil nil))
193
194(deftest find-vector.6
195  (loop for i from 0 to 7 collect
196        (find 'c #(a b c d e c a) :start i :from-end t))
197  (c c c c c c nil nil))
198
199(deftest find-vector.7
200  (loop for i from 0 to 7 collect
201        (find 'c #(a b c d e c a) :start i :end nil :from-end t))
202  (c c c c c c nil nil))
203
204(deftest find-vector.8
205  (loop for i from 7 downto 0 collect
206        (find 'c #(a b c d e c a) :end i :from-end t))
207  (c c c c c nil nil nil))
208
209(deftest find-vector.9
210  (loop for i from 0 to 6 collect
211        (loop for j from (1+ i) to 7
212              collect
213              (find 'c #(a b c d e c a) :start i :end j)))
214  ((nil nil c c c c c)
215   (nil c c c c c)
216   (c c c c c)
217   (nil nil c c)
218   (nil c c)
219   (c c)
220   (nil)))
221
222(deftest find-vector.10
223  (loop for i from 0 to 6 collect
224        (loop for j from (1+ i) to 7
225              collect
226              (find 'c #(a b c d e c a) :start i :end j :from-end t)))
227  ((nil nil c c c c c)
228   (nil c c c c c)
229   (c c c c c)
230   (nil nil c c)
231   (nil c c)
232   (c c)
233   (nil)))
234
235(deftest find-vector.11
236  (find 5 #(1 2 3 4 5 6 4 8) :key #'1+)
237  4)
238
239(deftest find-vector.12
240  (find 5 #(1 2 3 4 5 6 4 8) :key '1+)
241  4)
242
243(deftest find-vector.13
244  (find 5 #(1 2 3 4 5 6 4 8) :key #'1+ :from-end t)
245  4)
246
247(deftest find-vector.14
248  (find 'a #(a a b a c e d a f a) :test (complement #'eql))
249  b)
250
251(deftest find-vector.15
252  (find 'a #(a a b a c e d a f a) :test (complement #'eql)
253            :from-end t)
254  f)
255
256(deftest find-vector.16
257  (find 'a #(a a b a c e d a f a) :test-not #'eql)
258  b)
259
260(deftest find-vector.17
261  (find 'a #(a a b a c e d a f a) :test-not 'eql
262            :from-end t)
263  f)
264
265(deftest find-vector.18
266  (find 'a #(a a b a c e d a f a) :test-not 'eql)
267  b)
268
269(deftest find-vector.19
270  (find 'a #(a a b a c e d a f a) :test-not #'eql
271            :from-end t)
272  f)
273
274(deftest find-vector.20
275  (find 'a #(a a b a c e d a f a) :test-not #'eql)
276  b)
277
278(deftest find-vector.21
279  (find 'a #(a a b a c e d a f a) :test #'eql
280            :start 2)
281  a)
282
283(deftest find-vector.22
284  (find 'a #(a a b a c e d a f a) :test #'eql
285            :start 2 :end nil)
286  a)
287
288(deftest find-vector.23
289  (find 'a #(a a b a c e d a f a) :test-not #'eql
290            :start 0 :end 5)
291  b)
292
293(deftest find-vector.24
294  (find 'a #(a a b a c e d a f a) :test-not #'eql
295            :start 0 :end 5 :from-end t)
296  c)
297
298(deftest find-vector.25
299  (find "ab" #("a" #(#\b #\a) #(#\a #\b #\c) #(#\a #\b) #(#\d #\e) f) :test #'equalp)
300  #(#\a #\b))
301
302(deftest find-vector.26
303  (find 'a #((c) (b a) (a b c) (a b) (d e) f) :key #'car)
304  (a b c))
305
306(deftest find-vector.27
307  (find 'a #((c) (b a) (a b c) (z) (a b) (d e) f) :key #'car
308            :start 3)
309  (a b))
310
311(deftest find-vector.28
312  (find 'a #((c) (b a) (a b c) (z) (a b) (d e) (f)) :key #'car
313            :start 2 :from-end t)
314  (a b))
315
316(deftest find-vector.29
317  (let ((a (make-array '(10)
318                       :initial-contents '(1 2 3 4 5 6 7 8 9 10)
319                       :fill-pointer 5)))
320    (loop for i from 1 to 10 collect (find i a)))
321  (1 2 3 4 5 nil nil nil nil nil))
322
323(deftest find-vector.30
324  (let ((a (make-array '(10)
325                       :initial-contents (loop for i from 1 for e in '(1 2 3 4 5 5 4 3 2 1)
326                                               collect (list e i))
327                       :fill-pointer 5)))
328    (loop for i from 1 to 5 collect (find i a :from-end t :key #'car)))
329  ((1 1) (2 2) (3 3) (4 4) (5 5)))
330
331(deftest find-vector.31
332  (find 10 #(1 2 3 8 20 3 1 21 3) :test #'<)
333  20)
334
335(deftest find-vector.32
336  (find 10 #(1 2 3 8 20 3 1 21 3) :test-not #'>=)
337  20)
338
339(deftest find-vector.33
340  (do-special-integer-vectors
341   (v #(1 2 3 4 5 6 7) nil)
342   (assert (null (find 0 v)))
343   (assert (= (find 4 v) 4))
344   (assert (= (find -1 v :test #'<) 1))
345   (assert (= (find -1 v :test #'< :from-end t) 7)))
346  nil)
347
348(deftest find-vector.34
349  (do-special-integer-vectors
350   (v #(0 0 0 0) nil)
351   (assert (eql (find 0 v) 0))
352   (assert (eql (find 0 v :start 1) 0))
353   (assert (eql (find 0 v :from-end t) 0))
354   (assert (null (find 1 v)))
355   (assert (null (find 'a v)))
356   (assert (null (find 0.0 v)))
357   (assert (null (find #c(1.0 0.0) v)))
358   (assert (null (find -1 v)))
359   (assert (null (find 2 v))))
360  nil)
361
362;;; tests on bit vectors
363
364(deftest find-bit-vector.1
365  (find 1 #*001001010100)
366  1)
367
368(deftest find-bit-vector.1a
369  (find 0 #*001001010100)
370  0)
371
372(deftest find-bit-vector.1b
373  (find 2 #*001001010100)
374  nil)
375
376(deftest find-bit-vector.1c
377  (find 'a #*001001010100)
378  nil)
379
380(deftest find-bit-vector.1d
381  (find 1 #*000000)
382  nil)
383
384(deftest find-bit-vector.2
385  (find 1 #*001001010100 :from-end t)
386  1)
387
388(deftest find-bit-vector.2a
389  (find 1 #*00000 :from-end t)
390  nil)
391
392(deftest find-bit-vector.2b
393  (find 0 #*00000 :from-end t)
394  0)
395
396(deftest find-bit-vector.2c
397  (find 0 #*11111 :from-end t)
398  nil)
399
400(deftest find-bit-vector.2d
401  (find 2 #*11111 :from-end t)
402  nil)
403
404(deftest find-bit-vector.2e
405  (find 'a #*11111 :from-end t)
406  nil)
407
408(deftest find-bit-vector.3
409  (loop for i from 0 to 7 collect
410        (find 1 #*0010010 :start i))
411  (1 1 1 1 1 1 nil nil))
412
413(deftest find-bit-vector.4
414  (loop for i from 0 to 7 collect
415        (find 1 #*0010010 :start i :end nil))
416  (1 1 1 1 1 1 nil nil))
417
418(deftest find-bit-vector.5
419  (loop for i from 7 downto 0 collect
420        (find 1 #*0010010 :end i))
421  (1 1 1 1 1 nil nil nil))
422
423(deftest find-bit-vector.6
424  (loop for i from 0 to 7 collect
425        (find 1 #*0010010 :start i :from-end t))
426  (1 1 1 1 1 1 nil nil))
427
428(deftest find-bit-vector.7
429  (loop for i from 0 to 7 collect
430        (find 0 #*1101101 :start i :end nil :from-end t))
431  (0 0 0 0 0 0 nil nil))
432
433(deftest find-bit-vector.8
434  (loop for i from 7 downto 0 collect
435        (find 0 #*1101101 :end i :from-end t))
436  (0 0 0 0 0 nil nil nil))
437
438(deftest find-bit-vector.9
439  (loop for i from 0 to 6 collect
440        (loop for j from (1+ i) to 7
441              collect
442              (find 1 #*0010010 :start i :end j)))
443  ((nil nil 1 1 1 1 1)
444   (nil 1 1 1 1 1)
445   (1 1 1 1 1)
446   (nil nil 1 1)
447   (nil 1 1)
448   (1 1)
449   (nil)))
450
451(deftest find-bit-vector.10
452  (loop for i from 0 to 6 collect
453        (loop for j from (1+ i) to 7
454              collect
455              (find 1 #*0010010 :start i :end j :from-end t)))
456  ((nil nil 1 1 1 1 1)
457   (nil 1 1 1 1 1)
458   (1 1 1 1 1)
459   (nil nil 1 1)
460   (nil 1 1)
461   (1 1)
462   (nil)))
463
464(deftest find-bit-vector.11
465  (find 2 #*00010001010 :key #'1+)
466  1)
467
468(deftest find-bit-vector.12
469  (find 2 #*00010001010 :key '1+)
470  1)
471
472(deftest find-bit-vector.13
473  (find 2 #*0010001000 :key #'1+ :from-end t)
474  1)
475
476(deftest find-bit-vector.14
477  (find 0 #*0010111010 :test (complement #'eql))
478  1)
479
480(deftest find-bit-vector.15
481  (find 0 #*0010111010 :test (complement #'eql)
482            :from-end t)
483  1)
484
485(deftest find-bit-vector.16
486  (find 0 #*0010111010 :test-not #'eql)
487  1)
488
489(deftest find-bit-vector.16a
490  (find 1 #*111111111111 :test-not #'eql)
491  nil)
492
493(deftest find-bit-vector.16b
494  (find 0 #*0000000 :test-not #'eql)
495  nil)
496
497(deftest find-bit-vector.17
498  (find 0 #*001011101 :test-not 'eql
499        :from-end t)
500  1)
501
502(deftest find-bit-vector.17a
503  (find 0 #*0000000 :test-not 'eql
504        :from-end t)
505  nil)
506
507(deftest find-bit-vector.17b
508  (find 1 #*111111111111 :test-not 'eql
509        :from-end t)
510  nil)
511
512(deftest find-bit-vector.18
513  (find 0 #*00101110 :test-not 'eql)
514  1)
515
516(deftest find-bit-vector.18a
517  (find 0 #*00000000 :test-not 'eql)
518  nil)
519
520(deftest find-bit-vector.19
521  (find 0 #*00101110 :test-not #'eql
522            :from-end t)
523  1)
524
525(deftest find-bit-vector.19a
526  (find 0 #*00000000 :test-not #'eql
527        :from-end t)
528  nil)
529
530(deftest find-bit-vector.20
531  (find 0 #*00101110 :test-not #'eql)
532  1)
533
534(deftest find-bit-vector.21
535  (find 0 #*00101110 :test #'eql
536        :start 2)
537  0)
538
539(deftest find-bit-vector.21a
540  (find 0 #*00111111 :test #'eql
541        :start 2)
542  nil)
543
544(deftest find-bit-vector.21b
545  (find 1 #*00111111 :test #'eql
546        :start 2)
547  1)
548
549(deftest find-bit-vector.22
550  (find 0 #*00101110 :test #'eql
551        :start 2 :end nil)
552  0)
553
554(deftest find-bit-vector.22a
555  (find 0 #*001111111 :test #'eql
556        :start 2 :end nil)
557  nil)
558
559(deftest find-bit-vector.22b
560  (find 1 #*001111111 :test #'eql
561        :start 2 :end nil)
562  1)
563
564(deftest find-bit-vector.23
565  (find 0 #*00101110 :test-not #'eql
566        :start 0 :end 5)
567  1)
568
569(deftest find-bit-vector.23a
570  (find 0 #*00000111 :test-not #'eql
571        :start 0 :end 5)
572  nil)
573
574(deftest find-bit-vector.23b
575  (find 0 #*00001000 :test-not #'eql
576        :start 0 :end 5)
577  1)
578
579(deftest find-bit-vector.24
580  (find 0 #*00101110 :test-not #'eql
581            :start 0 :end 5 :from-end t)
582  1)
583
584(deftest find-bit-vector.24a
585  (find 0 #*0000001111 :test-not #'eql
586            :start 0 :end 5 :from-end t)
587  nil)
588
589(deftest find-bit-vector.24b
590  (find 0 #*0000100 :test-not #'eql
591            :start 0 :end 5 :from-end t)
592  1)
593
594(deftest find-bit-vector.25
595  (find 2 #*1100001010 :key #'1+
596            :start 3)
597  1)
598
599(deftest find-bit-vector.26
600  (find 2 #*11100000 :key #'1+
601            :start 3)
602  nil)
603
604(deftest find-bit-vector.26a
605  (find 2 #*11110000 :key #'1+
606            :start 3)
607  1)
608
609(deftest find-bit-vector.27
610  (find 2 #*1100001010 :key #'1+
611            :start 2 :from-end t)
612  1)
613
614(deftest find-bit-vector.28
615  (find 2 #*1100000000 :key #'1+
616            :start 2 :from-end t)
617  nil)
618
619(deftest find-bit-vector.29
620  (let ((a
621         (make-array '(10) :initial-contents '(1 1 1 1 1 0 0 0 0 0)
622                     :element-type 'bit
623                     :fill-pointer 5)))
624    (values (find 0 a)
625            (find 0 a :from-end t)))
626  nil nil)
627
628(deftest find-bit-vector.30
629  (let ((a (make-array '(10) :initial-contents '(1 1 1 1 0 0 0 0 0 0)
630                       :element-type 'bit
631                       :fill-pointer 5)))
632    (values (find 0 a) (find 0 a :from-end t)))
633  0 0)
634
635(deftest find-bit-vector.31
636  (find 2 #*00011010010 :test #'<)
637  nil)
638
639(deftest find-bit-vector.32
640  (find 2 #*0010101101 :test-not #'>=)
641  nil)
642
643(deftest find-bit-vector.33
644  (find 0 #*00011010010 :test #'<)
645  1)
646
647(deftest find-bit-vector.34
648  (find 0 #*0010101101 :test-not #'>=)
649  1)
650
651;;; strings
652
653(deftest find-string.1
654  (find #\c "abcdeca")
655  #\c)
656
657(deftest find-string.1a
658  (find #\c "abCa")
659  nil)
660
661(deftest find-string.2
662  (find #\c "abcdeca" :from-end t)
663  #\c)
664
665(deftest find-string.2a
666  (find #\c "abCCCa" :from-end t)
667  nil)
668
669(deftest find-string.3
670  (loop for i from 0 to 7 collect
671        (find #\c "abcdeca" :start i))
672  (#\c #\c #\c #\c #\c #\c nil nil))
673
674(deftest find-string.4
675  (loop for i from 0 to 7 collect
676        (find #\c "abcdeca" :start i :end nil))
677  (#\c #\c #\c #\c #\c #\c nil nil))
678
679(deftest find-string.5
680  (loop for i from 7 downto 0 collect
681        (find #\c "abcdeca" :end i))
682  (#\c #\c #\c #\c #\c nil nil nil))
683
684(deftest find-string.6
685  (loop for i from 0 to 7 collect
686        (find #\c "abcdeca" :start i :from-end t))
687  (#\c #\c #\c #\c #\c #\c nil nil))
688
689(deftest find-string.7
690  (loop for i from 0 to 7 collect
691        (find #\c "abcdeca" :start i :end nil :from-end t))
692  (#\c #\c #\c #\c #\c #\c nil nil))
693
694(deftest find-string.8
695  (loop for i from 7 downto 0 collect
696        (find #\c "abcdeca" :end i :from-end t))
697  (#\c #\c #\c #\c #\c nil nil nil))
698
699(deftest find-string.9
700  (loop for i from 0 to 6 collect
701        (loop for j from (1+ i) to 7
702              collect
703              (find #\c "abcdeca" :start i :end j)))
704  ((nil nil #\c #\c #\c #\c #\c)
705   (nil #\c #\c #\c #\c #\c)
706   (#\c #\c #\c #\c #\c)
707   (nil nil #\c #\c)
708   (nil #\c #\c)
709   (#\c #\c)
710   (nil)))
711
712(deftest find-string.10
713  (loop for i from 0 to 6 collect
714        (loop for j from (1+ i) to 7
715              collect
716              (find #\c "abcdeca" :start i :end j :from-end t)))
717  ((nil nil #\c #\c #\c #\c #\c)
718   (nil #\c #\c #\c #\c #\c)
719   (#\c #\c #\c #\c #\c)
720   (nil nil #\c #\c)
721   (nil #\c #\c)
722   (#\c #\c)
723   (nil)))
724
725(deftest find-string.11
726  (find 5 "12345648" :key #'(lambda (c)
727                              (1+ (read-from-string (string c)))))
728  #\4)
729
730(deftest find-string.13
731  (find 5 "12345648" :key #'(lambda (c)
732                                  (1+ (read-from-string (string c))))
733            :from-end t)
734  #\4)
735
736(deftest find-string.14
737  (find #\a "aabacedafa" :test (complement #'eql))
738  #\b)
739
740(deftest find-string.15
741  (find #\a "aabacedafa" :test (complement #'eql)
742            :from-end t)
743  #\f)
744
745(deftest find-string.16
746  (find #\a "aabacedafa" :test-not #'eql)
747  #\b)
748
749(deftest find-string.17
750  (find #\a "aabacedafa" :test-not 'eql
751            :from-end t)
752  #\f)
753
754(deftest find-string.18
755  (find #\a "aabacedafa" :test-not 'eql)
756  #\b)
757
758(deftest find-string.19
759  (find #\a "aabacedafa" :test-not #'eql
760            :from-end t)
761  #\f)
762
763(deftest find-string.20
764  (find #\a "aabacedafa" :test-not #'eql)
765  #\b)
766
767(deftest find-string.21
768  (find #\a "aabAcedafa" :test #'char-equal
769        :start 2)
770  #\A)
771
772(deftest find-string.22
773  (find #\a "aabAcedafa" :test #'char-equal
774            :start 2 :end nil)
775  #\A)
776
777(deftest find-string.23
778  (find #\a "aAbAcedafa" :test-not #'char-equal
779            :start 0 :end 5)
780  #\b)
781
782(deftest find-string.24
783  (find #\a "aabacedafa" :test-not #'char-equal
784        :start 0 :end 5 :from-end t)
785  #\c)
786
787(deftest find-string.25
788  (let ((s (make-array '(10) :initial-contents "abcdefghij"
789                       :element-type 'character
790                       :fill-pointer 5)))
791    (values
792     (loop for e across "abcdefghij"
793           collect (find e s))
794     (loop for e across "abcdefghij"
795           collect (find e s :from-end t))))
796  (#\a #\b #\c #\d #\e nil nil nil nil nil)
797  (#\a #\b #\c #\d #\e nil nil nil nil nil))
798
799(deftest find-string.26
800  (find #\k "abcdmnop" :test #'char<)
801  #\m)
802
803(deftest find-string.27
804  (find #\k "abcdmnop" :test-not #'char>=)
805  #\m)
806
807(deftest find-string.28
808  (do-special-strings
809   (s "abcdef" nil)
810   (assert (char= (find #\c s :test #'char<) #\d)))
811  nil)
812
813;;; Test & test not
814
815(defharmless find-list.test-and-test-not.1
816  (find 'b '(a b c) :test #'eql :test-not #'eql))
817
818(defharmless find-list.test-and-test-not.2
819  (find 'b '(a b c) :test-not #'eql :test #'eql))
820
821(defharmless find-vector.test-and-test-not.1
822  (find 'b #(a b c) :test #'eql :test-not #'eql))
823
824(defharmless find-vector.test-and-test-not.2
825  (find 'b #(a b c) :test-not #'eql :test #'eql))
826
827(defharmless find-string.test-and-test-not.1
828  (find #\b "abc" :test #'eql :test-not #'eql))
829
830(defharmless find-string.test-and-test-not.2
831  (find #\b "abc" :test-not #'eql :test #'eql))
832
833(defharmless find-bit-string.test-and-test-not.1
834  (find 0 #*110110 :test #'eql :test-not #'eql))
835
836(defharmless find-bit-string.test-and-test-not.2
837  (find 0 #*110110 :test-not #'eql :test #'eql))
838
839;;; Keyword tests
840
841(deftest find.allow-other-keys.1
842  (find 0 '(1 2 3 4 5) :key #'(lambda (x) (mod x 2))
843        :bad t :allow-other-keys t)
844  2)
845
846(deftest find.allow-other-keys.2
847  (find 0 '(1 2 3 4 5) :key #'(lambda (x) (mod x 2))
848               :allow-other-keys t :also-bad t)
849  2)
850
851;;; The leftmost of two :allow-other-keys arguments is the one that  matters.
852(deftest find.allow-other-keys.3
853  (find 0 '(1 2 3 4 5) :key #'(lambda (x) (mod x 2))
854        :allow-other-keys t
855        :allow-other-keys nil
856        :bad t)
857  2)
858
859(deftest find.keywords.4
860  (find 2 '(1 2 3 4 5) :key #'identity :key #'1+)
861  2)
862
863(deftest find.allow-other-keys.5
864  (find 'b '(nil a b c nil) :allow-other-keys nil)
865  b)
866
867
868;;; Error tests
869
870(deftest find.error.1
871  (check-type-error #'(lambda (x) (find 'a x)) #'(lambda (x) (typep x 'sequence)))
872  nil)
873
874(deftest find.error.4
875  (signals-error (find 'e '(a b c . d)) type-error)
876  t)
877
878(deftest find.error.5
879  (signals-error (find) program-error)
880  t)
881
882(deftest find.error.6
883  (signals-error (find 'a) program-error)
884  t)
885
886(deftest find.error.7
887  (signals-error (find 'a nil :bad t) program-error)
888  t)
889
890(deftest find.error.8
891  (signals-error (find 'a nil :bad t :allow-other-keys nil)
892                 program-error)
893  t)
894
895(deftest find.error.9
896  (signals-error (find 'a nil 1 1) program-error)
897  t)
898
899(deftest find.error.10
900  (signals-error (find 'a nil :key) program-error)
901  t)
902
903(deftest find.error.11
904  (signals-error (locally (find 'a 'b) t) type-error)
905  t)
906
907(deftest find.error.12
908  (signals-error (find 'b '(a b c) :test #'identity) program-error)
909  t)
910
911(deftest find.error.13
912  (signals-error (find 'b '(a b c) :test-not #'identity) program-error)
913  t)
914
915(deftest find.error.14
916  (signals-error (find 'c '(a b c) :key #'cons) program-error)
917  t)
918
919(deftest find.error.15
920  (signals-error (find 'c '(a b c) :key #'car) type-error)
921  t)
922
923
924;;; Order of evaluation tests
925
926(deftest find.order.1
927  (let ((i 0) x y)
928    (values
929     (find (progn (setf x (incf i)) 'a)
930           (progn (setf y (incf i)) '(nil nil nil a nil nil)))
931     i x y))
932  a 2 1 2)
933
934(deftest find.order.2
935  (let ((i 0) a b c d e f)
936    (values
937     (find (progn (setf a (incf i)) nil)
938           (progn (setf b (incf i)) '(nil nil nil a nil nil))
939           :start (progn (setf c (incf i)) 1)
940           :end   (progn (setf d (incf i)) 4)
941           :from-end (setf e (incf i))
942           :key   (progn (setf f (incf i)) #'null)
943           )
944     i a b c d e f))
945  a 6 1 2 3 4 5 6)
946
947(deftest find.order.3
948  (let ((i 0) a b c d e f)
949    (values
950     (find (progn (setf a (incf i)) nil)
951           (progn (setf b (incf i)) '(nil nil nil a nil nil))
952           :key   (progn (setf c (incf i)) #'null)
953           :from-end (setf d (incf i))
954           :end   (progn (setf e (incf i)) 4)
955           :start (progn (setf f (incf i)) 1)
956           )
957     i a b c d e f))
958  a 6 1 2 3 4 5 6)
Note: See TracBrowser for help on using the repository browser.