source: trunk/source/tests/ansi-tests/length.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 3.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Aug 20 23:25:29 2002
4;;;; Contains: Test cases for LENGTH
5
6(in-package :cl-test)
7
8(deftest length.list.1
9  (length nil)
10  0)
11
12(deftest length.list.2
13  (length '(a b c d e))
14  5)
15
16(deftest length.list.3
17    (length (make-list 200000))
18  200000)
19
20(defun length.list-4-body ()
21  (let ((x ()))
22    (loop
23     for i from 0 to 999 do
24     (progn
25       (unless (eql (length x) i) (return nil))
26       (push i x))
27     finally (return t))))
28
29(deftest length.list-4
30  (length.list-4-body)
31  t)
32
33(deftest length.vector.1
34  (length #())
35  0)
36
37(deftest length.vector.2
38  (length #(a))
39  1)
40
41(deftest length.vector.3
42  (length #(a b))
43  2)
44
45(deftest length.vector.4
46  (length #(a b c))
47  3)
48
49(deftest length.nonsimple-vector.1
50  (length (make-array 10 :fill-pointer t :adjustable t))
51  10)
52
53(deftest length.nonsimple-vector.2
54  (let ((a (make-array 10 :fill-pointer t :adjustable t)))
55    (setf (fill-pointer a) 5)
56    (length a))
57  5)
58
59`(deftest length.bit-vector.1
60  (length #*)
61  0)
62
63(deftest length.bit-vector.2
64  (length #*1)
65  1)
66
67(deftest length.bit-vector.3
68  (length #*0)
69  1)
70
71(deftest length.bit-vector.4
72  (length #*010101)
73  6)
74
75(deftest length.bit-vector.5
76  (let ((i 0))
77    (flet ((%f () (incf i)
78               (make-array 5 :element-type 'bit
79                           :initial-contents '(0 0 1 1 0))))
80      (values
81       (length (the (simple-bit-vector 5) (%f)))
82       i)))
83  5 1)
84
85(deftest length.string.1
86  (length "")
87  0)
88
89(deftest length.string.2
90  (length "a")
91  1)
92
93(deftest length.string.3
94  (length "abcdefghijklm")
95  13)
96
97(deftest length.string.4
98  (length "\")
99  1)
100
101(deftest length.string.5
102  (let ((i 0))
103    (flet ((%f () (incf i)
104               (make-string 5 :initial-element #\a)))
105      (values (length (the (simple-string 5) (%f))) i)))
106  5 1)
107
108(deftest length.string.6
109  (let ((i 0))
110    (flet ((%f () (incf i)
111               (make-array 5 :element-type 'base-char
112                           :initial-element #\a)))
113      (values (length (the (simple-base-string 5) (%f))) i)))
114  5 1)
115
116(deftest length.string.7
117  (do-special-strings
118   (s "12345" nil)
119   (assert (= (length s) 5)))
120  nil)
121
122(deftest length.string.8
123  (do-special-strings
124   (s "" nil)
125   (assert (= (length s) 0)))
126  nil)
127
128;;; Error cases
129
130(deftest length.error.1
131  (check-type-error #'length #'(lambda (x) (typep x 'sequence)))
132  nil)
133
134(deftest length.error.6
135  (signals-error (length) program-error)
136  t)
137
138(deftest length.error.7
139  (signals-error (length nil nil) program-error)
140  t)
141
142(deftest length.error.8
143  (signals-error (locally (length 'a) t) type-error)
144  t)
145
146;;; Length on vectors created with make-array
147
148(deftest length.array.1
149  (length (make-array '(20)))
150  20)
151
152(deftest length.array.2
153  (length (make-array '(100001)))
154  100001)
155
156(deftest length.array.3
157  (length (make-array '(0)))
158  0)
159
160(deftest length.array.4
161  (let ((x (make-array '(100) :fill-pointer 10)))
162    (length x))
163  10)
164
165(deftest length.array.5
166  (let ((x (make-array '(100) :fill-pointer 10)))
167    (setf (fill-pointer x) 20)
168    (length x))
169  20)
170
171;;; Unusual vectors
172
173(deftest length.array.6
174  (loop for i from 1 to 40
175        for etype = `(unsigned-byte ,i)
176        for vec = (make-array 7 :element-type etype :initial-element 0)
177        for len = (length vec)
178        unless (eql len 7)
179        collect (list i vec len))
180  nil)
181
182(deftest length.array.7
183  (loop for i from 1 to 40
184        for etype = `(signed-byte ,i)
185        for vec = (make-array 13 :element-type etype :initial-element 0)
186        for len = (length vec)
187        unless (eql len 13)
188        collect (list i vec len))
189  nil)
190
191(deftest length.array.8
192  (loop for etype in '(short-float single-float double-float long-float rational)
193        for vec = (make-array 5 :element-type etype :initial-element (coerce 0 etype))
194        for len = (length vec)
195        unless (eql len 5)
196        collect (list etype vec len))
197  nil)
198
199(deftest length.array.9
200  (do-special-integer-vectors
201   (v #(0 1 1 0 0 1) nil)
202   (assert (eql (length v) 6)))
203  nil)
Note: See TracBrowser for help on using the repository browser.