1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Thu Sep 4 20:01:15 2003 |
---|
4 | ;;;; Contains: Tests of INCF |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (compile-and-load "numbers-aux.lsp") |
---|
9 | |
---|
10 | (deftest incf.1 |
---|
11 | (let ((x 12)) |
---|
12 | (values |
---|
13 | (incf x) |
---|
14 | x)) |
---|
15 | 13 13) |
---|
16 | |
---|
17 | (deftest incf.2 |
---|
18 | (let ((x 3.0s0)) |
---|
19 | (values |
---|
20 | (incf x) |
---|
21 | x)) |
---|
22 | 4.0s0 4.0s0) |
---|
23 | |
---|
24 | (deftest incf.3 |
---|
25 | (let ((x 19.0f0)) |
---|
26 | (values |
---|
27 | (incf x) |
---|
28 | x)) |
---|
29 | 20.0f0 20.0f0) |
---|
30 | |
---|
31 | (deftest incf.4 |
---|
32 | (let ((x 813.0d0)) |
---|
33 | (values |
---|
34 | (incf x) |
---|
35 | x)) |
---|
36 | 814.0d0 814.0d0) |
---|
37 | |
---|
38 | (deftest incf.5 |
---|
39 | (let ((x -17.0l0)) |
---|
40 | (values |
---|
41 | (incf x) |
---|
42 | x)) |
---|
43 | -16.0l0 -16.0l0) |
---|
44 | |
---|
45 | (deftest incf.6 |
---|
46 | (loop for x from 1 to 5 |
---|
47 | collect (let ((y x)) |
---|
48 | (list (incf y) y))) |
---|
49 | ((2 2) (3 3) (4 4) (5 5) (6 6))) |
---|
50 | |
---|
51 | (deftest incf.7 |
---|
52 | (loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0) |
---|
53 | collect (let ((y x)) |
---|
54 | (list (incf y) y))) |
---|
55 | ((2.0s0 2.0s0) (2.0f0 2.0f0) (2.0d0 2.0d0) (2.0l0 2.0l0))) |
---|
56 | |
---|
57 | (deftest incf.8 |
---|
58 | (loop for x in '(1.0s0 1.0f0 1.0d0 1.0f0) |
---|
59 | for y = (complex x 0) |
---|
60 | for z = (incf y) |
---|
61 | for x1c = (complex (1+ x) 0) |
---|
62 | unless (and (eql y z) (eql x1c y)) |
---|
63 | collect (list x y z x1c)) |
---|
64 | nil) |
---|
65 | |
---|
66 | (deftest incf.9 |
---|
67 | (let ((x most-positive-fixnum)) |
---|
68 | (values (incf x) x)) |
---|
69 | #.(1+ most-positive-fixnum) #.(1+ most-positive-fixnum)) |
---|
70 | |
---|
71 | (deftest incf.10 |
---|
72 | (let ((x (1+ most-positive-fixnum))) |
---|
73 | (values (incf x) x)) |
---|
74 | #.(+ 2 most-positive-fixnum) #.(+ 2 most-positive-fixnum)) |
---|
75 | |
---|
76 | (deftest incf.11 |
---|
77 | (loop for x in *numbers* |
---|
78 | unless (let* ((y x) |
---|
79 | (z (incf y))) |
---|
80 | (and (eql y (1+ x)) |
---|
81 | (eql y z))) |
---|
82 | collect x) |
---|
83 | nil) |
---|
84 | |
---|
85 | ;;; Increment by other than 1 |
---|
86 | |
---|
87 | (deftest incf.12 |
---|
88 | (loop for x in *numbers* |
---|
89 | unless (let* ((y x) (z (incf y 0))) |
---|
90 | (and (eql x y) (eql y z))) |
---|
91 | collect x) |
---|
92 | nil) |
---|
93 | |
---|
94 | (deftest incf.13 |
---|
95 | (loop for x in *numbers* |
---|
96 | nconc |
---|
97 | (loop for r = (random-from-interval 1000000) |
---|
98 | repeat 100 |
---|
99 | when (let* ((y x) (z (incf y r))) |
---|
100 | (and (not (and (eql (+ x r) y) (eql y z))) |
---|
101 | (list x y r))) |
---|
102 | collect it)) |
---|
103 | nil) |
---|
104 | |
---|
105 | (deftest incf.14 |
---|
106 | (let ((x 1)) |
---|
107 | (values (incf x 0.0s0) x)) |
---|
108 | 1.0s0 1.0s0) |
---|
109 | |
---|
110 | (deftest incf.15 |
---|
111 | (let ((x 1)) |
---|
112 | (values (incf x 0.0f0) x)) |
---|
113 | 1.0f0 1.0f0) |
---|
114 | |
---|
115 | (deftest incf.16 |
---|
116 | (let ((x 2)) |
---|
117 | (values (incf x 0.0d0) x)) |
---|
118 | 2.0d0 2.0d0) |
---|
119 | |
---|
120 | (deftest incf.17 |
---|
121 | (let ((x 10)) |
---|
122 | (values (incf x 0.0l0) x)) |
---|
123 | 10.0l0 10.0l0) |
---|
124 | |
---|
125 | (deftest incf.18 |
---|
126 | (let ((x 1)) |
---|
127 | (values (incf x #c(0.0s0 0.0s0)) x)) |
---|
128 | #c(1.0s0 0.0s0) #c(1.0s0 0.0s0)) |
---|
129 | |
---|
130 | (deftest incf.19 |
---|
131 | (let ((x 1)) |
---|
132 | (values (incf x #c(0.0f0 2.0f0)) x)) |
---|
133 | #c(1.0f0 2.0f0) #c(1.0f0 2.0f0)) |
---|
134 | |
---|
135 | (deftest incf.20 |
---|
136 | (let ((x 1)) |
---|
137 | (values (incf x #c(0.0d0 2.0d0)) x)) |
---|
138 | #c(1.0d0 2.0d0) #c(1.0d0 2.0d0)) |
---|
139 | |
---|
140 | (deftest incf.21 |
---|
141 | (let ((x 1)) |
---|
142 | (values (incf x #c(0.0l0 -2.0l0)) x)) |
---|
143 | #c(1.0l0 -2.0l0) #c(1.0l0 -2.0l0)) |
---|
144 | |
---|
145 | ;;; Test that explicit calls to macroexpand in subforms |
---|
146 | ;;; are done in the correct environment |
---|
147 | |
---|
148 | (deftest incf.22 |
---|
149 | (macrolet |
---|
150 | ((%m (z) z)) |
---|
151 | (let ((x 2)) |
---|
152 | (values |
---|
153 | (incf (expand-in-current-env (%m x))) |
---|
154 | x))) |
---|
155 | 3 3) |
---|
156 | |
---|
157 | (deftest incf.23 |
---|
158 | (macrolet |
---|
159 | ((%m (z) z)) |
---|
160 | (let ((x 2)) |
---|
161 | (values |
---|
162 | (incf x (expand-in-current-env (%m 4))) |
---|
163 | x))) |
---|
164 | 6 6) |
---|
165 | |
---|
166 | (deftest incf.order.2 |
---|
167 | (let ((a (vector 1 2 3 4)) |
---|
168 | (i 0) x y z) |
---|
169 | (values |
---|
170 | (incf (aref (progn (setf x (incf i)) a) |
---|
171 | (progn (setf y (incf i)) 0)) |
---|
172 | (progn (setf z (incf i)) 17)) |
---|
173 | i x y z a)) |
---|
174 | 18 3 1 2 3 #(18 2 3 4)) |
---|
175 | |
---|
176 | (deftest incf.order.3 |
---|
177 | (let ((a (vector 10 2 3 4)) |
---|
178 | (i 0) x y) |
---|
179 | (values |
---|
180 | (incf (aref (progn (setf x (incf i)) a) |
---|
181 | (progn (setf y (incf i)) 0))) |
---|
182 | i x y a)) |
---|
183 | 11 2 1 2 #(11 2 3 4)) |
---|
184 | |
---|
185 | (deftest incf.order.4 |
---|
186 | (let ((x 0)) |
---|
187 | (progn |
---|
188 | "See CLtS 5.1.3" |
---|
189 | (values |
---|
190 | (incf x (setf x 1)) |
---|
191 | x))) |
---|
192 | 2 2) |
---|
193 | |
---|