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

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

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

File size: 3.3 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Feb 11 17:33:24 2003
4;;;; Contains: Tests for AREF
5
6(in-package :cl-test)
7
8;;; AREF is also tested in many other places
9
10(deftest aref.1
11  (aref #0aT)
12  T)
13
14(deftest aref.2
15  (aref #(1 2 3 4) 2)
16  3)
17
18(deftest aref.3
19  (aref #2a((a b c d)(e f g h))  1 2)
20  g)
21
22(deftest aref.4
23  (loop for i from 0 below 6 collect (aref "abcdef" i))
24  (#\a #\b #\c #\d #\e #\f))
25
26(deftest aref.5
27  (let ((a (make-array '(2 3) :element-type 'base-char
28                       :initial-contents '("abc" "def"))))
29    (loop for i below 2
30          collect (loop for j below 3
31                        collect (aref a i j))))
32  ((#\a #\b #\c)
33   (#\d #\e #\f)))
34
35(deftest aref.6
36  (loop for i below 10 collect (aref #*1101100010 i))
37  (1 1 0 1 1 0 0 0 1 0))
38
39(deftest aref.7
40  (let ((a (make-array '(2 5) :element-type 'bit
41                       :initial-contents '((1 1 0 0 1)
42                                           (0 1 0 1 0)))))
43    (loop for i below 2
44          collect (loop for j below 5
45                        collect (aref a i j))))
46  ((1 1 0 0 1)
47   (0 1 0 1 0)))
48
49;;; Order of argument evaluation
50
51(deftest aref.order.1
52  (let ((i 0) x y (a #(a b c d)))
53    (values
54     (aref (progn (setf x (incf i)) a)
55           (progn (setf y (incf i)) 2))
56     i x y))
57  c 2 1 2)
58
59(deftest aref.order.2
60  (let ((i 0) x y z (a #2a((a b c)(d e f))))
61    (values
62     (aref (progn (setf x (incf i)) a)
63           (progn (setf y (incf i)) 1)
64           (progn (setf z (incf i)) 2))
65     i x y z))
66  f 3 1 2 3)
67
68
69;;; Setf of aref
70
71(deftest setf-aref.1
72  (let ((a (copy-seq #(1 2 3 4))))
73    (values
74     (setf (aref a 2) 'z)
75     a))
76  z
77  #(1 2 z 4))
78
79(deftest setf-aref.2
80  (let ((a (make-array nil :initial-element 1)))
81    (values
82     (setf (aref a) 'z)
83     a))
84  z #0az)
85
86(deftest setf-aref.3
87  (let ((a (make-array '(2 3) :initial-element 'a)))
88    (values
89     (setf (aref a 0 1) 'z)
90     a))
91  z
92  #2a((a z a)(a a a)))
93
94(deftest setf-aref.4
95  (let ((a (copy-seq "abcd")))
96    (values
97     (setf (aref a 0) #\z)
98     a))
99  #\z
100  "zbcd")
101
102(deftest setf-aref.5
103  (let ((a (copy-seq #*0011)))
104    (values
105     (setf (aref a 0) 1)
106     a))
107  1
108  #*1011)
109
110(deftest setf-aref.6
111  (let ((a (make-array '(2 3) :initial-element #\a :element-type 'base-char)))
112    (values
113     (setf (aref a 0 1) #\z)
114     a))
115  #\z
116  #2a((#\a #\z #\a)(#\a #\a #\a)))
117
118(deftest setf-aref.7
119  (let ((a (make-array '(2 3) :initial-element 1 :element-type 'bit)))
120    (values
121     (setf (aref a 0 1) 0)
122     a))
123  0
124  #2a((1 0 1)(1 1 1)))
125
126(deftest setf-aref.order.1
127  (let ((i 0) x y z (a (copy-seq #(a b c d))))
128    (values
129     (setf (aref (progn (setf x (incf i)) a)
130                 (progn (setf y (incf i)) 2))
131           (progn (setf z (incf i)) 'z))
132     a
133     i x y z))
134  z #(a b z d) 3 1 2 3)
135
136;;; To add: aref on displaced arrays, arrays with fill pointers, etc.
137
138(deftest aref.special-integer.1
139  (do-special-integer-vectors
140   (v #(1 1 0 1 0 1) nil)
141   (assert (= (aref v 0) 1))
142   (assert (= (aref v 1) 1))
143   (assert (= (aref v 2) 0))
144   (assert (= (aref v 3) 1))
145   (assert (= (aref v 4) 0))
146   (assert (= (aref v 5) 1)))
147  nil)
148
149(deftest aref.special-strings.1
150  (do-special-strings
151   (s "ABCDE" nil)
152   (assert (eql (aref s 0) #\A))
153   (assert (eql (aref s 1) #\B))
154   (assert (eql (aref s 2) #\C))
155   (assert (eql (aref s 3) #\D))
156   (assert (eql (aref s 4) #\E)))
157  nil)
158
159;;; Error tests
160
161(deftest aref.error.1
162  (signals-error (aref) program-error)
163  t)
164
165(deftest aref.error.2
166  (signals-error (funcall #'aref) program-error)
167  t)
168
Note: See TracBrowser for help on using the repository browser.