nbutlast.lsp 2.11 KB
Newer Older
1
2
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
3
4
;;;; Created:  Sat Apr 19 22:41:54 2003
;;;; Contains: Tests of NBUTLAST
5
6

(in-package :cl-test)
7

8
(deftest nbutlast.1
9
10
11
12
13
14
15
16
  (let ((x (list 'a 'b 'c 'd 'e)))
    (let ((y (cdr x))
	  (z (cddr x)))
      (let ((result (nbutlast x 2)))
	(and (eqt x result)
	     (eqt (cdr x) y)
	     (eqt (cddr x) z)
	     result))))
17
18
  (a b c))

19
(deftest nbutlast.2
20
21
22
  (let ((x (list 'a 'b 'c 'd 'e)))
    (let ((result (nbutlast x 5)))
      (list x result)))
23
24
  ((a b c d e) nil))

25
(deftest nbutlast.3
26
27
28
  (let ((x (list 'a 'b 'c 'd 'e)))
    (let ((result (nbutlast x 500)))
      (list x result)))
29
30
  ((a b c d e) nil))

31
(deftest nbutlast.4
32
33
34
35
  (let ((x (list* 'a 'b 'c 'd)))
    (let ((result (nbutlast x 1)))
      (and (eqt result x)
	   result)))
36
37
  (a b))

38
39
40
41
42
43
44
45
(deftest nbutlast.5
  (nbutlast nil)
  nil)

(deftest nbutlast.6
  (nbutlast (list 'a))
  nil)

46
47
48
49
(deftest nbutlast.7
  (nbutlast (list 'a 'b 'c 'd) (1+ most-positive-fixnum))
  nil)

50
(deftest nbutlast.order.1
51
52
53
54
55
56
57
58
59
  (let ((i 0) x y)
    (values
     (nbutlast (progn (setf x (incf i))
		      (list 'a 'b 'c 'd 'e))
	       (progn (setf y (incf i))
		      2))
     i x y))
  (a b c) 2 1 2)

60
61
62
63
64
65
66
(deftest nbutlast.order.2
  (let ((i 0))
    (values
     (nbutlast (progn (incf i) (list 'a 'b 'c 'd)))
     i))
  (a b c) 1)

67
(deftest nbutlast.error.1
68
  (classify-error (let ((x (list* 'a 'b 'c 'd))) (nbutlast x 'a)))
69
70
  type-error)

71
(deftest nbutlast.error.2
72
  (classify-error (nbutlast 'a 10))
73
74
  type-error)

75
(deftest nbutlast.error.3
76
  (classify-error (nbutlast 2 10))
77
78
  type-error)

79
(deftest nbutlast.error.4
80
  (classify-error (nbutlast #\w 10))
81
82
  type-error)

83
(deftest nbutlast.error.5
84
  (classify-error (nbutlast (list 'a 'b 'c 'd) -3))
85
86
  type-error)

87
(deftest nbutlast.error.6
88
  (classify-error (nbutlast (list 'a) 20.0))
89
90
  type-error)

91
(deftest nbutlast.error.7
92
  (classify-error (nbutlast (list 'a) -100.0))
93
  type-error)
94

95
(deftest nbutlast.error.8
96
97
98
  (classify-error (nbutlast))
  program-error)

99
(deftest nbutlast.error.9
100
101
  (classify-error (nbutlast (list 'a 'b 'c) 3 3))
  program-error)
102

103
(deftest nbutlast.error.10
104
105
  (classify-error (locally (nbutlast 'a 10) t))
  type-error)