1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Tue Jan 21 19:57:29 2003 |
---|
4 | ;;;; Contains: Tests for ARRAY-IN-BOUNDS-P |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (deftest array-in-bounds-p.1 |
---|
9 | (array-in-bounds-p #() 0) |
---|
10 | nil) |
---|
11 | |
---|
12 | (deftest array-in-bounds-p.2 |
---|
13 | (array-in-bounds-p #() -1) |
---|
14 | nil) |
---|
15 | |
---|
16 | (deftest array-in-bounds-p.3 |
---|
17 | (let ((a #(a b c d))) |
---|
18 | (loop for i from 0 to 4 collect (notnot (array-in-bounds-p a i)))) |
---|
19 | (t t t t nil)) |
---|
20 | |
---|
21 | (deftest array-in-bounds-p.4 |
---|
22 | (notnot (array-in-bounds-p #0aNIL)) |
---|
23 | t) |
---|
24 | |
---|
25 | (deftest array-in-bounds-p.5 |
---|
26 | (array-in-bounds-p "" 0) |
---|
27 | nil) |
---|
28 | |
---|
29 | (deftest array-in-bounds-p.6 |
---|
30 | (array-in-bounds-p "" -1) |
---|
31 | nil) |
---|
32 | |
---|
33 | (deftest array-in-bounds-p.7 |
---|
34 | (let ((a "abcd")) |
---|
35 | (loop for i from 0 to 4 collect (notnot (array-in-bounds-p a i)))) |
---|
36 | (t t t t nil)) |
---|
37 | |
---|
38 | (deftest array-in-bounds-p.8 |
---|
39 | (array-in-bounds-p #* 0) |
---|
40 | nil) |
---|
41 | |
---|
42 | (deftest array-in-bounds-p.9 |
---|
43 | (array-in-bounds-p #* -1) |
---|
44 | nil) |
---|
45 | |
---|
46 | (deftest array-in-bounds-p.10 |
---|
47 | (let ((a #*0110)) |
---|
48 | (loop for i from 0 to 4 collect (notnot (array-in-bounds-p a i)))) |
---|
49 | (t t t t nil)) |
---|
50 | |
---|
51 | ;; Fill pointer tests |
---|
52 | |
---|
53 | (deftest array-in-bounds-p.11 |
---|
54 | (let ((a (make-array '(10) :fill-pointer 5))) |
---|
55 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a i)))) |
---|
56 | (nil t t t t t t t t t t nil)) |
---|
57 | |
---|
58 | (deftest array-in-bounds-p.12 |
---|
59 | (let ((a (make-array '(10) :fill-pointer 5 :element-type 'bit :initial-element 0))) |
---|
60 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a i)))) |
---|
61 | (nil t t t t t t t t t t nil)) |
---|
62 | |
---|
63 | (deftest array-in-bounds-p.13 |
---|
64 | (let ((a (make-array '(10) :fill-pointer 5 :element-type 'base-char :initial-element #\x))) |
---|
65 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a i)))) |
---|
66 | (nil t t t t t t t t t t nil)) |
---|
67 | |
---|
68 | (deftest array-in-bounds-p.14 |
---|
69 | (let ((a (make-array '(10) :fill-pointer 5 :element-type 'character :initial-element #\x))) |
---|
70 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a i)))) |
---|
71 | (nil t t t t t t t t t t nil)) |
---|
72 | |
---|
73 | ;;; Displaced arrays |
---|
74 | |
---|
75 | (deftest array-in-bounds-p.15 |
---|
76 | (let* ((a1 (make-array '(20))) |
---|
77 | (a2 (make-array '(10) :displaced-to a1))) |
---|
78 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a2 i)))) |
---|
79 | (nil t t t t t t t t t t nil)) |
---|
80 | |
---|
81 | (deftest array-in-bounds-p.16 |
---|
82 | (let* ((a1 (make-array '(20) :element-type 'bit :initial-element 0)) |
---|
83 | (a2 (make-array '(10) :displaced-to a1 :element-type 'bit))) |
---|
84 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a2 i)))) |
---|
85 | (nil t t t t t t t t t t nil)) |
---|
86 | |
---|
87 | (deftest array-in-bounds-p.17 |
---|
88 | (let* ((a1 (make-array '(20) :element-type 'character :initial-element #\x)) |
---|
89 | (a2 (make-array '(10) :displaced-to a1 :element-type 'character))) |
---|
90 | (loop for i from -1 to 10 collect (notnot (array-in-bounds-p a2 i)))) |
---|
91 | (nil t t t t t t t t t t nil)) |
---|
92 | |
---|
93 | ;;; Multidimensional arrays |
---|
94 | |
---|
95 | (deftest array-in-bounds-p.18 |
---|
96 | (let ((a (make-array '(3 4)))) |
---|
97 | (loop for i from -1 to 3 collect |
---|
98 | (loop for j from -1 to 4 collect |
---|
99 | (notnot (array-in-bounds-p a i j))))) |
---|
100 | ((nil nil nil nil nil nil) |
---|
101 | (nil t t t t nil) |
---|
102 | (nil t t t t nil) |
---|
103 | (nil t t t t nil) |
---|
104 | (nil nil nil nil nil nil))) |
---|
105 | |
---|
106 | (deftest array-in-bounds-p.19 |
---|
107 | (let ((a (make-array '(1 3 4) :adjustable t))) |
---|
108 | (loop for i from -1 to 3 collect |
---|
109 | (loop for j from -1 to 4 collect |
---|
110 | (notnot (array-in-bounds-p a 0 i j))))) |
---|
111 | ((nil nil nil nil nil nil) |
---|
112 | (nil t t t t nil) |
---|
113 | (nil t t t t nil) |
---|
114 | (nil t t t t nil) |
---|
115 | (nil nil nil nil nil nil))) |
---|
116 | |
---|
117 | ;;; Very large indices |
---|
118 | |
---|
119 | (deftest array-in-bounds-p.20 |
---|
120 | (array-in-bounds-p #(a b c) (1+ most-positive-fixnum)) |
---|
121 | nil) |
---|
122 | |
---|
123 | (deftest array-in-bounds-p.21 |
---|
124 | (array-in-bounds-p #(a b c) (1- most-negative-fixnum)) |
---|
125 | nil) |
---|
126 | |
---|
127 | (deftest array-in-bounds-p.22 |
---|
128 | (array-in-bounds-p #(a b c) 1000000000000000000) |
---|
129 | nil) |
---|
130 | |
---|
131 | (deftest array-in-bounds-p.23 |
---|
132 | (array-in-bounds-p #(a b c) -1000000000000000000) |
---|
133 | nil) |
---|
134 | |
---|
135 | ;;; Macro expansion |
---|
136 | |
---|
137 | (deftest array-in-bounds-p.24 |
---|
138 | (macrolet ((%m (z) z)) (array-in-bounds-p (expand-in-current-env (%m #(a b))) 3)) |
---|
139 | nil) |
---|
140 | |
---|
141 | (deftest array-in-bounds-p.25 |
---|
142 | (macrolet ((%m (z) z)) |
---|
143 | (array-in-bounds-p #(a b) (expand-in-current-env (%m 2)))) |
---|
144 | nil) |
---|
145 | |
---|
146 | ;;; Order of evaluation tests |
---|
147 | |
---|
148 | (deftest array-in-bounds-p.order.1 |
---|
149 | (let ((x 0) y z) |
---|
150 | (values |
---|
151 | (array-in-bounds-p (progn (setf y (incf x)) |
---|
152 | #()) |
---|
153 | (progn (setf z (incf x)) |
---|
154 | 10)) |
---|
155 | x y z)) |
---|
156 | nil 2 1 2) |
---|
157 | |
---|
158 | ;;; Error tests |
---|
159 | |
---|
160 | (deftest array-in-bounds-p.error.1 |
---|
161 | (signals-error (array-in-bounds-p) program-error) |
---|
162 | t) |
---|