1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Sat Apr 19 22:41:54 2003 |
---|
4 | ;;;; Contains: Tests of NBUTLAST |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (compile-and-load "cons-aux.lsp") |
---|
9 | |
---|
10 | (deftest nbutlast.1 |
---|
11 | (let ((x (list 'a 'b 'c 'd 'e))) |
---|
12 | (let ((y (cdr x)) |
---|
13 | (z (cddr x))) |
---|
14 | (let ((result (nbutlast x 2))) |
---|
15 | (and (eqt x result) |
---|
16 | (eqt (cdr x) y) |
---|
17 | (eqt (cddr x) z) |
---|
18 | result)))) |
---|
19 | (a b c)) |
---|
20 | |
---|
21 | (deftest nbutlast.2 |
---|
22 | (let ((x (list 'a 'b 'c 'd 'e))) |
---|
23 | (let ((result (nbutlast x 5))) |
---|
24 | (list x result))) |
---|
25 | ((a b c d e) nil)) |
---|
26 | |
---|
27 | (deftest nbutlast.3 |
---|
28 | (let ((x (list 'a 'b 'c 'd 'e))) |
---|
29 | (let ((result (nbutlast x 500))) |
---|
30 | (list x result))) |
---|
31 | ((a b c d e) nil)) |
---|
32 | |
---|
33 | (deftest nbutlast.4 |
---|
34 | (let ((x (list* 'a 'b 'c 'd))) |
---|
35 | (let ((result (nbutlast x 1))) |
---|
36 | (and (eqt result x) |
---|
37 | result))) |
---|
38 | (a b)) |
---|
39 | |
---|
40 | (deftest nbutlast.5 |
---|
41 | (nbutlast nil) |
---|
42 | nil) |
---|
43 | |
---|
44 | (deftest nbutlast.6 |
---|
45 | (nbutlast (list 'a)) |
---|
46 | nil) |
---|
47 | |
---|
48 | (deftest nbutlast.7 |
---|
49 | (nbutlast (list 'a 'b 'c 'd) (1+ most-positive-fixnum)) |
---|
50 | nil) |
---|
51 | |
---|
52 | (deftest nbutlast.8 |
---|
53 | (nbutlast (list 'a 'b 'c 'd) most-positive-fixnum) |
---|
54 | nil) |
---|
55 | |
---|
56 | (deftest nbutlast.9 |
---|
57 | (nbutlast (list 'a 'b 'c 'd) (1- most-positive-fixnum)) |
---|
58 | nil) |
---|
59 | |
---|
60 | (deftest nbutlast.order.1 |
---|
61 | (let ((i 0) x y) |
---|
62 | (values |
---|
63 | (nbutlast (progn (setf x (incf i)) |
---|
64 | (list 'a 'b 'c 'd 'e)) |
---|
65 | (progn (setf y (incf i)) |
---|
66 | 2)) |
---|
67 | i x y)) |
---|
68 | (a b c) 2 1 2) |
---|
69 | |
---|
70 | (deftest nbutlast.order.2 |
---|
71 | (let ((i 0)) |
---|
72 | (values |
---|
73 | (nbutlast (progn (incf i) (list 'a 'b 'c 'd))) |
---|
74 | i)) |
---|
75 | (a b c) 1) |
---|
76 | |
---|
77 | ;;; Error tests |
---|
78 | |
---|
79 | (deftest nbutlast.error.1 |
---|
80 | (signals-error (let ((x (list* 'a 'b 'c 'd))) (nbutlast x 'a)) |
---|
81 | type-error) |
---|
82 | t) |
---|
83 | |
---|
84 | (deftest nbutlast.error.2 |
---|
85 | (signals-error (nbutlast 'a 10) type-error) |
---|
86 | t) |
---|
87 | |
---|
88 | (deftest nbutlast.error.3 |
---|
89 | (signals-error (nbutlast 2 10) type-error) |
---|
90 | t) |
---|
91 | |
---|
92 | (deftest nbutlast.error.4 |
---|
93 | (signals-error (nbutlast #\w 10) type-error) |
---|
94 | t) |
---|
95 | |
---|
96 | (deftest nbutlast.error.5 |
---|
97 | (signals-error (nbutlast (list 'a 'b 'c 'd) -3) type-error) |
---|
98 | t) |
---|
99 | |
---|
100 | (deftest nbutlast.error.6 |
---|
101 | (signals-error (nbutlast (list 'a) 20.0) type-error) |
---|
102 | t) |
---|
103 | |
---|
104 | (deftest nbutlast.error.7 |
---|
105 | (signals-error (nbutlast (list 'a) -100.0) type-error) |
---|
106 | t) |
---|
107 | |
---|
108 | (deftest nbutlast.error.8 |
---|
109 | (signals-error (nbutlast) program-error) |
---|
110 | t) |
---|
111 | |
---|
112 | (deftest nbutlast.error.9 |
---|
113 | (signals-error (nbutlast (list 'a 'b 'c) 3 3) program-error) |
---|
114 | t) |
---|
115 | |
---|
116 | (deftest nbutlast.error.10 |
---|
117 | (signals-error (locally (nbutlast 'a 10) t) type-error) |
---|
118 | t) |
---|