list-length.lsp 1.5 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 22:03:01 2003
;;;; Contains: Tests of LIST-LENGTH

6

7

8

9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
(deftest list-length-nil
  (list-length nil)
  0)

(deftest list-length-list
  (list-length '(a b c d e f))
  6)

;; check that list-length returns nil
;; on a circular list

(deftest list-length-circular-list
  (let ((x (cons nil nil)))
    (let ((y (list* 1 2 3 4 5 6 7 8 9 x)))
      (setf (cdr x) y)
      (let ((z (list* 'a 'b 'c 'd 'e y)))
sds's avatar
sds committed
26
        (list-length z))))
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  nil)

(deftest list-length.order.1
  (let ((i 0))
    (values (list-length (progn (incf i) '(a b c))) i))
  3 1)


(deftest list-length.4
  (list-length (copy-tree '(a b c)))
  3)

;; Check that list-length produces a type-error
;; on arguments that are not proper lists or circular lists

(deftest list-length.error.1
  (loop
   for x in (list 'a 1 1.0 #\w (make-array '(10))
sds's avatar
sds committed
45
                  '(a b . c) (symbol-package 'cons))
46
   count (not (eval `(signals-type-error x ',x (list-length x)))))
47 48 49
  0)

(deftest list-length.error.2
50 51
  (signals-error (list-length) program-error)
  t)
52 53

(deftest list-length.error.3
54 55
  (signals-error (list-length nil nil) program-error)
  t)
56 57

(deftest list-length.error.4
58 59
  (signals-error (list-length 'a) type-error)
  t)
60 61

(deftest list-length.error.5
62 63
  (signals-error (locally (list-length 'a) t) type-error)
  t)
64 65

(deftest list-length-symbol
66 67
  (signals-error (list-length 'a) type-error)
  t)
68 69

(deftest list-length-dotted-list
70 71
  (signals-error (list-length (copy-tree '(a b c d . e))) type-error)
  t)