Changed license terms to the plain LGPL thru-out.
[bpt/guile.git] / test-suite / tests / common-list.test
CommitLineData
e5d2c2fa 1;;;; common-list.test --- tests guile's common list functions -*- scheme -*-
96e30d2a 2;;;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
e5d2c2fa 3;;;;
73be1d9e
MV
4;;;; This library is free software; you can redistribute it and/or
5;;;; modify it under the terms of the GNU Lesser General Public
6;;;; License as published by the Free Software Foundation; either
7;;;; version 2.1 of the License, or (at your option) any later version.
e5d2c2fa 8;;;;
73be1d9e 9;;;; This library is distributed in the hope that it will be useful,
e5d2c2fa 10;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
11;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;;;; Lesser General Public License for more details.
e5d2c2fa 13;;;;
73be1d9e
MV
14;;;; You should have received a copy of the GNU Lesser General Public
15;;;; License along with this library; if not, write to the Free Software
16;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e5d2c2fa
DH
17
18(use-modules (ice-9 documentation)
19 (ice-9 common-list))
20
21
22;;;
23;;; miscellaneous
24;;;
25
26
27(define (documented? object)
5c96bc39 28 (not (not (object-documentation object))))
e5d2c2fa
DH
29
30
31;;;
32;;; intersection
33;;;
34
35(with-test-prefix "intersection"
36
37 (pass-if "documented?"
38 (documented? intersection))
39
40 (pass-if "both arguments empty"
41 (eq? (intersection '() '()) '()))
42
43 (pass-if "first argument empty"
44 (eq? (intersection '() '(1)) '()))
45
46 (pass-if "second argument empty"
47 (eq? (intersection '(1) '()) '()))
48
49 (pass-if "disjoint arguments"
50 (eq? (intersection '(1) '(2)) '()))
51
52 (pass-if "equal arguments"
53 (equal? (intersection '(1) '(1)) '(1)))
54
55 (pass-if "reverse argument order"
56 (equal? (intersection '(1 2 3) '(3 2 1)) '(1 2 3)))
57
58 (pass-if "multiple matches in first list"
59 (equal? (intersection '(1 1 2 2 3) '(3 2 1)) '(1 1 2 2 3)))
60
61 (pass-if "multiple matches in second list"
62 (equal? (intersection '(1 2 3) '(3 3 2 2 1)) '(1 2 3)))
63
64 (pass-if "mixed arguments"
65 (equal? (intersection '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(1 3 7 8)))
66
67 )
68
69
70;;;
71;;; set-difference
72;;;
73
74(with-test-prefix "set-difference"
75
76 (pass-if "documented?"
77 (documented? set-difference))
78
79 (pass-if "both arguments empty"
80 (eq? (set-difference '() '()) '()))
81
82 (pass-if "first argument empty"
83 (eq? (set-difference '() '(1)) '()))
84
85 (pass-if "second argument empty"
86 (equal? (set-difference '(1) '()) '(1)))
87
88 (pass-if "disjoint arguments"
89 (equal? (set-difference '(1) '(2)) '(1)))
90
91 (pass-if "equal arguments"
92 (eq? (set-difference '(1) '(1)) '()))
93
94 (pass-if "reverse argument order"
95 (eq? (set-difference '(1 2 3) '(3 2 1)) '()))
96
97 (pass-if "multiple matches in first list"
98 (eq? (set-difference '(1 1 2 2 3) '(3 2 1)) '()))
99
100 (pass-if "multiple matches in second list"
101 (eq? (set-difference '(1 2 3) '(3 3 2 2 1)) '()))
102
103 (pass-if "mixed arguments"
104 (equal? (set-difference '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(2 5 10)))
105
106 )
107
108
109;;;
110;;; remove-if
111;;;
112
113(with-test-prefix "remove-if"
114
115 (pass-if "documented?"
116 (documented? remove-if))
117
118 (pass-if "empty list, remove all"
119 (eq? (remove-if (lambda (x) #t) '()) '()))
120
121 (pass-if "empty list, remove none"
122 (eq? (remove-if (lambda (x) #f) '()) '()))
123
124 (pass-if "non-empty list, remove all"
125 (eq? (remove-if (lambda (x) #t) '(1 2 3 4)) '()))
126
127 (pass-if "non-empty list, remove none"
128 (equal? (remove-if (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
129
130 (pass-if "non-empty list, remove some"
131 (equal? (remove-if odd? '(1 2 3 4)) '(2 4)))
132
133 )
134
135
136;;;
137;;; remove-if-not
138;;;
139
140
141(with-test-prefix "remove-if-not"
142
143 (pass-if "documented?"
144 (documented? remove-if-not))
145
146 (pass-if "empty list, remove all"
147 (eq? (remove-if-not (lambda (x) #f) '()) '()))
148
149 (pass-if "empty list, remove none"
150 (eq? (remove-if-not (lambda (x) #t) '()) '()))
151
152 (pass-if "non-empty list, remove all"
153 (eq? (remove-if-not (lambda (x) #f) '(1 2 3 4)) '()))
154
155 (pass-if "non-empty list, remove none"
156 (equal? (remove-if-not (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
157
158 (pass-if "non-empty list, remove some"
159 (equal? (remove-if-not odd? '(1 2 3 4)) '(1 3)))
160
161 )
162
163
164;;;
165;;; delete-if!
166;;;
167
168
169(with-test-prefix "delete-if!"
170
171 (pass-if "documented?"
172 (documented? delete-if!))
173
174 (pass-if "empty list, remove all"
175 (eq? (delete-if! (lambda (x) #t) '()) '()))
176
177 (pass-if "empty list, remove none"
178 (eq? (delete-if! (lambda (x) #f) '()) '()))
179
180 (pass-if "non-empty list, remove all"
181 (eq? (delete-if! (lambda (x) #t) '(1 2 3 4)) '()))
182
183 (pass-if "non-empty list, remove none"
184 (equal? (delete-if! (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
185
186 (pass-if "non-empty list, remove some"
187 (equal? (delete-if! odd? '(1 2 3 4)) '(2 4)))
188
189 )
190
191
192;;;
193;;; delete-if-not!
194;;;
195
196
197(with-test-prefix "delete-if-not!"
198
199 (pass-if "documented?"
200 (documented? delete-if-not!))
201
202 (pass-if "empty list, remove all"
203 (eq? (delete-if-not! (lambda (x) #f) '()) '()))
204
205 (pass-if "empty list, remove none"
206 (eq? (delete-if-not! (lambda (x) #t) '()) '()))
207
208 (pass-if "non-empty list, remove all"
209 (eq? (delete-if-not! (lambda (x) #f) '(1 2 3 4)) '()))
210
211 (pass-if "non-empty list, remove none"
212 (equal? (delete-if-not! (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
213
214 (pass-if "non-empty list, remove some"
215 (equal? (delete-if-not! odd? '(1 2 3 4)) '(1 3)))
216
217 )