-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-vicare.sps
169 lines (127 loc) · 2.94 KB
/
test-vicare.sps
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
;;; test-vicare.sps --- Functional Vectors: tests with Vicare Scheme
;; Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
;; Copyright (C) 2012 Ian Price <ianprice90@googlemail.com>
;; Author: Marco Maggi <marco.maggi-ipsu@poste.it>
;; This program is free software, you can redistribute it and/or
;; modify it under the terms of the new-style BSD license.
;; You should have received a copy of the BSD license along with this
;; program. If not, see <http://www.debian.org/misc/bsd.license>.
#!r6rs
(import (rnrs)
(fectors)
(vicare checks))
(check-set-mode! 'report-failed)
;;;; helpers
(define fector=?
(case-lambda
((obj1 obj2)
(fector=? obj1 obj2 eqv?))
((obj1 obj2 item=)
(and (fector? obj1)
(fector? obj2)
(or (eq? obj1 obj2)
(let ((len1 (fector-length obj1)))
(and (= len1 (fector-length obj2))
(let loop ((i 0))
(or (= i len1)
(and (item= (fector-ref obj1 i)
(fector-ref obj2 i))
(loop (+ 1 i))))))))))))
;;;; building fectors
(check
(let ((F (make-fector 5 #\a)))
(and (fector? F)
(fector->list F)))
=> '(#\a #\a #\a #\a #\a))
(check
(let ((F (fector 1 2 3)))
(and (fector? F)
(fector->list F)))
=> '(1 2 3))
(check
(let ((F (build-fector 5 (lambda (idx) (* 10 idx)))))
(and (fector? F)
(fector->list F)))
=> '(0 10 20 30 40))
;;;; inspecting
(check
(let ((F (fector)))
(fector-length F))
=> 0)
(check
(let ((F (fector 1)))
(fector-length F))
=> 1)
(check
(let ((F (fector 1 2 3)))
(fector-length F))
=> 3)
;;;; accessing and mutating
(check
(let ((F (fector 1 2 3)))
(list (fector-ref F 0)
(fector-ref F 1)
(fector-ref F 2)))
=> '(1 2 3))
(check
(let* ((F (fector 1 2 3))
(F (fector-set F 0 'a))
(F (fector-set F 1 'b))
(F (fector-set F 2 'c)))
(list (fector-ref F 0)
(fector-ref F 1)
(fector-ref F 2)))
=> '(a b c))
;;;; comparison
(check
(let ((F (fector 1 2 3))
(G (fector 1 2 3)))
(fector=? F G))
=> #t)
(check
(let ((F (fector 1 2 3))
(G (fector 10 2 3)))
(fector=? F G))
=> #f)
(check
(let ((F (fector 1 2 3))
(G (fector 1 20 3)))
(fector=? F G))
=> #f)
(check
(let ((F (fector 1 2 3))
(G (fector 1 2 30)))
(fector=? F G))
=> #f)
;;; --------------------------------------------------------------------
(check
(let ((F (fector 1 2 3))
(G (fector 1 2 3 4)))
(fector=? F G))
=> #f)
(check
(let ((F (fector 1 2 3 4))
(G (fector 1 2 3)))
(fector=? F G))
=> #f)
(check
(let ((F (fector))
(G (fector 1 2 3)))
(fector=? F G))
=> #f)
(check
(let ((F (fector 1 2 3))
(G (fector)))
(fector=? F G))
=> #f)
;;;; conversion
(check
(let ((F (fector 1 2 3)))
(fector->list F))
=> '(1 2 3))
(check
(list->fector '(1 2 3))
(=> fector=?) (fector 1 2 3))
;;;; done
(check-report)
;;; end of file