File: equalp.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (306 lines) | stat: -rw-r--r-- 7,153 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Oct 17 22:14:42 2002
;;;; Contains: Tests for EQUALP

(in-package :cl-test)

(compile-and-load "random-aux.lsp")

(deftest equalp.1
  (loop for c across +base-chars+
	always (loop for d across +base-chars+
		     always (if (char-equal c d) (equalpt c d)
			      (not (equalpt c d)))))
  t)

(deftest equalp.2
  (loop for i from 1 to 100
	always (loop for j from 1 to 100
		     always (if (eqlt i j) (equalpt i j)
			      (not (equalpt i j)))))
  t)

(deftest equalp.3
  (equalpt "abc" "ABC")
  t)

(deftest equalp.4
  (equalpt "abc" "abd")
  nil)

(deftest equalp.5
  :notes (:allow-nil-arrays)
  (equalpt (make-array '(0) :element-type nil) #())
  t)

(deftest equalp.6
  :notes (:allow-nil-arrays)
  (equalpt (make-array '(0) :element-type nil) "")
  t)

(deftest equalp.7
  (loop for nbits from 1 to 100
	for type = `(unsigned-byte ,nbits)
	for bound = (ash 1 nbits)
	for val = (random bound)
	for a1 = (make-array nil :initial-element val :element-type type)
	for a2 = (make-array nil :initial-element val)
	unless (equalp a1 a2)
	collect (list nbits type val))
  nil)

(deftest equalp.8
  (loop for nbits from 1 to 100
	for type = `(unsigned-byte ,nbits)
	for bound = (ash 1 nbits)
	for n = (1+ (random 20))
	for vals = (loop repeat n collect (random bound))
	for a1 = (make-array n :initial-contents vals :element-type type)
	for a2 = (make-array n :initial-contents vals)
	unless (equalp a1 a2)
	collect (list nbits type vals))
  nil)

(deftest equalp.9
  (loop for nbits from 1 to 100
	for type = `(signed-byte ,nbits)
	for bound = (ash 1 nbits)
	for n = (1+ (random 20))
	for vals = (loop repeat n collect (- (random bound) (/ bound 2)))
	for a1 = (make-array n :initial-contents vals :element-type type)
	for a2 = (make-array n :initial-contents vals)
	unless (equalp a1 a2)
	collect (list nbits type vals))
  nil)

(deftest equalp.10
  (equalpt #*0010 #(0 0 1 0))
  t)

(deftest equalp.11
  (let ((v1 #(1 2 3))
	(v2 (make-array 8 :initial-contents '(1 2 3 4 5 6 7 8)
			:fill-pointer 3)))
    (equalpt v1 v2))
  t)

(deftest equalp.12
  (equalpt '(#\a #\b) "ab")
  nil)

(deftest equalp.13
  (equalpt '(#\a #\b) '(#\A #\B))
  t)

(deftest equalp.14
  (let ((s1 (make-array '(4) :initial-contents '(#\a #\b #\c #\d)
			:element-type 'base-char))
	(s2 (make-array '(4) :initial-contents '(#\a #\b #\c #\d)
			:element-type 'character)))
    (equalpt s1 s2))
  t)

(deftest equalp.15
  (let ((bv (make-array '(4) :initial-contents '(0 0 1 0)
			:element-type 'bit))
	(v #(0 0 1 0)))
    (equalpt bv v))
  t)

(defstruct equalp-struct-16
  a b c)

(defstruct equalp-struct-16-alt
  a b c)

(deftest equalp.16
  (let ((s1 (make-equalp-struct-16 :a 1 :b 2 :c #\a))
	(s2 (make-equalp-struct-16 :a 1.0 :b 2.0 :c #\A))
	(s3 (make-equalp-struct-16-alt :a 1.0 :b 2.0 :c #\A)))
    (values (equalpt s1 s2)
	    (equalpt s1 s3)
	    (equalpt s2 s3)))
  t nil nil)

(deftest equalp.17
  (loop for i below 8192
	for f = (float i 1.0s0)
	repeat 1000
	unless (equalp i f)
	collect (list i f))
  nil)

(deftest equalp.18
  (loop for i = (- (random 10000000) 5000000)
	for f = (float i 1.0f0)
	repeat 1000
	unless (equalp i f)
	collect (list i f))
  nil)

(deftest equalp.19
  (loop for i = (- (random 10000000) 5000000)
	for f = (float i 1.0d0)
	repeat 1000
	unless (equalp i f)
	collect (list i f))
  nil)

(deftest equalp.20
  (loop for i = (- (random 10000000) 5000000)
	for f = (float i 1.0l0)
	repeat 1000
	unless (equalp i f)
	collect (list i f))
  nil)

(deftest equalp.21
  (let ((ht1 (make-hash-table :test #'eq))
	(ht2 (make-hash-table :test #'eql))
	(ht3 (make-hash-table :test #'equal))
	(ht4 (make-hash-table :test #'equalp)))
    (values (equalpt ht1 ht2)
	    (equalpt ht1 ht3)
	    (equalpt ht1 ht4)
	    (equalpt ht2 ht3)
	    (equalpt ht2 ht4)
	    (equalpt ht3 ht4)))
  nil nil nil nil nil nil)

(deftest equalp.22
  (equalpt (make-hash-table :test 'eq)
	   (make-hash-table :test #'eq))
  t)

(deftest equalp.23
  (equalpt (make-hash-table :test 'eql)
	   (make-hash-table :test #'eql))
  t)

(deftest equalp.24
  (equalpt (make-hash-table :test 'equal)
	   (make-hash-table :test #'equal))
  t)

(deftest equalp.25
  (equalpt (make-hash-table :test 'equalp)
	   (make-hash-table :test #'equalp))
  t)

(deftest equalp.26
  (let ((ht1 (make-hash-table :test #'eq))
	(ht2 (make-hash-table :test #'eq)))
    (setf (gethash #\a ht1) t)
    (setf (gethash #\A ht2) t)
    (equalpt ht1 ht2))
  nil)

(deftest equalp.27
  (let ((ht1 (make-hash-table :test #'eq))
	(ht2 (make-hash-table :test #'eq)))
    (setf (gethash 'a ht1) #\a)
    (setf (gethash 'a ht2) #\A)
    (equalpt ht1 ht2))
  t)

(deftest equalp.28
  (let ((ht1 (make-hash-table :test #'eql))
	(ht2 (make-hash-table :test #'eql)))
    (setf (gethash #\a ht1) t)
    (setf (gethash #\A ht2) t)
    (equalpt ht1 ht2))
  nil)

(deftest equalp.29
  (let ((ht1 (make-hash-table :test #'eql))
	(ht2 (make-hash-table :test #'eql)))
    (setf (gethash #\a ht1) "a")
    (setf (gethash #\a ht2) "A")
    (equalpt ht1 ht2))
  t)

(deftest equalp.30
  (let ((ht1 (make-hash-table :test #'equal))
	(ht2 (make-hash-table :test #'equal)))
    (setf (gethash #\a ht1) t)
    (setf (gethash #\A ht2) t)
    (equalpt ht1 ht2))
  nil)

(deftest equalp.31
  (let ((ht1 (make-hash-table :test #'equal))
	(ht2 (make-hash-table :test #'equal)))
    (setf (gethash #\a ht1) "a")
    (setf (gethash #\a ht2) "A")
    (equalpt ht1 ht2))
  t)

(deftest equalp.32
  (let ((ht1 (make-hash-table :test #'equalp))
	(ht2 (make-hash-table :test #'equalp)))
    (setf (gethash #\a ht1) t)
    (setf (gethash #\A ht2) t)
    (equalpt ht1 ht2))
  t)

(deftest equalp.33
  (let ((ht1 (make-hash-table :test #'equalp))
	(ht2 (make-hash-table :test #'equalp)))
    (setf (gethash #\a ht1) "a")
    (setf (gethash #\a ht2) "A")
    (equalpt ht1 ht2))
  t)

(deftest equalp.34
  (let ((ht1 (make-hash-table :test #'equalp))
	(ht2 (make-hash-table :test #'equalp)))
    (setf (gethash '#:a ht1) t)
    (setf (gethash '#:a ht2) t)
    (equalpt ht1 ht2))
  nil)

(deftest equalp.35
  (loop for test in '(eq eql equal equalp)
	collect
	(flet ((%make-table
		()
		(apply #'make-hash-table
		       :test test
		       `(,@(when (coin)
			     (list :size (random 100)))
			   ,@(when (coin)
			       (list :rehash-size (1+ (random 50))))
			   ,@(when (coin)
			       (list :rehash-threshold (random 1.0)) )))))
	  (loop repeat 200
		count
		(let ((ht1 (%make-table))
		      (ht2 (%make-table))
		      (pairs (loop for i below (random 100) collect (cons (gensym) i))))
		  (loop for (k . v) in pairs do (setf (gethash k ht1) v))
		  (setf pairs (random-permute pairs))
		  (loop for (k . v) in pairs do (setf (gethash k ht2) v))
		  (not (equalp ht1 ht2))))))
  (0 0 0 0))

(deftest equalp.order.1
  (let ((i 0) x y)
    (values
     (equalp (setf x (incf i)) (setf y (incf i)))
     i x y))
  nil 2 1 2)

;;; Error tests

(deftest equalp.error.1
  (signals-error (equalp) program-error)
  t)

(deftest equalp.error.2
  (signals-error (equalp nil) program-error)
  t)

(deftest equalp.error.3
  (signals-error (equalp nil nil nil) program-error)
  t)