2
;;;; Author: Paul Dietz
3
;;;; Created: Sun Apr 20 07:42:35 2003
4
;;;; Contains: Tests of NUNION
8
(compile-and-load "cons-aux.lsp")
15
(nunion-with-copy (list 'a) nil)
19
(nunion-with-copy (list 'a) (list 'a))
23
(nunion-with-copy (list 1) (list 1))
27
(let ((x (list 'a 'b)))
28
(nunion-with-copy (list x) (list x)))
32
(let ((x '(a b c d e f))
34
(let ((result (nunion-with-copy x y)))
35
(check-union x y result)))
39
(let ((x '(a b c d e f))
41
(let ((result (nunion-with-copy x y :test #'eq)))
42
(check-union x y result)))
46
(let ((x '(a b c d e f))
48
(let ((result (nunion-with-copy x y :test #'eql)))
49
(check-union x y result)))
53
(let ((x '(a b c d e f))
55
(let ((result (nunion-with-copy x y :test #'equal)))
56
(check-union x y result)))
60
(let ((x '(a b c d e f))
62
(let ((result (nunion-with-copy x y :test-not (complement #'eql))))
63
(check-union x y result)))
67
(let ((x '(a b c d e f))
69
(let ((result (nunion-with-copy x y :test-not (complement #'equal))))
70
(check-union x y result)))
74
(let ((x '(a b c d e f))
76
(let ((result (nunion-with-copy x y :test-not (complement #'eq))))
77
(check-union x y result)))
81
(let ((x '(1 2 3 4 5 6 7))
82
(y '(10 19 5 3 17 1001 2)))
83
(let ((result (nunion-with-copy x y)))
84
(check-union x y result)))
88
(let ((x '(1 2 3 4 5 6 7))
89
(y '(10 19 5 3 17 1001 2)))
90
(let ((result (nunion-with-copy x y :test #'equal)))
91
(check-union x y result)))
95
(let ((x '(1 2 3 4 5 6 7))
96
(y '(10 19 5 3 17 1001 2)))
97
(let ((result (nunion-with-copy x y :test #'eql)))
98
(check-union x y result)))
102
(let ((x '(1 2 3 4 5 6 7))
103
(y '(10 19 5 3 17 1001 2)))
104
(let ((result (nunion-with-copy x y :test-not (complement #'equal))))
105
(check-union x y result)))
109
(let ((x '(1 2 3 4 5 6 7))
110
(y '(10 19 5 3 17 1001 2)))
111
(let ((result (nunion-with-copy x y :test-not (complement #'eql))))
112
(check-union x y result)))
116
(let ((x '(1 2 3 4 5 6 7))
117
(y '(10 19 5 3 17 1001 2)))
118
(let ((result (nunion-with-copy-and-key x y #'1+)))
119
(check-union x y result)))
123
(let ((x '(1 2 3 4 5 6 7))
124
(y '(10 19 5 3 17 1001 2)))
125
(let ((result (nunion-with-copy-and-key x y #'1+ :test #'equal)))
126
(check-union x y result)))
130
(let ((x '(1 2 3 4 5 6 7))
131
(y '(10 19 5 3 17 1001 2)))
132
(let ((result (nunion-with-copy-and-key x y #'1+ :test #'eql)))
133
(check-union x y result)))
137
(let ((x '(1 2 3 4 5 6 7))
138
(y '(10 19 5 3 17 1001 2)))
139
(let ((result (nunion-with-copy-and-key x y #'1+
140
:test-not (complement #'equal))))
141
(check-union x y result)))
145
(let ((x '(1 2 3 4 5 6 7))
146
(y '(10 19 5 3 17 1001 2)))
147
(let ((result (nunion-with-copy-and-key x y #'1+
148
:test-not (complement #'equal))))
149
(check-union x y result)))
153
(let ((x '(1 2 3 4 5 6 7))
154
(y '(10 19 5 3 17 1001 2)))
155
(let ((result (nunion-with-copy-and-key x y nil)))
156
(check-union x y result)))
160
(let ((x '(1 2 3 4 5 6 7))
161
(y '(10 19 5 3 17 1001 2)))
162
(let ((result (nunion-with-copy-and-key x y '1+)))
163
(check-union x y result)))
166
;; Do large numbers of random nunions
169
(do-random-nunions 100 100 200)
173
(let ((x (shuffle '(1 4 6 10 45 101)))
174
(y '(102 5 2 11 44 6)))
175
(let ((result (nunion-with-copy x y
176
:test #'(lambda (a b)
177
(<= (abs (- a b)) 1)))))
180
'((2 . 1) (5 . 4) (11 . 10) (45 . 44) (102 . 101))
185
;; Check that nunion uses eql, not equal or eq
191
while (not (typep x 'bignum))
197
(eqt x y) ;; if bignums are eq, the test is worthless
199
(nunion-with-copy (list x) (list x)))
204
(nunion-with-copy (list (copy-seq "aa"))
205
(list (copy-seq "aa")))
208
(defharmless nunion.test-and-test-not.1
209
(nunion (list 1 4 8 10) (list 1 2 3 9 10 13) :test #'eql :test-not #'eql))
211
(defharmless nunion.test-and-test-not.2
212
(nunion (list 1 4 8 10) (list 1 2 3 9 10 13) :test-not #'eql :test #'eql))
214
;; Check that nunion does not reverse the arguments to :test, :test-not
222
:test #'(lambda (x y)
223
(when (< y x) (return-from fail 'fail))
231
(nunion-with-copy-and-key
235
:test #'(lambda (x y)
236
(when (< y x) (return-from fail 'fail))
249
(when (< y x) (return-from fail 'fail))
257
(nunion-with-copy-and-key
261
:test-not #'(lambda (x y)
262
(when (< y x) (return-from fail 'fail))
267
;;; Order of evaluation tests
269
(deftest nunion.order.1
273
(nunion (progn (setf x (incf i)) (copy-list '(1 3 5)))
274
(progn (setf y (incf i)) (copy-list '(2 5 8))))
280
(deftest nunion.order.2
284
(nunion (progn (setf x (incf i)) (copy-list '(1 3 5)))
285
(progn (setf y (incf i)) (copy-list '(2 5 8)))
286
:test (progn (setf z (incf i)) #'eql)
287
:key (progn (setf w (incf i)) #'identity))
294
(deftest nunion.order.3
298
(nunion (progn (setf x (incf i)) (copy-list '(1 3 5)))
299
(progn (setf y (incf i)) (copy-list '(2 5 8)))
300
:key (progn (setf z (incf i)) #'identity)
301
:test (progn (setf w (incf i)) #'eql))
309
(deftest nunion.allow-other-keys.1
310
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2) :bad t
311
:allow-other-keys "yes")
313
(1 2 5 7 9 10 11 20))
315
(deftest nunion.allow-other-keys.2
316
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2)
317
:allow-other-keys t :also-bad t)
319
(1 2 5 7 9 10 11 20))
321
(deftest nunion.allow-other-keys.3
322
(sort (nunion (list 1 2 3) (list 1 2 3)
323
:allow-other-keys t :also-bad t
324
:test #'(lambda (x y) (= x (+ y 100))))
328
(deftest nunion.allow-other-keys.4
329
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2)
332
(1 2 5 7 9 10 11 20))
334
(deftest nunion.allow-other-keys.5
335
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2)
336
:allow-other-keys nil)
338
(1 2 5 7 9 10 11 20))
340
(deftest nunion.allow-other-keys.6
341
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2)
343
:allow-other-keys nil)
345
(1 2 5 7 9 10 11 20))
347
(deftest nunion.allow-other-keys.7
348
(sort (nunion (list 7 9 1 5) (list 10 11 9 20 1 2)
350
:allow-other-keys nil
353
(1 2 5 7 9 10 11 20))
355
(deftest nunion.keywords.9
356
(sort (nunion (list 1 2 3) (list 1 2 3)
357
:test #'(lambda (x y) (= x (+ y 100)))
364
(deftest nunion.error.1
365
(signals-error (nunion) program-error)
368
(deftest nunion.error.2
369
(signals-error (nunion nil) program-error)
372
(deftest nunion.error.3
373
(signals-error (nunion nil nil :bad t) program-error)
376
(deftest nunion.error.4
377
(signals-error (nunion nil nil :key) program-error)
380
(deftest nunion.error.5
381
(signals-error (nunion nil nil 1 2) program-error)
384
(deftest nunion.error.6
385
(signals-error (nunion nil nil :bad t :allow-other-keys nil) program-error)
388
(deftest nunion.error.7
389
(signals-error (nunion (list 1 2) (list 3 4) :test #'identity) program-error)
392
(deftest nunion.error.8
393
(signals-error (nunion (list 1 2) (list 3 4) :test-not #'identity) program-error)
396
(deftest nunion.error.9
397
(signals-error (nunion (list 1 2) (list 3 4) :key #'cons) program-error)
400
(deftest nunion.error.10
401
(signals-error (nunion (list 1 2) (list 3 4) :key #'car) type-error)
404
(deftest nunion.error.11
405
(signals-error (nunion (list 1 2 3) (list* 4 5 6)) type-error)
408
(deftest nunion.error.12
409
(signals-error (nunion (list* 1 2 3) (list 4 5 6)) type-error)