1 ;;;; common-list.test --- tests guile's common list functions -*- scheme -*-
2 ;;;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 ;;;; This program is free software; you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation; either version 2, or (at your option)
7 ;;;; any later version.
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;;; GNU General Public License for more details.
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this software; see the file COPYING. If not, write to
16 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 ;;;; Boston, MA 02111-1307 USA
19 ;;;; As a special exception, the Free Software Foundation gives permission
20 ;;;; for additional uses of the text contained in its release of GUILE.
22 ;;;; The exception is that, if you link the GUILE library with other files
23 ;;;; to produce an executable, this does not by itself cause the
24 ;;;; resulting executable to be covered by the GNU General Public License.
25 ;;;; Your use of that executable is in no way restricted on account of
26 ;;;; linking the GUILE library code into it.
28 ;;;; This exception does not however invalidate any other reasons why
29 ;;;; the executable file might be covered by the GNU General Public License.
31 ;;;; This exception applies only to the code released by the
32 ;;;; Free Software Foundation under the name GUILE. If you copy
33 ;;;; code from other Free Software Foundation releases into a copy of
34 ;;;; GUILE, as the General Public License permits, the exception does
35 ;;;; not apply to the code that you add in this way. To avoid misleading
36 ;;;; anyone as to the status of such modified files, you must delete
37 ;;;; this exception notice from them.
39 ;;;; If you write modifications of your own for GUILE, it is your choice
40 ;;;; whether to permit this exception to apply to your modifications.
41 ;;;; If you do not wish that, delete this exception notice.
43 (use-modules (ice-9 documentation)
52 (define (documented? object)
53 (not (not (object-documentation object))))
60 (with-test-prefix "intersection"
62 (pass-if "documented?"
63 (documented? intersection))
65 (pass-if "both arguments empty"
66 (eq? (intersection '() '()) '()))
68 (pass-if "first argument empty"
69 (eq? (intersection '() '(1)) '()))
71 (pass-if "second argument empty"
72 (eq? (intersection '(1) '()) '()))
74 (pass-if "disjoint arguments"
75 (eq? (intersection '(1) '(2)) '()))
77 (pass-if "equal arguments"
78 (equal? (intersection '(1) '(1)) '(1)))
80 (pass-if "reverse argument order"
81 (equal? (intersection '(1 2 3) '(3 2 1)) '(1 2 3)))
83 (pass-if "multiple matches in first list"
84 (equal? (intersection '(1 1 2 2 3) '(3 2 1)) '(1 1 2 2 3)))
86 (pass-if "multiple matches in second list"
87 (equal? (intersection '(1 2 3) '(3 3 2 2 1)) '(1 2 3)))
89 (pass-if "mixed arguments"
90 (equal? (intersection '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(1 3 7 8)))
99 (with-test-prefix "set-difference"
101 (pass-if "documented?"
102 (documented? set-difference))
104 (pass-if "both arguments empty"
105 (eq? (set-difference '() '()) '()))
107 (pass-if "first argument empty"
108 (eq? (set-difference '() '(1)) '()))
110 (pass-if "second argument empty"
111 (equal? (set-difference '(1) '()) '(1)))
113 (pass-if "disjoint arguments"
114 (equal? (set-difference '(1) '(2)) '(1)))
116 (pass-if "equal arguments"
117 (eq? (set-difference '(1) '(1)) '()))
119 (pass-if "reverse argument order"
120 (eq? (set-difference '(1 2 3) '(3 2 1)) '()))
122 (pass-if "multiple matches in first list"
123 (eq? (set-difference '(1 1 2 2 3) '(3 2 1)) '()))
125 (pass-if "multiple matches in second list"
126 (eq? (set-difference '(1 2 3) '(3 3 2 2 1)) '()))
128 (pass-if "mixed arguments"
129 (equal? (set-difference '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(2 5 10)))
138 (with-test-prefix "remove-if"
140 (pass-if "documented?"
141 (documented? remove-if))
143 (pass-if "empty list, remove all"
144 (eq? (remove-if (lambda (x) #t) '()) '()))
146 (pass-if "empty list, remove none"
147 (eq? (remove-if (lambda (x) #f) '()) '()))
149 (pass-if "non-empty list, remove all"
150 (eq? (remove-if (lambda (x) #t) '(1 2 3 4)) '()))
152 (pass-if "non-empty list, remove none"
153 (equal? (remove-if (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
155 (pass-if "non-empty list, remove some"
156 (equal? (remove-if odd? '(1 2 3 4)) '(2 4)))
166 (with-test-prefix "remove-if-not"
168 (pass-if "documented?"
169 (documented? remove-if-not))
171 (pass-if "empty list, remove all"
172 (eq? (remove-if-not (lambda (x) #f) '()) '()))
174 (pass-if "empty list, remove none"
175 (eq? (remove-if-not (lambda (x) #t) '()) '()))
177 (pass-if "non-empty list, remove all"
178 (eq? (remove-if-not (lambda (x) #f) '(1 2 3 4)) '()))
180 (pass-if "non-empty list, remove none"
181 (equal? (remove-if-not (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
183 (pass-if "non-empty list, remove some"
184 (equal? (remove-if-not odd? '(1 2 3 4)) '(1 3)))
194 (with-test-prefix "delete-if!"
196 (pass-if "documented?"
197 (documented? delete-if!))
199 (pass-if "empty list, remove all"
200 (eq? (delete-if! (lambda (x) #t) '()) '()))
202 (pass-if "empty list, remove none"
203 (eq? (delete-if! (lambda (x) #f) '()) '()))
205 (pass-if "non-empty list, remove all"
206 (eq? (delete-if! (lambda (x) #t) '(1 2 3 4)) '()))
208 (pass-if "non-empty list, remove none"
209 (equal? (delete-if! (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
211 (pass-if "non-empty list, remove some"
212 (equal? (delete-if! odd? '(1 2 3 4)) '(2 4)))
222 (with-test-prefix "delete-if-not!"
224 (pass-if "documented?"
225 (documented? delete-if-not!))
227 (pass-if "empty list, remove all"
228 (eq? (delete-if-not! (lambda (x) #f) '()) '()))
230 (pass-if "empty list, remove none"
231 (eq? (delete-if-not! (lambda (x) #t) '()) '()))
233 (pass-if "non-empty list, remove all"
234 (eq? (delete-if-not! (lambda (x) #f) '(1 2 3 4)) '()))
236 (pass-if "non-empty list, remove none"
237 (equal? (delete-if-not! (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
239 (pass-if "non-empty list, remove some"
240 (equal? (delete-if-not! odd? '(1 2 3 4)) '(1 3)))