mismatch.lsp 18.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Aug 26 23:55:29 2002
;;;; Contains: Tests for MISMATCH

(in-package :cl-test)

(deftest mismatch-list.1
  (mismatch '() '(a b c))
  0)

(deftest mismatch-list.2
  (mismatch '(a b c d) '())
  0)

(deftest mismatch-list.3
  (mismatch '(a b c) '(a b c))
  nil)

(deftest mismatch-list.4
  (mismatch '(a b c) '(a b d))
  2)

(deftest mismatch-list.5
  (mismatch '(a b c) '(b c) :start1 1)
  nil)

(deftest mismatch-list.6
  (mismatch '(a b c d) '(z b c e) :start1 1 :start2 1)
  3)

(deftest mismatch-list.7
  (mismatch '(a b c d) '(z b c e) :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

(deftest mismatch-list.8
  (mismatch '(1 2 3 4) '(5 6 7 8) :test #'(lambda (x y) (= x (- y 4))))
  nil)

(deftest mismatch-list.9
  (mismatch '(1 2 3 4) '(5 6 17 8) :test #'(lambda (x y) (= x (- y 4))))
  2)

(deftest mismatch-list.10
  (mismatch '(1 2 3 4) '(10 11 7 123) :test-not #'(lambda (x y) (= x (- y 4))))
  2)

(deftest mismatch-list.11
  (mismatch '(1 2 3 4) '(5 6 17 8) :key #'evenp)
  nil)

(deftest mismatch-list.12
  (mismatch '(1 2 3 4) '(5 6 12 8) :key 'oddp)
  2)

(deftest mismatch-list.13
57
  (mismatch '(1 2 3 4) '(1 2 3 4) :test 'eql)
58 59 60
  nil)

(deftest mismatch-list.14
61
  (mismatch '(1 2 3 4) '(5 6 7 8) :test-not 'eql)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  nil)

(deftest mismatch-list.15
  (mismatch '(a b c d e f g h i j k) '(a b c c e f g h z j k))
  3)

(deftest mismatch-list.16
  (mismatch '(a b c d e f g h i j k) '(a b c c y f g h z j k) :from-end t)
  9)

(deftest mismatch-list.17
  (mismatch '(a b c) '(a b c a b c d) :from-end t)
  3)

(deftest mismatch-list.18
  (mismatch '(a b c a b c d) '(a b c) :from-end t)
  7)

(deftest mismatch-list.19
81
  (mismatch '(1 1 1) '(2 2 2 2 2 1 2 2) :from-end t :test-not 'eql)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
  1)

(deftest mismatch-list.20
  (mismatch '(1 1 1 1 1 1 1) '(2 3 3) :from-end t :key #'evenp)
  5)

(deftest mismatch-list.21
  (mismatch '(1 1 1) '(2 2 2 2 2 1 2 2) :from-end t :test-not #'equal)
  1)

(deftest mismatch-list.22
  (mismatch '(1 1 1 1 1 1 1) '(2 3 3) :from-end t :key 'evenp)
  5)

;;; tests on vectors

(deftest mismatch-vector.1
  (mismatch #() #(a b c))
  0)

(deftest mismatch-vector.2
  (mismatch #(a b c d) #())
  0)

(deftest mismatch-vector.3
  (mismatch #(a b c) #(a b c))
  nil)

(deftest mismatch-vector.4
  (mismatch #(a b c) #(a b d))
  2)

(deftest mismatch-vector.5
  (mismatch #(a b c) #(b c) :start1 1)
  nil)

(deftest mismatch-vector.6
  (mismatch #(a b c d) #(z b c e) :start1 1 :start2 1)
  3)

(deftest mismatch-vector.7
  (mismatch #(a b c d) #(z b c e) :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

(deftest mismatch-vector.8
  (mismatch #(1 2 3 4) #(5 6 7 8) :test #'(lambda (x y) (= x (- y 4))))
  nil)

(deftest mismatch-vector.9
  (mismatch #(1 2 3 4) #(5 6 17 8) :test #'(lambda (x y) (= x (- y 4))))
  2)

(deftest mismatch-vector.10
  (mismatch #(1 2 3 4) #(10 11 7 123) :test-not #'(lambda (x y) (= x (- y 4))))
  2)

(deftest mismatch-vector.11
  (mismatch #(1 2 3 4) #(5 6 17 8) :key #'evenp)
  nil)

(deftest mismatch-vector.12
  (mismatch #(1 2 3 4) #(5 6 12 8) :key 'oddp)
  2)

(deftest mismatch-vector.13
147
  (mismatch #(1 2 3 4) #(1 2 3 4) :test 'eql)
148 149 150
  nil)

(deftest mismatch-vector.14
151
  (mismatch #(1 2 3 4) #(5 6 7 8) :test-not 'eql)
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
  nil)

(deftest mismatch-vector.15
  (mismatch #(a b c d e f g h i j k) #(a b c c e f g h z j k))
  3)

(deftest mismatch-vector.16
  (mismatch #(a b c d e f g h i j k) #(a b c c y f g h z j k) :from-end t)
  9)

(deftest mismatch-vector.17
  (mismatch #(a b c) #(a b c a b c d) :from-end t)
  3)

(deftest mismatch-vector.18
  (mismatch #(a b c a b c d) #(a b c) :from-end t)
  7)

(deftest mismatch-vector.19
171
  (mismatch #(1 1 1) #(2 2 2 2 2 1 2 2) :from-end t :test-not 'eql)
172 173 174 175 176 177 178 179 180 181 182 183 184 185
  1)

(deftest mismatch-vector.20
  (mismatch #(1 1 1 1 1 1 1) #(2 3 3) :from-end t :key #'evenp)
  5)

(deftest mismatch-vector.21
  (mismatch #(1 1 1) #(2 2 2 2 2 1 2 2) :from-end t :test-not #'equal)
  1)

(deftest mismatch-vector.22
  (mismatch #(1 1 1 1 1 1 1) #(2 3 3) :from-end t :key 'evenp)
  5)

186 187
(deftest mismatch-vector.23
  (let ((a (make-array '(9) :initial-contents '(1 2 3 4 5 6 7 8 9)
sds's avatar
sds committed
188
                       :fill-pointer 5)))
189 190 191 192 193 194 195 196
    (values
     (mismatch '(1 2 3 4 5) a)
     (mismatch '(1 2 3 4 5) a :from-end t)
     (mismatch '(1 2 3 4) a)
     (mismatch '(1 2 3 4 5 6) a)
     (mismatch '(6 7 8 9) a :from-end t)
     (mismatch '(2 3 4 5) a :from-end t)))
  nil nil 4 5 4 0)
197 198 199

(deftest mismatch-vector.24
  (let ((m (make-array '(6) :initial-contents '(1 2 3 4 5 6)
sds's avatar
sds committed
200 201
                       :fill-pointer 4))
        (a '(1 2 3 4 5)))
202 203 204 205 206 207 208 209 210
    (list
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 5)
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 6)
     (mismatch m a)
     (mismatch m a :from-end t)))
sds's avatar
sds committed
211
  (4 4 5 nil nil 6 5 6))
212

213 214
;;; tests on bit vectors

215
(deftest mismatch-bit-vector.1
216 217 218
  (mismatch "" #*111)
  0)

219
(deftest mismatch-bit-vector.1a
220 221 222
  (mismatch '() #*111)
  0)

223
(deftest mismatch-bit-vector.1b
224 225 226
  (mismatch "" '(1 1 1))
  0)

227
(deftest mismatch-bit-vector.2
228 229 230
  (mismatch #*1010 #*)
  0)

231
(deftest mismatch-bit-vector.2a
232 233 234
  (mismatch #*1010 '())
  0)

235
(deftest mismatch-bit-vector.2b
236 237 238
  (mismatch '(1 0 1 0) #*)
  0)

239
(deftest mismatch-bit-vector.3
240 241 242
  (mismatch #*101 #*101)
  nil)

243
(deftest mismatch-bit-vector.4
244 245 246
  (mismatch #*101 #*100)
  2)

247
(deftest mismatch-bit-vector.5
248 249 250
  (mismatch #*101  #*01 :start1 1)
  nil)

251
(deftest mismatch-bit-vector.6
252 253 254
  (mismatch #*0110 #*0111 :start1 1 :start2 1)
  3)

255
(deftest mismatch-bit-vector.7
256 257 258
  (mismatch #*0110 #*0111 :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

259
(deftest mismatch-bit-vector.7a
260 261 262
  (mismatch '(0 1 1 0) #*0111 :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

263
(deftest mismatch-bit-vector.7b
264 265 266
  (mismatch #*0110 '(0 1 1 1) :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

267
(deftest mismatch-bit-vector.8
268 269 270
  (mismatch #*1001 #*0110 :test #'(lambda (x y) (= x (- 1 y))))
  nil)

271
(deftest mismatch-bit-vector.8a
272 273 274
  (mismatch #*1001 '(5 4 4 5) :test #'(lambda (x y) (= x (- y 4))))
  nil)

275
(deftest mismatch-bit-vector.9
276 277 278
  (mismatch #*1001 '(5 4 17 5) :test #'(lambda (x y) (= x (- y 4))))
  2)

279
(deftest mismatch-bit-vector.9a
280 281 282
  (mismatch '(5 4 17 5) #*1001 :test #'(lambda (x y) (= y (- x 4))))
  2)

283
(deftest mismatch-bit-vector.9b
284 285 286
  (mismatch #*0100 #*1001 :test #'(lambda (x y) (= x (- 1 y))))
  2)

287
(deftest mismatch-bit-vector.10
288 289 290
  (mismatch #*1001 '(10 11 4 123) :test-not #'(lambda (x y) (= x (- y 4))))
  2)

291
(deftest mismatch-bit-vector.10a
292 293 294
  (mismatch #*1001 '(10 11 100 123) :test-not #'(lambda (x y) (= x (- y 4))))
  nil)

295
(deftest mismatch-bit-vector.11
296 297 298
  (mismatch #*1010 '(5 6 17 8) :key #'evenp)
  nil)

299
(deftest mismatch-bit-vector.11a
300 301 302
  (mismatch '(5 6 17 8) #*1010 :key #'evenp)
  nil)

303
(deftest mismatch-bit-vector.11b
304
  (mismatch #*0101 #*1010 :key #'evenp :test-not 'eql)
305 306
  nil)

307
(deftest mismatch-bit-vector.11c
308 309 310
  (mismatch '(5 6 17 8) #*10101 :key #'evenp)
  4)

311
(deftest mismatch-bit-vector.11d
312 313 314
  (mismatch '(5 6 17 8 100) #*1010 :key #'evenp)
  4)

315
(deftest mismatch-bit-vector.12
316 317 318
  (mismatch #*1010 #*1000 :key 'oddp)
  2)

319
(deftest mismatch-bit-vector.12a
320 321 322
  (mismatch #*1010 '(5 6 8 8) :key 'oddp)
  2)

323
(deftest mismatch-bit-vector.12b
324 325 326
  (mismatch '(5 6 8 8) #*1010 :key 'oddp)
  2)

327
(deftest mismatch-bit-vector.13
328
  (mismatch #*0001 #*0001 :test 'eql)
329 330
  nil)

331
(deftest mismatch-bit-vector.14
332
  (mismatch '#*10001 #*01110 :test-not 'eql)
333 334
  nil)

335
(deftest mismatch-bit-vector.15
336 337 338
  (mismatch #*00100010100 #*00110010000)
  3)

339
(deftest mismatch-bit-vector.16
340 341 342
  (mismatch #*00100010100 #*00110010000 :from-end t)
  9)

343
(deftest mismatch-bit-vector.17
344 345 346
  (mismatch #*001 #*0010010 :from-end t)
  3)

347
(deftest mismatch-bit-vector.18
348 349 350
  (mismatch #*0010010 #*001 :from-end t)
  7)

351
(deftest mismatch-bit-vector.19
352
  (mismatch #*000 #*11111011 :from-end t :test-not 'eql)
353 354
  1)

355
(deftest mismatch-bit-vector.20
356 357 358
  (mismatch #*1111111 '(2 3 3) :from-end t :key #'evenp)
  5)

359
(deftest mismatch-bit-vector.21
360 361 362
  (mismatch #*111 #*00000100 :from-end t :test-not #'equal)
  1)

363
(deftest mismatch-bit-vector.22
364 365 366
  (mismatch #*1111111 '(2 3 3) :from-end t :key 'evenp)
  5)

367
(deftest mismatch-bit-vector.23
368
  (let ((a (make-array '(9) :initial-contents #*001011000
sds's avatar
sds committed
369 370
                       :fill-pointer 5
                       :element-type 'bit)))
371 372 373 374 375 376 377 378 379 380
    (values
     (mismatch #*00101 a)
     (mismatch #*00101 a :from-end t)
     (mismatch #*0010 a)
     (mismatch #*001011 a)
     (mismatch #*1000 a :from-end t)
     (mismatch #*0010 a :from-end t)))
  nil nil 4 5 4 4)

(deftest mismatch-bit-vector.24
381
  (let ((m (make-array '(6) :initial-contents #*001011
sds's avatar
sds committed
382 383 384
                       :fill-pointer 4
                       :element-type 'bit))
        (a #*00101))
385 386 387 388 389 390 391 392 393 394 395
    (list
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 5)
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 6)
     (mismatch m a)
     (mismatch m a :from-end t)))
  (4 4 5 nil nil 6 5 5))

396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
;;; tests on strings

(deftest mismatch-string.1
  (mismatch "" "111")
  0)

(deftest mismatch-string.1a
  (mismatch '() "111")
  0)

(deftest mismatch-string.1b
  (mismatch "" '(1 1 1))
  0)

(deftest mismatch-string.2
  (mismatch "1010" "")
  0)

(deftest mismatch-string.2a
  (mismatch "1010" '())
  0)

(deftest mismatch-string.2b
  (mismatch '(1 0 1 0) "")
  0)

(deftest mismatch-string.3
  (mismatch "101" "101")
  nil)

(deftest mismatch-string.4
  (mismatch "101" "100")
  2)

(deftest mismatch-string.5
  (mismatch "101" "01" :start1 1)
  nil)

(deftest mismatch-string.6
  (mismatch "0110" "0111" :start1 1 :start2 1)
  3)

(deftest mismatch-string.7
  (mismatch "0110" "0111" :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

(deftest mismatch-string.7a
  (mismatch '(#\0 #\1 #\1 #\0) "0111" :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

(deftest mismatch-string.7b
  (mismatch "0110" '(#\0 #\1 #\1 #\1) :start1 1 :start2 1 :end1 3 :end2 3)
  nil)

(deftest mismatch-string.8
451
  (mismatch "1001" "0110" :test #'(lambda (x y) (eql x (if (eql y #\0)
sds's avatar
sds committed
452
                                                           #\1 #\0))))
453 454 455 456
  nil)

(deftest mismatch-string.8a
  (mismatch "1001" '(5 4 4 5) :test #'(lambda (x y)
sds's avatar
sds committed
457 458
                                        (setq x (read-from-string (string x)))
                                        (= x (- y 4))))
459 460 461 462
  nil)

(deftest mismatch-string.9
  (mismatch "1001" '(5 4 17 5) :test #'(lambda (x y)
sds's avatar
sds committed
463 464
                                         (setq x (read-from-string (string x)))
                                         (= x (- y 4))))
465 466 467 468
  2)

(deftest mismatch-string.9a
  (mismatch '(5 4 17 5) "1001" :test #'(lambda (x y)
sds's avatar
sds committed
469 470
                                         (setq y (read-from-string (string y)))
                                         (= y (- x 4))))
471 472 473 474 475 476 477 478
  2)

(deftest mismatch-string.9b
  (mismatch "0100" "1001" :test #'(lambda (x y) (eql x (if (eql y #\0) #\1 #\0))))
  2)

(deftest mismatch-string.10
  (mismatch "1001" "0049" :test-not #'(lambda (x y)
sds's avatar
sds committed
479 480 481
                                         (setq x (read-from-string (string x)))
                                         (setq y (read-from-string (string y)))
                                         (eql x (- y 4))))
482 483 484 485
  2)

(deftest mismatch-string.10a
  (mismatch "1001" "3333" :test-not #'(lambda (x y)
sds's avatar
sds committed
486 487 488
                                        (setq x (read-from-string (string x)))
                                        (setq y (read-from-string (string y)))
                                        (eql x (- y 4))))
489 490 491 492 493 494 495 496 497 498 499
  nil)

(deftest mismatch-string.11
  (mismatch "1010" "5678"  :key #'evendigitp)
  nil)

(deftest mismatch-string.11a
  (mismatch "5678" "1010" :key #'odddigitp)
  nil)

(deftest mismatch-string.11b
500
  (mismatch "0101" "1010" :key #'evendigitp :test-not 'eql)
501 502 503 504 505 506 507 508 509 510 511
  nil)

(deftest mismatch-string.11c
  (mismatch "5678" "10101" :key #'evendigitp)
  4)

(deftest mismatch-string.11d
  (mismatch "56122" "1010" :key #'evendigitp)
  4)

(deftest mismatch-string.11e
512
  (mismatch "0101" '(#\1 #\0 #\1 #\0) :key #'evendigitp :test-not 'eql)
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
  nil)

(deftest mismatch-string.12
  (mismatch "1010" "1000" :key 'odddigitp)
  2)

(deftest mismatch-string.12a
  (mismatch "1010" "5688" :key 'odddigitp)
  2)

(deftest mismatch-string.12b
  (mismatch '(#\5 #\6 #\8 #\8) "1010" :key 'odddigitp)
  2)

(deftest mismatch-string.13
528
  (mismatch "0001" "0001" :test 'eql)
529 530 531
  nil)

(deftest mismatch-string.14
532
  (mismatch "10001" "01110" :test-not 'eql)
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
  nil)

(deftest mismatch-string.15
  (mismatch "00100010100" "00110010000")
  3)

(deftest mismatch-string.16
  (mismatch "00100010100" "00110010000" :from-end t)
  9)

(deftest mismatch-string.17
  (mismatch "001" "0010010" :from-end t)
  3)

(deftest mismatch-string.18
  (mismatch "0010010" "001" :from-end t)
  7)

(deftest mismatch-string.19
552
  (mismatch "000" "11111011" :from-end t :test-not 'eql)
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
  1)

(deftest mismatch-string.20
  (mismatch "1111111" "233" :from-end t :key #'evendigitp)
  5)

(deftest mismatch-string.20a
  (mismatch "1111111" '(#\2 #\3 #\3) :from-end t :key #'evendigitp)
  5)

(deftest mismatch-string.21
  (mismatch "111" "00000100" :from-end t :test-not #'equal)
  1)

(deftest mismatch-string.22
  (mismatch "1111111" "233" :from-end t :key 'evendigitp)
  5)
570 571

(deftest mismatch-string.23
572
  (let ((a (make-array '(9) :initial-contents "123456789"
sds's avatar
sds committed
573 574
                       :fill-pointer 5
                       :element-type 'character)))
575 576 577 578 579 580 581 582 583 584
    (values
     (mismatch "12345" a)
     (mismatch "12345" a :from-end t)
     (mismatch "1234" a)
     (mismatch "123456" a)
     (mismatch "6789" a :from-end t)
     (mismatch "2345" a :from-end t)))
  nil nil 4 5 4 0)

(deftest mismatch-string.24
585
  (let ((m (make-array '(6) :initial-contents "123456"
sds's avatar
sds committed
586 587 588
                       :fill-pointer 4
                       :element-type 'character))
        (a "12345"))
589 590 591 592 593 594 595 596 597 598
    (list
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 5)
     (mismatch m a)
     (mismatch m a :from-end t)
     (setf (fill-pointer m) 6)
     (mismatch m a)
     (mismatch m a :from-end t)))
  (4 4 5 nil nil 6 5 6))
599

pfdietz's avatar
pfdietz committed
600 601
(deftest mistmatch-string.25
  (let ((s0 "12345")
sds's avatar
sds committed
602 603
        (s1 "123A")
        (s2 "245"))
pfdietz's avatar
pfdietz committed
604 605 606 607 608 609 610 611 612 613 614
    (do-special-strings
     (s s0 nil)
     (assert (null (mismatch s s0)))
     (assert (null (mismatch s0 s)))
     (assert (null (mismatch s s0 :from-end t)))
     (assert (null (mismatch s0 s :from-end t)))
     (assert (eql (mismatch s s1) 3))
     (assert (eql (mismatch s1 s) 3))
     ))
  nil)

615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
;;; test and test-not tests

(defharmless mismatch.test-and-test-not.1
  (mismatch '(1 2 3) '(1 2 4) :test #'eql :test-not #'eql))

(defharmless mismatch.test-and-test-not.2
  (mismatch '(1 2 3) '(1 2 4) :test-not #'eql :test #'eql))

(defharmless mismatch.test-and-test-not.3
  (mismatch #(1 2 3) #(1 2 4) :test #'eql :test-not #'eql))

(defharmless mismatch.test-and-test-not.4
  (mismatch #(1 2 3) #(1 2 4) :test-not #'eql :test #'eql))

(defharmless mismatch.test-and-test-not.5
  (mismatch "abc" "abd" :test #'eql :test-not #'eql))

(defharmless mismatch.test-and-test-not.6
  (mismatch "abc" "abd" :test-not #'eql :test #'eql))

(defharmless mismatch.test-and-test-not.7
  (mismatch #*011 #*010 :test #'eql :test-not #'eql))

(defharmless mismatch.test-and-test-not.8
  (mismatch #*011 #*010 :test-not #'eql :test #'eql))

641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
;;; Keyword tests

(deftest mismatch.allow-other-keys.1
  (mismatch "1234" "1244" :allow-other-keys t :bad t)
  2)

(deftest mismatch.allow-other-keys.2
  (mismatch "1234" "1244" :bad t :allow-other-keys t)
  2)

(deftest mismatch.allow-other-keys.3
  (mismatch "1234" "1244" :bad t :allow-other-keys t :allow-other-keys nil)
  2)

(deftest mismatch.allow-other-keys.4
sds's avatar
sds committed
656 657
  (mismatch "1234" "1244" :allow-other-keys t :bad t
            :allow-other-keys nil)
658 659 660 661
  2)

(deftest mismatch.allow-other-keys.5
  (mismatch "1234" "1244" :allow-other-keys t
sds's avatar
sds committed
662 663
            :allow-other-keys nil
            :bad t)
664 665 666 667 668 669 670 671
  2)

(deftest mismatch.keywords.6
  (mismatch "1234" "1244" :test #'equal :test (complement #'equal))
  2)

(deftest mismatch.allow-other-keys.7
  (mismatch "1234" "1244" :bad t :allow-other-keys t
sds's avatar
sds committed
672
            :test (complement #'equal))
673 674
  0)

675 676 677 678 679 680
;;; Order of evaluation

(deftest mismatch.order.1
  (let ((i 0) a b)
    (values
     (mismatch (progn (setf a (incf i)) "abcd")
sds's avatar
sds committed
681
               (progn (setf b (incf i)) "abzd"))
682 683 684 685 686 687 688
     i a b))
  2 2 1 2)

(deftest mismatch.order.2
  (let ((i 0) a b c d e f g h j)
    (values
     (mismatch (progn (setf a (incf i)) "abcdef")
sds's avatar
sds committed
689 690 691 692 693 694 695 696
               (progn (setf b (incf i)) "abcdef")
               :key (progn (setf c (incf i)) #'identity)
               :test (progn (setf d (incf i)) #'equal)
               :start1 (progn (setf e (incf i)) 1)
               :start2 (progn (setf f (incf i)) 1)
               :end1 (progn (setf g (incf i)) 4)
               :end2 (progn (setf h (incf i)) 4)
               :from-end (setf j (incf i)))
697 698 699 700 701 702 703
     i a b c d e f g h j))
  nil 9 1 2 3 4 5 6 7 8 9)

(deftest mismatch.order.3
  (let ((i 0) a b c d e f g h j)
    (values
     (mismatch (progn (setf a (incf i)) "abcdef")
sds's avatar
sds committed
704 705 706 707 708 709 710 711
               (progn (setf b (incf i)) "abcdef")
               :from-end (setf c (incf i))
               :end2 (progn (setf d (incf i)) 4)
               :end1 (progn (setf e (incf i)) 4)
               :start2 (progn (setf f (incf i)) 1)
               :start1 (progn (setf g (incf i)) 1)
               :test (progn (setf h (incf i)) #'equal)
               :key (progn (setf j (incf i)) #'identity))
712 713 714 715
     i a b c d e f g h j))
  nil 9 1 2 3 4 5 6 7 8 9)


716 717 718
;;; Error cases

(deftest mismatch.error.1
719 720
  (signals-error (mismatch) program-error)
  t)
721 722

(deftest mismatch.error.2
723 724
  (signals-error (mismatch nil) program-error)
  t)
725 726

(deftest mismatch.error.3
727 728
  (signals-error (mismatch nil nil :bad t) program-error)
  t)
729 730

(deftest mismatch.error.4
731
  (signals-error (mismatch nil nil :bad t :allow-other-keys nil)
sds's avatar
sds committed
732
                 program-error)
733
  t)
734 735

(deftest mismatch.error.5
736 737
  (signals-error (mismatch nil nil :key) program-error)
  t)
738 739

(deftest mismatch.error.6
740 741
  (signals-error (mismatch nil nil 1 2) program-error)
  t)
742 743

(deftest mismatch.error.7
744 745
  (signals-error (mismatch '(a b) '(a b) :test #'identity) program-error)
  t)
746 747

(deftest mismatch.error.8
748 749
  (signals-error (mismatch '(a b) '(a b) :test-not #'identity) program-error)
  t)
750 751

(deftest mismatch.error.9
752 753
  (signals-error (mismatch '(a b) '(a b) :key #'car) type-error)
  t)
754 755

(deftest mismatch.error.10
756 757 758
  (signals-error (mismatch '(a b) '(a b) :key #'cons) program-error)
  t)