(delete, delete!): Test predicate call arg order.
[bpt/guile.git] / test-suite / tests / srfi-1.test
CommitLineData
91e7199f
KR
1;;;; srfi-1.test --- Test suite for Guile's SRFI-1 functions. -*- scheme -*-
2;;;;
3;;;; Copyright 2003 Free Software Foundation, Inc.
4;;;;
5;;;; This program is free software; you can redistribute it and/or modify
6;;;; it under the terms of the GNU General Public License as published by
7;;;; the Free Software Foundation; either version 2, or (at your option)
8;;;; any later version.
9;;;;
10;;;; This program is distributed in the hope that it will be useful,
11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13;;;; GNU General Public License for more details.
14;;;;
15;;;; You should have received a copy of the GNU General Public License
16;;;; along with this software; see the file COPYING. If not, write to
17;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18;;;; Boston, MA 02111-1307 USA
19
20(use-modules (srfi srfi-1)
21 (test-suite lib))
22
23
8ec84fe5
KR
24;;
25;; delete and delete!
26;;
27
28(let ()
29 (define (common-tests delete-proc)
30 (pass-if "called arg order"
31 (equal? '(1 2 3)
32 (delete-proc 3 '(1 2 3 4 5) <))))
33
34 (with-test-prefix "delete"
35 (common-tests delete))
36
37 (with-test-prefix "delete!"
38 (common-tests delete!)))
39
91e7199f
KR
40;;
41;; drop
42;;
43
44(with-test-prefix "drop"
45
46 (pass-if "'() 0"
47 (null? (drop '() 0)))
48
49 (pass-if "'(a) 0"
50 (let ((lst '(a)))
51 (eq? lst
52 (drop lst 0))))
53
54 (pass-if "'(a b) 0"
55 (let ((lst '(a b)))
56 (eq? lst
57 (drop lst 0))))
58
59 (pass-if "'(a) 1"
60 (let ((lst '(a)))
61 (eq? (cdr lst)
62 (drop lst 1))))
63
64 (pass-if "'(a b) 1"
65 (let ((lst '(a b)))
66 (eq? (cdr lst)
67 (drop lst 1))))
68
69 (pass-if "'(a b) 2"
70 (let ((lst '(a b)))
71 (eq? (cddr lst)
72 (drop lst 2))))
73
74 (pass-if "'(a b c) 1"
75 (let ((lst '(a b c)))
76 (eq? (cddr lst)
77 (drop lst 2))))
78
79 (pass-if "circular '(a) 0"
80 (let ((lst (circular-list 'a)))
81 (eq? lst
82 (drop lst 0))))
83
84 (pass-if "circular '(a) 1"
85 (let ((lst (circular-list 'a)))
86 (eq? lst
87 (drop lst 1))))
88
89 (pass-if "circular '(a) 2"
90 (let ((lst (circular-list 'a)))
91 (eq? lst
92 (drop lst 1))))
93
94 (pass-if "circular '(a b) 1"
95 (let ((lst (circular-list 'a)))
96 (eq? (cdr lst)
97 (drop lst 0))))
98
99 (pass-if "circular '(a b) 2"
100 (let ((lst (circular-list 'a)))
101 (eq? lst
102 (drop lst 1))))
103
104 (pass-if "circular '(a b) 5"
105 (let ((lst (circular-list 'a)))
106 (eq? (cdr lst)
107 (drop lst 5))))
108
109 (pass-if "'(a . b) 1"
110 (eq? 'b
111 (drop '(a . b) 1)))
112
113 (pass-if "'(a b . c) 1"
114 (equal? 'c
115 (drop '(a b . c) 2))))
116
117;;
118;; take
119;;
120
121(with-test-prefix "take"
122
123 (pass-if "'() 0"
124 (null? (take '() 0)))
125
126 (pass-if "'(a) 0"
127 (null? (take '(a) 0)))
128
129 (pass-if "'(a b) 0"
130 (null? (take '() 0)))
131
132 (pass-if "'(a b c) 0"
133 (null? (take '() 0)))
134
135 (pass-if "'(a) 1"
136 (let* ((lst '(a))
137 (got (take lst 1)))
138 (and (equal? '(a) got)
139 (not (eq? lst got)))))
140
141 (pass-if "'(a b) 1"
142 (equal? '(a)
143 (take '(a b) 1)))
144
145 (pass-if "'(a b c) 1"
146 (equal? '(a)
147 (take '(a b c) 1)))
148
149 (pass-if "'(a b) 2"
150 (let* ((lst '(a b))
151 (got (take lst 2)))
152 (and (equal? '(a b) got)
153 (not (eq? lst got)))))
154
155 (pass-if "'(a b c) 2"
156 (equal? '(a b)
157 (take '(a b c) 2)))
158
159 (pass-if "circular '(a) 0"
160 (equal? '()
161 (take (circular-list 'a) 0)))
162
163 (pass-if "circular '(a) 1"
164 (equal? '(a)
165 (take (circular-list 'a) 1)))
166
167 (pass-if "circular '(a) 2"
168 (equal? '(a a)
169 (take (circular-list 'a) 2)))
170
171 (pass-if "circular '(a b) 5"
172 (equal? '(a b a b a)
173 (take (circular-list 'a 'b) 5)))
174
175 (pass-if "'(a . b) 1"
176 (equal? '(a)
177 (take '(a . b) 1)))
178
179 (pass-if "'(a b . c) 1"
180 (equal? '(a)
181 (take '(a b . c) 1)))
182
183 (pass-if "'(a b . c) 2"
184 (equal? '(a b)
185 (take '(a b . c) 2))))