2
;;;; Author: Paul Dietz
3
;;;; Created: Fri Aug 23 22:08:57 2002
4
;;;; Contains: Tests for POSITION-IF
8
(deftest position-if-list.1
9
(position-if #'evenp '(1 3 1 4 3 2 1 8 9))
12
(deftest position-if-list.2
13
(position-if 'evenp '(1 3 1 4 3 2 1 8 9))
16
(deftest position-if-list.3
17
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :start 4)
20
(deftest position-if-list.4
21
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :from-end t)
24
(deftest position-if-list.5
25
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :from-end nil)
28
(deftest position-if-list.6
29
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :start 4
33
(deftest position-if-list.7
34
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :end nil)
37
(deftest position-if-list.8
38
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :end 3)
41
(deftest position-if-list.9
42
(loop for i from 0 to 8
44
(loop for j from (1+ i) to 9
46
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :start i :end j)))
47
((nil nil nil 3 3 3 3 3 3)
57
(deftest position-if-list.10
58
(loop for i from 0 to 8
60
(loop for j from (1+ i) to 9
62
(position-if #'evenp '(1 3 1 4 3 2 1 8 9) :start i :end j
64
((nil nil nil 3 3 5 5 7 7)
74
(deftest position-if-list.11
75
(loop for i from 0 to 8
77
(loop for j from (1+ i) to 9
79
(position-if #'oddp '(1 3 1 4 3 2 1 8 9) :start i :end j
81
((nil nil nil 3 3 3 3 3 3)
91
(deftest position-if-list.12
92
(loop for i from 0 to 8
94
(loop for j from (1+ i) to 9
96
(position-if #'oddp '(1 3 1 4 3 2 1 8 9) :start i :end j
97
:key #'1+ :from-end t)))
98
((nil nil nil 3 3 5 5 7 7)
110
(deftest position-if-vector.1
111
(position-if #'evenp #(1 3 1 4 3 2 1 8 9))
114
(deftest position-if-vector.2
115
(position-if 'evenp #(1 3 1 4 3 2 1 8 9))
118
(deftest position-if-vector.3
119
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :start 4)
122
(deftest position-if-vector.4
123
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :from-end t)
126
(deftest position-if-vector.5
127
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :from-end nil)
130
(deftest position-if-vector.6
131
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :start 4
135
(deftest position-if-vector.7
136
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :end nil)
139
(deftest position-if-vector.8
140
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :end 3)
143
(deftest position-if-vector.9
144
(loop for i from 0 to 8
146
(loop for j from (1+ i) to 9
148
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :start i :end j)))
149
((nil nil nil 3 3 3 3 3 3)
150
(nil nil 3 3 3 3 3 3)
159
(deftest position-if-vector.10
160
(loop for i from 0 to 8
162
(loop for j from (1+ i) to 9
164
(position-if #'evenp #(1 3 1 4 3 2 1 8 9) :start i :end j
166
((nil nil nil 3 3 5 5 7 7)
167
(nil nil 3 3 5 5 7 7)
176
(deftest position-if-vector.11
177
(loop for i from 0 to 8
179
(loop for j from (1+ i) to 9
181
(position-if #'oddp #(1 3 1 4 3 2 1 8 9) :start i :end j
183
((nil nil nil 3 3 3 3 3 3)
184
(nil nil 3 3 3 3 3 3)
193
(deftest position-if-vector.12
194
(loop for i from 0 to 8
196
(loop for j from (1+ i) to 9
198
(position-if #'oddp #(1 3 1 4 3 2 1 8 9) :start i :end j
199
:key #'1+ :from-end t)))
200
((nil nil nil 3 3 5 5 7 7)
201
(nil nil 3 3 5 5 7 7)
210
(deftest position-if-vector.13
211
(let ((a (make-array '(10) :initial-contents '(1 3 1 4 3 1 2 1 8 9)
213
(flet ((%f (x) (eql x 1)))
214
(values (position-if #'%f a)
215
(position-if #'%f a :from-end t))))
220
(deftest position-if-bit-vector.1
221
(position-if #'evenp #*111010101)
224
(deftest position-if-bit-vector.2
225
(position-if 'evenp #*111010101)
228
(deftest position-if-bit-vector.3
229
(position-if #'evenp #*111010101 :start 4)
232
(deftest position-if-bit-vector.4
233
(position-if #'evenp #*111010101 :from-end t)
236
(deftest position-if-bit-vector.5
237
(position-if #'evenp #*111010101 :from-end nil)
240
(deftest position-if-bit-vector.6
241
(position-if #'evenp #*111010101 :start 4
245
(deftest position-if-bit-vector.7
246
(position-if #'evenp #*111010101 :end nil)
249
(deftest position-if-bit-vector.8
250
(position-if #'evenp #*111010101 :end 3)
253
(deftest position-if-bit-vector.9
254
(loop for i from 0 to 8
256
(loop for j from (1+ i) to 9
258
(position-if #'evenp #*111010101 :start i :end j)))
259
((nil nil nil 3 3 3 3 3 3)
260
(nil nil 3 3 3 3 3 3)
269
(deftest position-if-bit-vector.10
270
(loop for i from 0 to 8
272
(loop for j from (1+ i) to 9
274
(position-if #'evenp #*111010101 :start i :end j
276
((nil nil nil 3 3 5 5 7 7)
277
(nil nil 3 3 5 5 7 7)
286
(deftest position-if-bit-vector.11
287
(loop for i from 0 to 8
289
(loop for j from (1+ i) to 9
291
(position-if #'oddp #*111010101 :start i :end j
293
((nil nil nil 3 3 3 3 3 3)
294
(nil nil 3 3 3 3 3 3)
303
(deftest position-if-bit-vector.12
304
(loop for i from 0 to 8
306
(loop for j from (1+ i) to 9
308
(position-if #'oddp #*111010101 :start i :end j
309
:key '1+ :from-end t)))
310
((nil nil nil 3 3 5 5 7 7)
311
(nil nil 3 3 5 5 7 7)
320
(deftest position-if-bit-vector.13
321
(let ((a (make-array '(10) :initial-contents '(1 1 1 1 1 0 0 0 0 0)
323
:element-type 'bit)))
324
(values (position-if #'evenp a)
325
(position-if #'evenp a :from-end 'foo)
326
(position-if #'oddp a)
327
(position-if #'oddp a :from-end 'foo)))
332
(deftest position-if-string.1
333
(position-if #'evendigitp "131432189")
336
(deftest position-if-string.2
337
(position-if 'evendigitp "131432189")
340
(deftest position-if-string.3
341
(position-if #'evendigitp "131432189" :start 4)
344
(deftest position-if-string.4
345
(position-if #'evendigitp "131432189" :from-end t)
348
(deftest position-if-string.5
349
(position-if #'evendigitp "131432189" :from-end nil)
352
(deftest position-if-string.6
353
(position-if #'evendigitp "131432189" :start 4
357
(deftest position-if-string.7
358
(position-if #'evendigitp "131432189" :end nil)
361
(deftest position-if-string.8
362
(position-if #'evendigitp "131432189" :end 3)
365
(deftest position-if-string.9
366
(loop for i from 0 to 8
368
(loop for j from (1+ i) to 9
370
(position-if #'evendigitp "131432189" :start i :end j)))
371
((nil nil nil 3 3 3 3 3 3)
372
(nil nil 3 3 3 3 3 3)
381
(deftest position-if-string.10
382
(loop for i from 0 to 8
384
(loop for j from (1+ i) to 9
386
(position-if #'evendigitp "131432189" :start i :end j
388
((nil nil nil 3 3 5 5 7 7)
389
(nil nil 3 3 5 5 7 7)
398
(deftest position-if-string.11
399
(loop for i from 0 to 8
401
(loop for j from (1+ i) to 9
403
(position-if #'odddigitp "131432189" :start i :end j
405
((nil nil nil 3 3 3 3 3 3)
406
(nil nil 3 3 3 3 3 3)
415
(deftest position-if-string.12
416
(loop for i from 0 to 8
418
(loop for j from (1+ i) to 9
420
(position-if #'odddigitp "131432189" :start i :end j
421
:key 'nextdigit :from-end t)))
422
((nil nil nil 3 3 5 5 7 7)
423
(nil nil 3 3 5 5 7 7)
432
(deftest position-if-string.13
433
(flet ((%f (c) (eql c #\0))
434
(%g (c) (eql c #\1)))
435
(let ((a (make-array '(10) :initial-contents "1111100000"
437
:element-type 'character)))
438
(values (position-if #'%f a)
439
(position-if #'%f a :from-end 'foo)
441
(position-if #'%g a :from-end 'foo))))
444
(deftest position-if.order.1
445
(let ((i 0) a b c d e f)
448
(progn (setf a (incf i)) #'zerop)
449
(progn (setf b (incf i)) '(3 1 8 2 1 2 3 4))
450
:from-end (setf c (incf i))
451
:start (progn (setf d (incf i)) 1)
452
:end (progn (setf e (incf i)) 6)
453
:key (progn (setf f (incf i)) #'1-))
457
(deftest position-if.order.2
458
(let ((i 0) a b c d e f)
461
(progn (setf a (incf i)) #'zerop)
462
(progn (setf b (incf i)) '(3 1 8 2 1 2 3 4))
463
:key (progn (setf c (incf i)) #'1-)
464
:end (progn (setf d (incf i)) 6)
465
:start (progn (setf e (incf i)) 1)
466
:from-end (setf f (incf i)))
472
(deftest position-if.allow-other-keys.1
473
(position-if #'zerop '(1 2 0 3 2 1) :allow-other-keys t)
476
(deftest position-if.allow-other-keys.2
477
(position-if #'zerop '(1 2 0 3 2 1) :allow-other-keys nil)
480
(deftest position-if.allow-other-keys.3
481
(position-if #'zerop '(1 2 0 3 2 1) :allow-other-keys t :bad t)
484
(deftest position-if.allow-other-keys.4
485
(position-if #'zerop '(1 2 0 3 2 1) :bad t :allow-other-keys t)
488
(deftest position-if.allow-other-keys.5
489
(position-if #'zerop '(1 2 0 3 2 1) :bad t :allow-other-keys t :key #'1-)
492
(deftest position-if.keywords.6
493
(position-if #'zerop '(1 2 0 3 2 1) :key #'1- :key #'identity)
496
(deftest position-if.allow-other-keys.7
497
(position-if #'zerop '(1 2 0 3 2 1) :bad t :allow-other-keys t
498
:allow-other-keys nil)
501
(deftest position-if.allow-other-keys.8
502
(position-if #'zerop '(1 2 0 3 2 1) :allow-other-keys t :bad t
503
:allow-other-keys nil)
506
(deftest position-if.allow-other-keys.9
507
(position-if #'zerop '(1 2 0 3 2 1) :allow-other-keys t
508
:allow-other-keys nil :bad t)
514
(deftest position-if.error.1
515
(signals-error (position-if #'identity 'b) type-error)
518
(deftest position-if.error.2
519
(signals-error (position-if #'identity 10) type-error)
522
(deftest position-if.error.3
523
(signals-error (position-if 'null 1.4) type-error)
526
(deftest position-if.error.4
527
(signals-error (position-if 'null '(a b c . d)) type-error)
530
(deftest position-if.error.5
531
(signals-error (position-if) program-error)
534
(deftest position-if.error.6
535
(signals-error (position-if #'null) program-error)
538
(deftest position-if.error.7
539
(signals-error (position-if #'null nil :key) program-error)
542
(deftest position-if.error.8
543
(signals-error (position-if #'null nil 'bad t) program-error)
546
(deftest position-if.error.9
547
(signals-error (position-if #'null nil 'bad t :allow-other-keys nil) program-error)
550
(deftest position-if.error.10
551
(signals-error (position-if #'null nil 1 2) program-error)
554
(deftest position-if.error.11
555
(signals-error (locally (position-if #'identity 'b) t) type-error)
558
(deftest position-if.error.12
559
(signals-error (position-if #'cons '(a b c d)) program-error)
562
(deftest position-if.error.13
563
(signals-error (position-if #'car '(a b c d)) type-error)
566
(deftest position-if.error.14
567
(signals-error (position-if #'identity '(a b c d) :key #'cdr) type-error)
570
(deftest position-if.error.15
571
(signals-error (position-if #'identity '(a b c d) :key #'cons) program-error)