nconc.lsp 1.51 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 22:35:53 2003
;;;; Contains: Tests of NCONC

(in-package :cl-test)

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

10 11 12 13 14 15 16 17 18 19 20 21 22 23
(deftest nconc.1
  (nconc)
  nil)

(deftest nconc.2
  (nconc (copy-tree '(a b c d e f)))
  (a b c d e f))

;;; (deftest nconc.3
;;;  (nconc 1)
;;;  1)

(deftest nconc.4
  (let ((x (list 'a 'b 'c))
sds's avatar
sds committed
24
        (y (list 'd 'e 'f)))
25 26
    (let ((ycopy (make-scaffold-copy y)))
      (let ((result (nconc x y)))
sds's avatar
sds committed
27 28 29 30
        (and
         (check-scaffold-copy y ycopy)
         (eqt (cdddr x) y)
         result))))
31 32 33 34 35 36 37 38 39 40 41 42
  (a b c d e f))

(deftest nconc.5
  (let ((x (list 'a 'b 'c)))
    (nconc x x)
    (and
     (eqt (cdddr x) x)
     (null (list-length x))))
  t)

(deftest nconc.6
  (let ((x (list 'a 'b 'c))
sds's avatar
sds committed
43 44
        (y (list 'd 'e 'f 'g 'h))
        (z (list 'i 'j 'k)))
45 46 47 48 49 50 51 52 53 54
    (let ((result (nconc x y z 'foo)))
      (and
       (eqt (nthcdr 3 x) y)
       (eqt (nthcdr 5 y) z)
       (eqt (nthcdr 3 z) 'foo)
       result)))
  (a b c d e f g h i j k . foo))

(deftest nconc.7
  (nconc (copy-tree '(a . b))
sds's avatar
sds committed
55 56 57
         (copy-tree '(c . d))
         (copy-tree '(e . f))
         'foo)
58 59 60 61 62 63
  (a c e . foo))

(deftest nconc.order.1
  (let ((i 0) x y z)
    (values
     (nconc (progn (setf x (incf i)) (copy-list '(a b c)))
sds's avatar
sds committed
64 65
            (progn (setf y (incf i)) (copy-list '(d e f)))
            (progn (setf z (incf i)) (copy-list '(g h i))))
66 67 68 69 70 71 72 73 74
     i x y z))
  (a b c d e f g h i) 3 1 2 3)

(deftest nconc.order.2
  (let ((i 0))
    (values
     (nconc (list 'a) (incf i))
     i))
  (a . 1) 1)