nth.lsp 1.13 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 22:33:23 2003
;;;; Contains: Tests of NTH

6

7

8

9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(deftest nth.1
  (nth-1-body (loop for i from 1 to 2000 collect (* 4 i)))
  0)

(deftest nth.2
  (let ((x (loop for i from 1 to 2000 collect i)))
    (loop
     for i from 0 to 1999 do
     (setf (nth i x) (- 1999 i)))
    (equalt x (loop for i from 1999 downto 0 collect i)))
  t)

;;; Test side effects, evaluation order in assignment to NTH
(deftest nth.order.1
  (let ((i 0)
sds's avatar
sds committed
25 26
        (x (list 'a 'b 'c 'd))
        y z)
27 28
    (and
     (eqlt (setf (nth (setf y (incf i)) x) (progn (setf z (incf i)) 'z))
sds's avatar
sds committed
29
           'z)
30 31 32 33 34 35 36 37 38
     (eqlt y 1)
     (eqlt z 2)
     x))
  (a z c d))

(deftest nth.order.2
  (let ((i 0) x y (z '(a b c d e)))
    (values
     (nth (progn (setf x (incf i)) 1)
sds's avatar
sds committed
39
          (progn (setf y (incf i)) z))
40 41 42 43
     i x y))
  b 2 1 2)

(deftest nth.error.1
44 45
  (signals-error (nth) program-error)
  t)
46 47

(deftest nth.error.2
48 49
  (signals-error (nth 0) program-error)
  t)
50 51

(deftest nth.error.3
52 53
  (signals-error (nth 1 '(a b c) nil) program-error)
  t)
54 55

(deftest nth.error.4
56 57
  (signals-error (nth 0 '(a b c) nil) program-error)
  t)