-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmiscellaneous_functions.feature
277 lines (264 loc) · 5.54 KB
/
miscellaneous_functions.feature
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
Feature: Miscellaneous functions
Scenario: Get types of values
Given a file named "main.cloe" with:
"""
(seq!
(print (typeOf true))
(print (typeOf {"key" "value"}))
(print (typeOf []))
(print (typeOf nil))
(print (typeOf 42))
(print (typeOf "foo"))
(print (typeOf +))
(print (typeOf (partial + 1))))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
boolean
dictionary
list
nil
number
string
function
function
"""
Scenario: Map a function to a list
Given a file named "main.cloe" with:
"""
(print (map (\ (x) (* x x)) [1 2 3]))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly "[1 4 9]"
Scenario: Calculate indices of elements in a list
Given a file named "main.cloe" with:
"""
(let l [1 2 3 42 -3 "foo"])
(seq!
(print (index l 42))
(print (index l 2))
(print (index l "foo")))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
4
2
6
"""
Scenario: Use multiple conditions with if function
Given a file named "main.cloe" with:
"""
(def (no) (print "No"))
(if false no true (print "Yes") false no no)
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly "Yes"
Scenario: Use boolean operators
Given a file named "main.cloe" with:
"""
(seq!
(print (not true))
(print (not false))
(print (and true))
(print (or true))
(print (and true false))
(print (or true false))
(print (and true true))
(print (or false false))
(print (and true false true))
(print (or true false true)))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
false
true
true
true
false
true
true
false
false
true
"""
Scenario: Slice lists
Given a file named "main.cloe" with:
"""
(seq!
(print (slice [1 2 3]))
(print (slice [1 2 3] . start 1))
(print (slice [1 2 3] . start 2))
(print (slice [1 2 3] . end 1))
(print (slice [1 2 3] . start 3))
(print (slice [1 2 3] . start 4))
(print (slice [1 2 3] . start 5))
(print (slice [1 2 3] . start 2 end 3))
(print (slice [1 2 3] . start 1 end 2)))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
[1 2 3]
[1 2 3]
[2 3]
[1]
[3]
[]
[]
[2 3]
[1 2]
"""
Scenario: Slice an infinite list
Given a file named "main.cloe" with:
"""
(def (f) [42 ..(f)])
(print (slice (f) . start 1 end 3))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly "[42 42 42]"
Scenario: Slice strings
Given a file named "main.cloe" with:
"""
(seq! ..(map (\ (x) (print (dump x))) [
(slice "abc")
(slice "abc" . start 1)
(slice "abc" . start 2)
(slice "abc" . end 1)
(slice "abc" . start 3)
(slice "abc" . start 4)
(slice "abc" . start 5)
(slice "abc" . start 2 end 3)
(slice "abc" . start 1 end 2)
]))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
"abc"
"abc"
"bc"
"a"
"c"
""
""
"bc"
"ab"
"""
Scenario: Calculate maximum and minimum of numbers
Given a file named "main.cloe" with:
"""
(seq!
(print (max 1))
(print (max 1 2))
(print (max 1 2 3))
(print (max 3))
(print (max 3 2))
(print (max 3 2 1))
(print (max 3 2 4 -3 123 -45 1))
(print (min 1))
(print (min 1 2))
(print (min 1 2 3))
(print (min 3))
(print (min 3 2))
(print (min 3 2 1))
(print (min 3 2 4 -3 123 -45 1)))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
1
2
3
3
3
3
123
1
1
1
3
2
1
-45
"""
Scenario: Zip lists
Given a file named "main.cloe" with:
"""
(print (zip [1 2 3] ["foo" "bar" "baz"]))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
[[1 "foo"] [2 "bar"] [3 "baz"]]
"""
Scenario: Check if values are ordered or not
Given a file named "main.cloe" with:
"""
(seq!
..(map (\ (x) (print (ordered? x))) [
123
"foo"
[]
[123]
nil
true
{}
[{}]
[123 {}]
]))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
true
true
true
true
false
false
false
false
false
"""
Scenario: Check value types
Given a file named "main.cloe" with:
"""
(seq!
..(map print [
(boolean? true)
(boolean? 42)
(dictionary? {"foo" 42})
(dictionary? "foo")
(function? (\ (x) x))
(function? [])
(list? [42 "foo"])
(list? nil)
(nil? nil)
(nil? "foo")
(number? 42)
(number? [])
(string? "foo")
(string? nil)
]))
"""
When I successfully run `cloe main.cloe`
Then the stdout should contain exactly:
"""
true
false
true
false
true
false
true
false
true
false
true
false
true
false
"""