cxr.lsp 11.4 KB
Newer Older
1 2
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
3 4
;;;; Created:  Sat Apr 19 21:28:38 2003
;;;; Contains: Tests of C*R functions
5 6 7

(in-package :cl-test)

8 9
(compile-and-load "cons-aux.lsp")

10 11 12 13
;; Tests of car, cdr and compound forms
(deftest cons.23
  (car '(a))
  a)
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 57 58 59 60 61 62 63 64 65 66 67 68
(deftest cons.24
  (cdr '(a . b))
  b)

(deftest cons.25
  (caar '((a)))
  a)

(deftest cons.26
  (cdar '((a . b)))
  b)

(deftest cons.27
  (cadr '(a b))
  b)

(deftest cons.28
  (cddr '(a b . c))
  c)

(deftest cons.29
  (caaar '(((a))))
  a)

(deftest cons.30
  (cdaar '(((a . b))))
  b)

(deftest cons.31
  (cadar (cons (cons 'a (cons 'b 'c)) 'd))
  b)

(deftest cons.32
  (cddar (cons (cons 'a (cons 'b 'c)) 'd))
  c)

(deftest cons.33
  (caadr (cons 'a (cons (cons 'b 'c) 'd)))
  b)

(deftest cons.34
  (caddr (cons 'a (cons 'b (cons 'c 'd))))
  c)

(deftest cons.36
  (cdadr (cons 'a (cons (cons 'b 'c) 'd)))
  c)

(deftest cons.37
  (cdddr (cons 'a (cons 'b (cons 'c 'd))))
  d)

(defvar *cons-test-4*
  (cons (cons (cons (cons 'a 'b)
sds's avatar
sds committed
69 70 71 72 73 74 75
                    (cons 'c 'd))
              (cons (cons 'e 'f)
                    (cons 'g 'h)))
        (cons (cons (cons 'i 'j)
                    (cons 'k 'l))
              (cons (cons 'm 'n)
                    (cons 'o 'p)))))
76 77 78 79 80 81 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

(deftest cons.38
  (caaaar *cons-test-4*)
  a)

(deftest cons.39
  (cdaaar *cons-test-4*)
  b)

(deftest cons.40
  (cadaar *cons-test-4*)
  c)

(deftest cons.41
  (cddaar *cons-test-4*)
  d)

(deftest cons.42
  (caadar *cons-test-4*)
  e)

(deftest cons.43
  (cdadar *cons-test-4*)
  f)

(deftest cons.44
  (caddar *cons-test-4*)
  g)

(deftest cons.45
  (cdddar *cons-test-4*)
  h)

;;;

(deftest cons.46
  (caaadr *cons-test-4*)
  i)

(deftest cons.47
  (cdaadr *cons-test-4*)
  j)

(deftest cons.48
  (cadadr *cons-test-4*)
  k)

(deftest cons.49
  (cddadr *cons-test-4*)
  l)

(deftest cons.50
  (caaddr *cons-test-4*)
  m)

(deftest cons.51
  (cdaddr *cons-test-4*)
  n)

(deftest cons.52
  (cadddr *cons-test-4*)
  o)

(deftest cons.53
  (cddddr *cons-test-4*)
  p)
142

143
(deftest car.1
144
  (car '(a))
145 146 147
  a)

(deftest car-nil
148
  (car nil)
149 150
  nil)

151 152 153
(deftest car.error.1
  (check-type-error #'car #'listp)
  nil)
154

155
(deftest car.error.2
156 157
  (signals-error (locally (car 'a) t) type-error)
  t)
158

159 160 161 162 163 164
(deftest car.order.1
  (let ((i 0))
    (values (car (progn (incf i) '(a b))) i))
  a 1)

(deftest cdr.1
165
  (cdr '(a b))
166 167 168
  (b))

(deftest cdr-nil
169
  (cdr ())
170 171
  nil)

172 173 174 175 176
(deftest cdr.order.1
  (let ((i 0))
    (values (cdr (progn (incf i) '(a b))) i))
  (b) 1)

177 178 179
(deftest cdr.error.1
  (check-type-error #'cdr #'listp)
  nil)
180

181
(deftest cdr.error.2
182 183
  (signals-error (locally (cdr 'a) t) type-error)
  t)
184

185 186
;;; Error checking of c*r functions

187
(deftest caar.error.1
188 189
  (signals-error (caar 'a) type-error)
  t)
190

191
(deftest caar.error.2
192 193
  (signals-error (caar '(a)) type-error)
  t)
194

195
(deftest cadr.error.1
196 197
  (signals-error (cadr 'a) type-error)
  t)
198

199
(deftest cadr.error.2
200 201
  (signals-error (cadr '(a . b)) type-error)
  t)
202

203
(deftest cdar.error.1
204 205
  (signals-error (cdar 'a) type-error)
  t)
206

207
(deftest cdar.error.2
208 209
  (signals-error (cdar '(a . b)) type-error)
  t)
210

211
(deftest cddr.error.1
212 213
  (signals-error (cddr 'a) type-error)
  t)
214

215
(deftest cddr.error.2
216 217
  (signals-error (cddr '(a . b)) type-error)
  t)
218

219
(deftest caaar.error.1
220 221
  (signals-error (caaar 'a) type-error)
  t)
222

223
(deftest caaar.error.2
224 225
  (signals-error (caaar '(a)) type-error)
  t)
226

227
(deftest caaar.error.3
228 229
  (signals-error (caaar '((a))) type-error)
  t)
230

231
(deftest caadr.error.1
232 233
  (signals-error (caadr 'a) type-error)
  t)
234

235
(deftest caadr.error.2
236 237
  (signals-error (caadr '(a . b)) type-error)
  t)
238

239
(deftest caadr.error.3
240 241
  (signals-error (caadr '(a . (b))) type-error)
  t)
242

243
(deftest cadar.error.1
244 245
  (signals-error (cadar 'a) type-error)
  t)
246

247
(deftest cadar.error.2
248 249
  (signals-error (cadar '(a . b)) type-error)
  t)
250

251
(deftest cadar.error.3
252 253
  (signals-error (cadar '((a . c) . b)) type-error)
  t)
254

255
(deftest caddr.error.1
256 257
  (signals-error (caddr 'a) type-error)
  t)
258

259
(deftest caddr.error.2
260 261
  (signals-error (caddr '(a . b)) type-error)
  t)
262

263
(deftest caddr.error.3
264 265
  (signals-error (caddr '(a c . b)) type-error)
  t)
266

267
(deftest cdaar.error.1
268 269
  (signals-error (cdaar 'a) type-error)
  t)
270

271
(deftest cdaar.error.2
272 273
  (signals-error (cdaar '(a)) type-error)
  t)
274

275
(deftest cdaar.error.3
276 277
  (signals-error (cdaar '((a . b))) type-error)
  t)
278

279
(deftest cdadr.error.1
280 281
  (signals-error (cdadr 'a) type-error)
  t)
282

283
(deftest cdadr.error.2
284 285
  (signals-error (cdadr '(a . b)) type-error)
  t)
286

287
(deftest cdadr.error.3
288 289
  (signals-error (cdadr '(a b . c)) type-error)
  t)
290

291
(deftest cddar.error.1
292 293
  (signals-error (cddar 'a) type-error)
  t)
294

295
(deftest cddar.error.2
296 297
  (signals-error (cddar '(a . b)) type-error)
  t)
298

299
(deftest cddar.error.3
300 301
  (signals-error (cddar '((a . b) . b)) type-error)
  t)
302

303
(deftest cdddr.error.1
304 305
  (signals-error (cdddr 'a) type-error)
  t)
306

307
(deftest cdddr.error.2
308 309
  (signals-error (cdddr '(a . b)) type-error)
  t)
310

311
(deftest cdddr.error.3
312 313
  (signals-error (cdddr '(a c . b)) type-error)
  t)
314 315 316

;;

317
(deftest caaaar.error.1
318 319
  (signals-error (caaaar 'a) type-error)
  t)
320

321
(deftest caaaar.error.2
322 323
  (signals-error (caaaar '(a)) type-error)
  t)
324

325
(deftest caaaar.error.3
326 327
  (signals-error (caaaar '((a))) type-error)
  t)
328

329
(deftest caaaar.error.4
330 331
  (signals-error (caaaar '(((a)))) type-error)
  t)
332

333
(deftest caaadr.error.1
334 335
  (signals-error (caaadr 'a) type-error)
  t)
336

337
(deftest caaadr.error.2
338 339
  (signals-error (caaadr '(a . b)) type-error)
  t)
340

341
(deftest caaadr.error.3
342 343
  (signals-error (caaadr '(a . (b))) type-error)
  t)
344

345
(deftest caaadr.error.4
346 347
  (signals-error (caaadr '(a . ((b)))) type-error)
  t)
348

349
(deftest caadar.error.1
350 351
  (signals-error (caadar 'a) type-error)
  t)
352

353
(deftest caadar.error.2
354 355
  (signals-error (caadar '(a . b)) type-error)
  t)
356

357
(deftest caadar.error.3
358 359
  (signals-error (caadar '((a . c) . b)) type-error)
  t)
360

361
(deftest caadar.error.4
362 363
  (signals-error (caadar '((a . (c)) . b)) type-error)
  t)
364

365
(deftest caaddr.error.1
366 367
  (signals-error (caaddr 'a) type-error)
  t)
368

369
(deftest caaddr.error.2
370 371
  (signals-error (caaddr '(a . b)) type-error)
  t)
372

373
(deftest caaddr.error.3
374 375
  (signals-error (caaddr '(a c . b)) type-error)
  t)
376

377
(deftest caaddr.error.4
378 379
  (signals-error (caaddr '(a c . (b))) type-error)
  t)
380

381
(deftest cadaar.error.1
382 383
  (signals-error (cadaar 'a) type-error)
  t)
384

385
(deftest cadaar.error.2
386 387
  (signals-error (cadaar '(a)) type-error)
  t)
388

389
(deftest cadaar.error.3
390 391
  (signals-error (cadaar '((a . b))) type-error)
  t)
392

393
(deftest cadaar.error.4
394 395
  (signals-error (cadaar '((a . (b)))) type-error)
  t)
396

397
(deftest cadadr.error.1
398 399
  (signals-error (cadadr 'a) type-error)
  t)
400

401
(deftest cadadr.error.2
402 403
  (signals-error (cadadr '(a . b)) type-error)
  t)
404

405
(deftest cadadr.error.3
406 407
  (signals-error (cadadr '(a b . c)) type-error)
  t)
408

409
(deftest cadadr.error.4
410 411
  (signals-error (cadadr '(a (b . e) . c)) type-error)
  t)
412

413
(deftest caddar.error.1
414 415
  (signals-error (caddar 'a) type-error)
  t)
416

417
(deftest caddar.error.2
418 419
  (signals-error (caddar '(a . b)) type-error)
  t)
420

421
(deftest caddar.error.3
422 423
  (signals-error (caddar '((a . b) . b)) type-error)
  t)
424

425
(deftest caddar.error.4
426 427
  (signals-error (caddar '((a  b . c) . b)) type-error)
  t)
428

429
(deftest cadddr.error.1
430 431
  (signals-error (cadddr 'a) type-error)
  t)
432

433
(deftest cadddr.error.2
434 435
  (signals-error (cadddr '(a . b)) type-error)
  t)
436

437
(deftest cadddr.error.3
438 439
  (signals-error (cadddr '(a c . b)) type-error)
  t)
440

441
(deftest cadddr.error.4
442 443
  (signals-error (cadddr '(a c e . b)) type-error)
  t)
444

445
(deftest cdaaar.error.1
446 447
  (signals-error (cdaaar 'a) type-error)
  t)
448

449
(deftest cdaaar.error.2
450 451
  (signals-error (cdaaar '(a)) type-error)
  t)
452

453
(deftest cdaaar.error.3
454 455
  (signals-error (cdaaar '((a))) type-error)
  t)
456

457
(deftest cdaaar.error.4
458 459
  (signals-error (cdaaar '(((a . b)))) type-error)
  t)
460

461
(deftest cdaadr.error.1
462 463
  (signals-error (cdaadr 'a) type-error)
  t)
464

465
(deftest cdaadr.error.2
466 467
  (signals-error (cdaadr '(a . b)) type-error)
  t)
468

469
(deftest cdaadr.error.3
470 471
  (signals-error (cdaadr '(a . (b))) type-error)
  t)
472

473
(deftest cdaadr.error.4
474 475
  (signals-error (cdaadr '(a . ((b . c)))) type-error)
  t)
476

477
(deftest cdadar.error.1
478 479
  (signals-error (cdadar 'a) type-error)
  t)
480

481
(deftest cdadar.error.2
482 483
  (signals-error (cdadar '(a . b)) type-error)
  t)
484

485
(deftest cdadar.error.3
486 487
  (signals-error (cdadar '((a . c) . b)) type-error)
  t)
488

489
(deftest cdadar.error.4
490 491
  (signals-error (cdadar '((a . (c . d)) . b)) type-error)
  t)
492

493
(deftest cdaddr.error.1
494 495
  (signals-error (cdaddr 'a) type-error)
  t)
496

497
(deftest cdaddr.error.2
498 499
  (signals-error (cdaddr '(a . b)) type-error)
  t)
500

501
(deftest cdaddr.error.3
502 503
  (signals-error (cdaddr '(a c . b)) type-error)
  t)
504

505
(deftest cdaddr.error.4
506 507
  (signals-error (cdaddr '(a c b . d)) type-error)
  t)
508

509
(deftest cddaar.error.1
510 511
  (signals-error (cddaar 'a) type-error)
  t)
512

513
(deftest cddaar.error.2
514 515
  (signals-error (cddaar '(a)) type-error)
  t)
516

517
(deftest cddaar.error.3
518 519
  (signals-error (cddaar '((a . b))) type-error)
  t)
520

521
(deftest cddaar.error.4
522 523
  (signals-error (cddaar '((a . (b)))) type-error)
  t)
524

525
(deftest cddadr.error.1
526 527
  (signals-error (cddadr 'a) type-error)
  t)
528

529
(deftest cddadr.error.2
530 531
  (signals-error (cddadr '(a . b)) type-error)
  t)
532

533
(deftest cddadr.error.3
534 535
  (signals-error (cddadr '(a b . c)) type-error)
  t)
536

537
(deftest cddadr.error.4
538 539
  (signals-error (cddadr '(a (b . e) . c)) type-error)
  t)
540

541
(deftest cdddar.error.1
542 543
  (signals-error (cdddar 'a) type-error)
  t)
544

545
(deftest cdddar.error.2
546 547
  (signals-error (cdddar '(a . b)) type-error)
  t)
548

549
(deftest cdddar.error.3
550 551
  (signals-error (cdddar '((a . b) . b)) type-error)
  t)
552

553
(deftest cdddar.error.4
554 555
  (signals-error (cdddar '((a  b . c) . b)) type-error)
  t)
556

557
(deftest cddddr.error.1
558 559
  (signals-error (cddddr 'a) type-error)
  t)
560

561
(deftest cddddr.error.2
562 563
  (signals-error (cddddr '(a . b)) type-error)
  t)
564

565
(deftest cddddr.error.3
566 567
  (signals-error (cddddr '(a c . b)) type-error)
  t)
568

569
(deftest cddddr.error.4
570 571
  (signals-error (cddddr '(a c e . b)) type-error)
  t)
572 573

;;; Need to add 'locally' wrapped forms of these
574 575 576 577 578 579

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; setting of C*R accessors

(loop
    for fn in '(car cdr caar cadr cdar cddr
sds's avatar
sds committed
580 581 582
                caaar caadr cadar caddr cdaar cdadr cddar cdddr
                caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
                cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr)
583 584
    do
      (let ((level (- (length (symbol-name fn)) 2)))
sds's avatar
sds committed
585 586 587 588 589 590 591 592 593 594 595 596 597
        (eval `(deftest ,(intern
                          (concatenate 'string
                            (symbol-name fn)
                            "-SET-ALT")
                          :cl-test)
                   (let ((x (create-c*r-test ,level)))
                     (and
                      (setf (,fn x) 'a)
                      (eql (,fn x) 'a)
                      (setf (,fn x) 'none)
                      (equalt x (create-c*r-test ,level))
                      ))
                 t))))
598 599 600

(loop
    for (fn len) in '((first 1) (second 2) (third 3) (fourth 4)
sds's avatar
sds committed
601 602
                      (fifth 5) (sixth 6) (seventh 7) (eighth 8)
                      (ninth 9) (tenth 10))
603 604 605
    do
      (eval
       `(deftest ,(intern
sds's avatar
sds committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
                   (concatenate 'string
                     (symbol-name fn)
                     "-SET-ALT")
                   :cl-test)
            (let ((x (make-list 20 :initial-element nil)))
              (and
               (setf (,fn x) 'a)
               (loop
                   for i from 1 to 20
                   do (when (and (not (eql i ,len))
                                 (nth (1- i) x))
                        (return nil))
                   finally (return t))
               (eql (,fn x) 'a)
               (nth ,(1- len) x)))
          a)))