source: trunk/source/tests/ansi-tests/nreverse.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.9 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Aug 21 00:04:57 2002
4;;;; Contains: Tests for NREVERSE
5
6(in-package :cl-test)
7
8(deftest nreverse-list.1
9  (nreverse nil)
10  nil)
11
12(deftest nreverse-list.2
13  (let ((x (copy-seq '(a b c))))
14    (nreverse x))
15  (c b a))
16
17(deftest nreverse-vector.1
18  (nreverse #())
19  #())
20
21(deftest nreverse-vector.2
22  (let ((x (copy-seq #(a b c d e))))
23    (nreverse x))
24  #(e d c b a))
25
26(deftest nreverse-vector.4
27  (let ((x (make-array 0 :fill-pointer t :adjustable t)))
28    (nreverse x))
29  #())
30
31(deftest nreverse-vector.5
32  (let* ((x (make-array 5 :initial-contents '(1 2 3 4 5)
33                        :fill-pointer t :adjustable t))
34         (y (nreverse x)))
35    (values y (equalt (type-of x) (type-of y))))
36  #(5 4 3 2 1)
37  t)
38
39(deftest nreverse-vector.6
40  (let* ((x (make-array 10 :initial-contents '(1 2 3 4 5 6 7 8 9 10)
41                        :fill-pointer 5))
42         (y (nreverse x)))
43    (values y (equalt (type-of x) (type-of y))))
44  #(5 4 3 2 1)
45  t)
46
47;;; Unusual vectors
48
49(deftest nreverse-vector.7
50  (do-special-integer-vectors
51   (v #(0 0 1 0 1 1) nil)
52   (let ((nv (nreverse v)))
53     (assert (= (length nv) 6))
54     (assert (every #'= nv #(1 1 0 1 0 0)))))
55  nil)
56
57(deftest nreverse-vector.8
58  (do-special-integer-vectors
59   (v #(0 0 -1 0 -1 -1 0 -1) nil)
60   (let ((nv (nreverse v)))
61     (assert (= (length nv) 8))
62     (assert (every #'= nv #(-1 0 -1 -1 0 -1 0 0)))))
63  nil)
64
65(deftest nreverse-vector.9
66  (let ((len 10))
67    (loop for etype in '(short-float single-float double-float long-float rational)
68          for vals = (loop for i from 1 to len collect (coerce i etype))
69          for vec = (make-array len :element-type etype :initial-contents vals)
70          for nvec = (nreverse vec)
71          unless (and (eql (length nvec) len)
72                      (every #'eql (reverse vals) nvec))
73          collect (list etype vals nvec)))
74  nil)
75
76(deftest nreverse-vector.10
77  (let ((len 10))
78    (loop for cetype in '(short-float single-float double-float long-float rational integer)
79          for etype = `(complex ,cetype)
80          for vals = (loop for i from 1 to len collect (complex (coerce i cetype)
81                                                                (coerce (- i) cetype)))
82          for vec = (make-array len :element-type etype :initial-contents vals)
83          for nvec = (nreverse vec)
84          unless (and (eql (length nvec) len)
85                      (every #'eql (reverse vals) nvec))
86          collect (list etype vals nvec)))
87  nil)
88
89
90;;; Bit vectors
91
92(deftest nreverse-bit-vector.1
93  (nreverse #*)
94  #*)
95
96(deftest nreverse-bit-vector.2
97  (let ((x (copy-seq #*000110110110)))
98    (nreverse x))
99  #*011011011000)
100
101(deftest nreverse-bit-vector.3
102  (let* ((x (make-array 10 :initial-contents '(0 0 0 1 1 0 1 0 1 0)
103                        :fill-pointer 5
104                        :element-type 'bit))
105         (y (nreverse x)))
106    y)
107  #*11000)
108
109;;; Strings
110
111(deftest nreverse-string.1
112  (nreverse "")
113  "")
114
115(deftest nreverse-string.2
116  (let ((x (copy-seq "000110110110")))
117    (nreverse x))
118  "011011011000")
119
120(deftest nreverse-string.3
121  (let* ((x (make-array 10 :initial-contents "abcdefghij"
122                        :fill-pointer 5
123                        :element-type 'character))
124         (y (nreverse x)))
125    y)
126  "edcba")
127
128(deftest nreverse-string.4
129  (let* ((x (make-array 10 :initial-contents "abcdefghij"
130                        :fill-pointer 5
131                        :element-type 'base-char))
132         (y (nreverse x)))
133    y)
134  "edcba")
135
136(deftest nreverse-string.5
137  (do-special-strings
138   (s (copy-seq "12345") nil)
139   (let ((s2 (nreverse s)))
140     (assert (stringp s2))
141     (assert (string= s2 "54321"))
142     (assert (equal (array-element-type s) (array-element-type s2)))))
143  nil)
144
145;;; Argument is evaluated only once
146
147(deftest nreverse.order.1
148  (let ((i 0))
149    (values
150     (nreverse (progn (incf i) (list 'a 'b 'c 'd)))
151     i))
152  (d c b a) 1)
153
154;;; Error tests
155
156(deftest nreverse.error.1
157  (check-type-error #'nreverse #'sequencep)
158  nil)
159
160(deftest nreverse.error.6
161  (signals-error (nreverse) program-error)
162  t)
163
164(deftest nreverse.error.7
165  (signals-error (nreverse nil nil) program-error)
166  t)
167
168(deftest nreverse.error.8
169  (signals-error (locally (nreverse 'a) t) type-error)
170  t)
Note: See TracBrowser for help on using the repository browser.