last.lsp 2.04 KB
Newer Older
1 2 3 4 5 6
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Mar 28 07:37:21 1998
;;;; Contains: Testing of CL Features related to "CONS", part 10

(in-package :cl-test)
7

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

10 11
(deftest last.1
  (last nil)
12 13
  nil)

14 15
(deftest last.2
  (last (copy-tree '(a b)))
16 17
  (b))

18 19
(deftest last.3
  (last (copy-tree '(a b . c)))
20 21
  (b . c))

22 23
(deftest last.4
  (last (copy-tree '(a b c d)) 0)
24 25
  nil)

26 27
(deftest last.5
  (last (copy-tree '(a b c d)) 1)
28 29
  (d))

30 31
(deftest last.6
  (last (copy-tree '(a b c d)) 2)
32 33
  (c d))

34 35
(deftest last.7
  (last (copy-tree '(a b c d)) 5)
36 37
  (a b c d))

38 39
(deftest last.8
  (last (cons 'a 'b) 0)
40 41
  b)

42 43
(deftest last.9
  (last (cons 'a 'b) 1)
44 45
  (a . b))

46 47
(deftest last.10
  (last (cons 'a 'b) 2)
48 49
  (a . b))

50 51 52 53 54 55 56 57 58 59
(deftest last.11
  (let ((x '(a b c)))
    (eqt (last x (1+ most-positive-fixnum)) x))
  t)

(deftest last.12
  (let ((x '(a b c . d)))
    (eqt (last x (1+ most-positive-fixnum)) x))
  t)

60 61 62 63 64 65 66 67 68 69
(deftest last.13
  (let ((x '(a b c . d)))
    (eqt (last x  most-positive-fixnum) x))
  t)

(deftest last.14
  (let ((x '(a b c . d)))
    (eqt (last x (1- most-positive-fixnum)) x))
  t)

70
(deftest last.order.1
71 72 73
  (let ((i 0) x y)
    (values
     (last (progn (setf x (incf i)) (list 'a 'b 'c 'd))
sds's avatar
sds committed
74
           (setf y (incf i)))
75 76 77
     i x y))
  (c d) 2 1 2)

78 79 80 81 82
(deftest last.order.2
  (let ((i 0))
    (values (last (progn (incf i) (list 'a 'b 'c 'd))) i))
  (d) 1)

83
(deftest last.error.1
84 85
  (signals-error (last (list 'a 'b 'c) -1) type-error)
  t)
86

87
(deftest last.error.2
88 89
  (signals-error (last (list 'a 'b 'c) 'a) type-error)
  t)
90

91
(deftest last.error.3
92 93
  (signals-error (last (list 'a 'b 'c) 10.0) type-error)
  t)
94

95
(deftest last.error.4
96 97
  (signals-error (last (list 'a 'b 'c) -10.0) type-error)
  t)
98

99
(deftest last.error.5
100 101
  (signals-error (last (list 'a 'b 'c) #\w) type-error)
  t)
102

103
(deftest last.error.6
104 105
  (signals-error (last) program-error)
  t)
106

107
(deftest last.error.7
108 109
  (signals-error (last '(a b c) 2 nil) program-error)
  t)
110 111

(deftest last.error.8
112
  (signals-error (locally (last (list 'a 'b 'c) 'a) t)
sds's avatar
sds committed
113
                 type-error)
114 115
  t)