2
;;;; Author: Paul Dietz
3
;;;; Created: Tue Aug 20 22:42:35 2002
4
;;;; Contains: Tests for COUNT-IF-NOT
8
(deftest count-if-not-list.1
9
(count-if-not #'identity '(a b nil c d nil e))
12
(deftest count-if-not-list.2
13
(count-if-not #'not '(a b nil c d nil e))
16
(deftest count-if-not-list.3
17
(count-if-not #'(lambda (x) (break)) nil)
20
(deftest count-if-not-list.4
21
(count-if-not #'identity '(a b nil c d nil e) :key #'identity)
24
(deftest count-if-not-list.5
25
(count-if-not 'identity '(a b nil c d nil e) :key #'identity)
28
(deftest count-if-not-list.6
29
(count-if-not #'identity '(a b nil c d nil e) :key 'identity)
32
(deftest count-if-not-list.8
33
(count-if-not #'identity '(a b nil c d nil e) :key 'not)
36
(deftest count-if-not-list.9
37
(count-if-not #'oddp '(1 2 3 4 4 1 8 10 1))
40
(deftest count-if-not-list.10
41
(count-if-not #'oddp '(1 2 3 4 4 1 8 10 1) :key #'1+)
44
(deftest count-if-not-list.11
46
(count-if-not #'oddp '(1 2 3 4 4 1 8 10 1)
47
:key #'(lambda (x) (+ x (incf c)))))
50
(deftest count-if-not-list.12
52
(count-if-not #'oddp '(0 1 2 3 4 4 1 7 10 1)
54
:key #'(lambda (x) (+ x (incf c)))))
57
(deftest count-if-not-list.13
58
(count-if-not #'(lambda (x) (not (eqt x 'a)))
59
'(a b c d a e f a e f f a a) :start 2)
62
(deftest count-if-not-list.14
63
(count-if-not #'(lambda (x) (not (eqt x 'a)))
64
'(a b c d a e f a e f f a a) :end 7)
67
(deftest count-if-not-list.15
68
(count-if-not #'(lambda (x) (not (eqt x 'a)))
69
'(a b c d a e f a e f f a a) :end 7
73
(deftest count-if-not-list.16
74
(count-if-not #'(lambda (x) (not (eqt x 'a)))
75
'(a b c d a e f a e f f a a) :end 7
82
(deftest count-if-not-vector.1
83
(count-if-not #'identity #(a b nil c d nil e))
86
(deftest count-if-not-vector.2
87
(count-if-not #'not #(a b nil c d nil e))
90
(deftest count-if-not-vector.3
91
(count-if-not #'(lambda (x) (break)) #())
94
(deftest count-if-not-vector.4
95
(count-if-not #'not #(a b nil c d nil e) :key #'identity)
98
(deftest count-if-not-vector.5
99
(count-if-not 'not #(a b nil c d nil e) :key #'identity)
102
(deftest count-if-not-vector.6
103
(count-if-not #'not #(a b nil c d nil e) :key 'identity)
106
(deftest count-if-not-vector.8
107
(count-if-not #'not #(a b nil c d nil e) :key 'not)
110
(deftest count-if-not-vector.9
111
(count-if-not #'oddp #(1 2 3 4 4 1 8 10 1))
114
(deftest count-if-not-vector.10
115
(count-if-not #'oddp #(1 2 3 4 4 1 8 10 1) :key #'1+)
118
(deftest count-if-not-vector.11
120
(count-if-not #'oddp #(1 2 3 4 4 1 8 10 1)
121
:key #'(lambda (x) (+ x (incf c)))))
124
(deftest count-if-not-vector.12
126
(count-if-not #'oddp #(0 1 2 3 4 4 1 7 10 1)
128
:key #'(lambda (x) (+ x (incf c)))))
131
(deftest count-if-not-vector.13
132
(count-if-not #'(lambda (x) (not (eqt x 'a)))
133
#(a b c d a e f a e f f a a) :start 2)
136
(deftest count-if-not-vector.14
137
(count-if-not #'(lambda (x) (not (eqt x 'a)))
138
#(a b c d a e f a e f f a a) :end 7)
141
(deftest count-if-not-vector.15
142
(count-if-not #'(lambda (x) (not (eqt x 'a)))
143
#(a b c d a e f a e f f a a) :end 7
147
(deftest count-if-not-vector.16
148
(count-if-not #'(lambda (x) (not (eqt x 'a)))
149
#(a b c d a e f a e f f a a) :end 7
150
:start 2 :from-end t)
153
;;; Non-simple vectors
155
(deftest count-if-not-nonsimple-vector.1
156
(count-if-not #'identity (make-array 7 :initial-contents '(a b nil c d nil e)
161
(deftest count-if-not-nonsimple-vector.2
162
(count-if-not #'not (make-array 7 :initial-contents '(a b nil c d nil e)
167
(deftest count-if-not-nonsimple-vector.3
168
(count-if-not #'(lambda (x) (break)) (make-array 0
173
(deftest count-if-not-nonsimple-vector.4
175
(make-array 7 :initial-contents '(a b nil c d nil e)
181
(deftest count-if-not-nonsimple-vector.5
183
(make-array 7 :initial-contents '(a b nil c d nil e)
189
(deftest count-if-not-nonsimple-vector.6
191
(make-array 7 :initial-contents '(a b nil c d nil e)
197
(deftest count-if-not-nonsimple-vector.8
199
(make-array 7 :initial-contents '(a b nil c d nil e)
205
(deftest count-if-not-nonsimple-vector.9
206
(count-if-not #'oddp (make-array 9 :initial-contents '(1 2 3 4 4 1 8 10 1)
207
:fill-pointer t :adjustable t))
210
(deftest count-if-not-nonsimple-vector.10
212
(make-array 9 :initial-contents '(1 2 3 4 4 1 8 10 1)
213
:fill-pointer t :adjustable t)
217
(deftest count-if-not-nonsimple-vector.11
220
(make-array 9 :initial-contents '(1 2 3 4 4 1 8 10 1)
221
:fill-pointer t :adjustable t)
222
:key #'(lambda (x) (+ x (incf c)))))
225
(deftest count-if-not-nonsimple-vector.12
228
(make-array 10 :initial-contents '(0 1 2 3 4 4 1 7 10 1)
229
:fill-pointer t :adjustable t)
231
:key #'(lambda (x) (+ x (incf c)))))
234
(deftest count-if-not-nonsimple-vector.13
235
(count-if-not #'(lambda (x) (not (eqt x 'a)))
236
(make-array 13 :initial-contents '(a b c d a e f a e f f a a)
237
:fill-pointer t :adjustable t)
241
(deftest count-if-not-nonsimple-vector.14
242
(count-if-not #'(lambda (x) (not (eqt x 'a)))
243
(make-array 13 :initial-contents '(a b c d a e f a e f f a a)
244
:fill-pointer t :adjustable t)
248
(deftest count-if-not-nonsimple-vector.15
249
(count-if-not #'(lambda (x) (not (eqt x 'a)))
250
(make-array 13 :initial-contents '(a b c d a e f a e f f a a)
251
:fill-pointer t :adjustable t)
255
(deftest count-if-not-nonsimple-vector.16
256
(count-if-not #'(lambda (x) (not (eqt x 'a)))
257
(make-array 13 :initial-contents '(a b c d a e f a e f f a a)
258
:fill-pointer t :adjustable t)
259
:end 7 :start 2 :from-end t)
262
(deftest count-if-not-nonsimple-vector.17
263
(flet ((%a (c) (not (eqt c 'a)))
264
(%f (c) (not (eqt c 'f))))
265
(let ((a (make-array 13 :initial-contents '(a b c d a e f a e f f a a)
267
(values (count-if-not #'%a a)
268
(count-if-not #'%a a :from-end t)
269
(count-if-not #'%f a)
270
(count-if-not #'%f a :from-end t)
274
;;; tests on bit-vectors
276
(deftest count-if-not-bit-vector.1
277
(count-if-not #'oddp #*001011101101)
280
(deftest count-if-not-bit-vector.2
281
(count-if-not #'identity #*001011101101)
284
(deftest count-if-not-bit-vector.3
285
(count-if-not #'(lambda (x) (break)) #*)
288
(deftest count-if-not-bit-vector.4
289
(count-if-not #'identity #*001011101101 :key #'zerop)
292
(deftest count-if-not-bit-vector.5
293
(count-if-not 'not #*001011101101 :key #'zerop)
296
(deftest count-if-not-bit-vector.6
297
(count-if-not #'not #*001011101101 :key 'zerop)
300
(deftest count-if-not-bit-vector.8
301
(count-if-not #'identity #*001011101101 :key 'oddp)
304
(deftest count-if-not-bit-vector.10
305
(count-if-not #'oddp #*001011101101 :key #'1+)
308
(deftest count-if-not-bit-vector.11
310
(count-if-not #'oddp #*001011101101
311
:key #'(lambda (x) (+ x (incf c)))))
314
(deftest count-if-not-bit-vector.12
316
(count-if-not #'oddp #*001011101101
318
:key #'(lambda (x) (+ x (incf c)))))
321
(deftest count-if-not-bit-vector.13
322
(count-if-not #'zerop #*0111011011100 :start 2)
325
(deftest count-if-not-bit-vector.14
326
(count-if-not #'zerop #*0111011011100 :end 7)
329
(deftest count-if-not-bit-vector.15
330
(count-if-not #'zerop #*0111011011100 :end 7 :start 2)
333
(deftest count-if-not-bit-vector.16
334
(count-if-not #'zerop #*0111011011100 :end 7 :start 2 :from-end t)
337
(deftest count-if-not-bit-vector.17
338
(let ((a (make-array '(10) :initial-contents '(0 0 0 1 1 1 0 1 0 0)
340
:element-type 'bit)))
341
(and (bit-vector-p a)
342
(values (count-if-not #'zerop a)
343
(count-if-not #'oddp a)
344
(count-if-not #'zerop a :from-end t)
345
(count-if-not #'oddp a :from-end t))))
350
(deftest count-if-not-string.1
351
(count-if-not #'(lambda (x) (eql x #\0)) "001011101101")
354
(deftest count-if-not-string.2
355
(count-if-not #'identity "001011101101")
358
(deftest count-if-not-string.3
359
(count-if-not #'(lambda (x) (break)) "")
362
(deftest count-if-not-string.4
363
(count-if-not #'identity "001011101101" :key #'(lambda (x) (eql x #\0)))
366
(deftest count-if-not-string.5
367
(count-if-not 'identity "001011101101" :key #'(lambda (x) (eql x #\0)))
370
(deftest count-if-not-string.6
371
(count-if-not #'(lambda (x) (eql x #\0)) "001011101101" :key 'identity)
374
(deftest count-if-not-string.8
375
(count-if-not #'identity "001011101101" :key #'(lambda (x) (eql x #\1)))
378
(deftest count-if-not-string.11
380
(count-if-not #'oddp "001011101101"
381
:key #'(lambda (x) (+ (if (eql x #\0) 0 1) (incf c)))))
384
(deftest count-if-not-string.12
386
(count-if-not #'oddp "001011101101"
388
:key #'(lambda (x) (+ (if (eql x #\0) 0 1) (incf c)))))
391
(deftest count-if-not-string.13
392
(count-if-not #'(lambda (x) (eql x #\0)) "0111011011100" :start 2)
395
(deftest count-if-not-string.14
396
(count-if-not #'(lambda (x) (eql x #\0)) "0111011011100" :end 7)
399
(deftest count-if-not-string.15
400
(count-if-not #'(lambda (x) (eql x #\0)) "0111011011100" :end 7 :start 2)
403
(deftest count-if-not-string.16
404
(count-if-not #'(lambda (x) (eql x #\0))
405
"0111011011100" :end 7 :start 2 :from-end t)
408
(deftest count-if-not-string.17
409
(flet ((%zerop (c) (eql c #\0))
410
(%onep (c) (eql c #\1)))
411
(let ((a (make-array '(10) :initial-contents "0001110100"
413
:element-type 'character)))
415
(values (count-if-not #'%zerop a)
416
(count-if-not #'%onep a)
417
(count-if-not #'%zerop a :from-end t)
418
(count-if-not #'%onep a :from-end t)))))
421
;;; Argument order tests
423
(deftest count-if-not.order.1
424
(let ((i 0) c1 c2 c3 c4 c5 c6)
427
(progn (setf c1 (incf i)) #'null)
428
(progn (setf c2 (incf i)) '(a nil b c nil d e))
429
:start (progn (setf c3 (incf i)) 0)
430
:end (progn (setf c4 (incf i)) 3)
431
:key (progn (setf c5 (incf i)) #'not)
432
:from-end (progn (setf c6 (incf i)) nil)
434
i c1 c2 c3 c4 c5 c6))
437
(deftest count-if-not.order.2
438
(let ((i 0) c1 c2 c3 c4 c5 c6)
441
(progn (setf c1 (incf i)) #'null)
442
(progn (setf c2 (incf i)) '(a nil b c nil d e))
443
:from-end (progn (setf c3 (incf i)) nil)
444
:key (progn (setf c4 (incf i)) #'not)
445
:end (progn (setf c5 (incf i)) 3)
446
:start (progn (setf c6 (incf i)) 0)
448
i c1 c2 c3 c4 c5 c6))
453
(deftest count-if-not.keywords.1
454
(count-if-not #'oddp '(1 2 3 4 5) :bad t :allow-other-keys t)
457
(deftest count-if-not.keywords.2
458
(count-if-not #'oddp '(1 2 3 4 5) :allow-other-keys #p"*" :also-bad t)
461
;;; The leftmost of two :allow-other-keys arguments is the one that matters.
462
(deftest count-if-not.keywords.3
463
(count-if-not #'oddp '(1 2 3 4 5)
465
:allow-other-keys nil
469
(deftest count-if-not.keywords.4
470
(count-if-not #'oddp '(1 2 3 4 5) :key #'identity :key #'1+)
473
(deftest count-if-not.allow-other-keys.5
474
(count-if-not #'null '(nil a b c nil) :allow-other-keys nil)
479
(deftest count-if-not.error.1
480
(signals-error (count-if-not #'identity 1) type-error)
483
(deftest count-if-not.error.2
484
(signals-error (count-if-not #'identity 'a) type-error)
487
(deftest count-if-not.error.3
488
(signals-error (count-if-not #'identity #\a) type-error)
491
(deftest count-if-not.error.4
492
(signals-error (count-if-not) program-error)
495
(deftest count-if-not.error.5
496
(signals-error (count-if-not #'null) program-error)
499
(deftest count-if-not.error.6
500
(signals-error (count-if-not #'null nil :bad t) program-error)
503
(deftest count-if-not.error.7
504
(signals-error (count-if-not #'null nil :bad t :allow-other-keys nil)
508
(deftest count-if-not.error.8
509
(signals-error (count-if-not #'null nil :key) program-error)
512
(deftest count-if-not.error.9
513
(signals-error (count-if-not #'null nil 3 3) program-error)
516
;;; Only leftmost :allow-other-keys argument matters
517
(deftest count-if-not.error.10
518
(signals-error (count-if-not #'null nil :bad t
519
:allow-other-keys nil
524
(deftest count-if-not.error.11
525
(signals-error (locally (count-if-not #'identity 1) t)
529
(deftest count-if-not.error.12
530
(signals-error (count-if-not #'cons '(a b c)) program-error)
533
(deftest count-if-not.error.13
534
(signals-error (count-if-not #'car '(a b c)) type-error)
537
(deftest count-if-not.error.14
538
(signals-error (count-if-not #'identity '(a b c) :key #'cdr)
542
(deftest count-if-not.error.15
543
(signals-error (count-if-not #'identity '(a b c) :key #'cons)