-
Notifications
You must be signed in to change notification settings - Fork 1
/
01-basic.rakutest
232 lines (197 loc) · 9.1 KB
/
01-basic.rakutest
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
use v6.*;
use Test;
use Array::Sparse;
plan 20;
my @a is Array::Sparse = 1 .. 10;
is @a.elems, 10, 'did we get 10 elements';
is @a.end, 9, 'is index 9 the last element';
is-deeply @a.shape, (*,), 'is the shape ok';
is @a.gist, "[1 2 3 4 5 6 7 8 9 10]", 'does .gist work ok';
is @a.Str, "1 2 3 4 5 6 7 8 9 10", 'does .Str work ok';
is @a.raku, "Array::Sparse.new(1,2,3,4,5,6,7,8,9,10)", 'does .raku work ok';
subtest {
plan 10;
my int $value = 0;
is $_, ++$value, "did iteration {$value -1} produce $value"
for @a;
}, 'checking iterator';
subtest {
plan 10;
is @a[$_], $_ + 1, "did element $_ produce {$_ + 1}"
for ^10;
}, 'checking [x]';
subtest {
plan 10;
is @a[* - $_], 11 - $_, "did element * - $_ produce {11 - $_}"
for 1 .. 10;
}, 'checking [* - x]';
subtest {
plan 8;
ok @a[9]:exists, 'does last element exist';
is @a[9]:delete, 10, 'does :delete work on last element';
nok @a[9]:exists, 'does last element no longer exist';
is-deeply @a.elems, 9, 'do we have one element less now: elems';
is-deeply @a.end, 8, 'do we have one element less now: end';
is-deeply +@a, 9, 'does it numerify ok';
is-deeply @a.Int, 9, 'does it intify ok';
is-deeply ?@a, True, 'does it boolify ok';
}, 'deletion of last element';
subtest {
plan 5;
is-deeply @a[3,5,7]:exists, (True,True,True),
'can we check existence of an existing slice';
is-deeply @a[3,5,7]:delete, (4,6,8),
'can we remove an existing slice';
is-deeply @a[3,5,7]:exists, (False,False,False),
'can we check existence of an non-existing slice';
is @a.elems, 9, 'did we keep same number of elements';
is @a.end, 8, 'did we keep same last element';
}, 'can we delete a slice';
subtest {
plan 3;
is-deeply @a[^5]:v, (1,2,3,5), 'does a value slice work';
is-deeply @a[]:v, (1,2,3,5,7,9), 'does a value zen-slice work';
is-deeply @a[*]:v, (1,2,3,5,7,9), 'does a value whatever-slice work';
}, 'can we do value slices';
subtest {
plan 11;
is-deeply @a.keys, (0,1,2,4,6,8),
'does .keys work';
is-deeply @a.values, (1,2,3,5,7,9),
'does .values work';
is-deeply @a.pairs, (0=>1,1=>2,2=>3,4=>5,6=>7,8=>9),
'does .pairs work';
is-deeply @a.kv, (0,1,1,2,2,3,4,5,6,7,8,9),
'does .kv work';
is-deeply @a.head, 1, 'does .head work';
is-deeply @a.head(3), (1,2,3), 'does .head(3) work';
is-deeply @a.tail, 9, 'does .tail work';
is-deeply @a.tail(3), (5,7,9), 'does .tail(3) work';
is-deeply @a.list, List.new(1,2,3,5,7,9),
'does .list work';
is-deeply @a.List, List.new(1,2,3,5,7,9),
'does .List work';
is-deeply @a.Array, Array.new(1,2,3,5,7,9),
'does .Array work';
}, 'check iterator based methods';
subtest {
plan 14;
is-deeply @a.push(42), @a, 'did .push return self';
is @a.elems, 10, 'did we increase number of elements';
is @a.end, 9, 'did we increase the last index';
is @a[9], 42, 'did we get the right value after .push';
is-deeply @a.append(666), @a, 'did .append return self';
is @a.elems, 11, 'did we increase number of elements';
is @a.end, 10, 'did we increase the last index';
is @a[10], 666, 'did we get the right value after .append';
is @a.pop, 666, 'did .pop return right value I';
is @a.pop, 42, 'did .pop return right value II';
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
is @a[ 9], Any, 'did the elements value disappear I';
is @a[10], Any, 'did the elements value disappear II';
}, 'test .push / .append / .pop one element';
subtest {
plan 11;
is-deeply @a.push([42,666]), @a, 'did .push return self';
is @a.elems, 10, 'did we increase number of elements';
is @a.end, 9, 'did we increase the last index';
is-deeply @a[9], [42,666], 'did we get the right value after .push';
is-deeply @a.append([999,1000]), @a, 'did .append return self';
is @a.elems, 12, 'did we increase number of elements';
is @a.end, 11, 'did we increase the last index';
is @a[10], 999, 'did we get the right value after .append I';
is @a[11], 1000, 'did we get the right value after .append II';
@a.pop for ^3;
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
}, 'test .push / .append / .pop one flattenable element';
subtest {
plan 12;
is-deeply @a.push(42,666), @a, 'did .push return self';
is @a.elems, 11, 'did we increase number of elements';
is @a.end, 10, 'did we increase the last index';
is @a[ 9], 42, 'did we get the right value after .push I';
is @a[10], 666, 'did we get the right value after .push II';
is-deeply @a.append(999,1000), @a, 'did .append return self';
is @a.elems, 13, 'did we increase number of elements';
is @a.end, 12, 'did we increase the last index';
is @a[11], 999, 'did we get the right value after .append I';
is @a[12], 1000, 'did we get the right value after .append II';
@a.pop for ^4;
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
}, 'test .push / .append / .pop multiple elements';
subtest {
plan 16;
is-deeply @a.unshift(42), @a, 'did .unshift return self';
is @a.elems, 10, 'did we increase number of elements';
is @a.end, 9, 'did we increase the last index';
is @a[0], 42, 'did we get the right value after .unshift';
is-deeply @a.prepend(666), @a, 'did .prepend return self';
is @a.elems, 11, 'did we increase number of elements';
is @a.end, 10, 'did we increase the last index';
is @a[0], 666, 'did we get the right value after .prepend';
is @a.shift, 666, 'did .shift return right value I';
is @a.elems, 10, 'did we decrease number of elements';
is @a.end, 9, 'did we decrease the last index';
is @a.shift, 42, 'did .shift return right value II';
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
is @a[ 9], Any, 'did the elements value disappear I';
is @a[10], Any, 'did the elements value disappear II';
}, 'test .unshift / .prepend / .shift one element';
subtest {
plan 11;
is-deeply @a.unshift([42,666]), @a, 'did .unshift return self';
is @a.elems, 10, 'did we increase number of elements';
is @a.end, 9, 'did we increase the last index';
is-deeply @a[0], [42,666], 'did we get the right value after .unshift';
is-deeply @a.prepend([999,1000]), @a, 'did .prepend return self';
is @a.elems, 12, 'did we increase number of elements';
is @a.end, 11, 'did we increase the last index';
is @a[0], 999, 'did we get the right value after .prepend I';
is @a[1], 1000, 'did we get the right value after .prepend II';
@a.shift for ^3;
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
}, 'test .unshift / .prepend / .shift one flattenable element';
subtest {
plan 12;
is-deeply @a.unshift(42,666), @a, 'did .unshift return self';
is @a.elems, 11, 'did we increase number of elements';
is @a.end, 10, 'did we increase the last index';
is @a[0], 42, 'did we get the right value after .unshift I';
is @a[1], 666, 'did we get the right value after .unshift II';
is-deeply @a.prepend(999,1000), @a, 'did .prepend return self';
is @a.elems, 13, 'did we increase number of elements';
is @a.end, 12, 'did we increase the last index';
is @a[0], 999, 'did we get the right value after .prepend I';
is @a[1], 1000, 'did we get the right value after .prepend II';
@a.shift for ^4;
is @a.elems, 9, 'did we decrease number of elements';
is @a.end, 8, 'did we decrease the last index';
}, 'test .unshift / .append / .shift multiple elements';
subtest {
plan 35;
my @b is Array::Sparse;
is (@b[4] = 42), 42, 'does assignment pass on the value';
is-deeply @b[$_]:exists, False, "does element $_ not exist" for ^4;
is-deeply @b[$_]:exists, False, "does element $_ not exist" for 5..10;
is @b[4], 42, 'did the right value get assigned';
is @b.elems, 5, 'did we get right number of elements initially';
is @b.end, 4, 'did we get right last element initially';
is @b.shift, Any, 'did we get the right 0th element';
is @b.elems, 4, 'did we get right number of elements after shift';
is @b.end, 3, 'did we get right last element after shift';
is-deeply @b[4]:exists, False, 'did the last element disappear';
is-deeply @b[$_]:exists, False, "does element $_ still not exist" for ^3;
is @b[3], 42, 'did the right value move down one';
is-deeply @b.unshift(666), @b, 'does unshift return self';
is @b[0], 666, 'did the right value get unshifted';
is-deeply @b[$_]:exists, False, "does element $_ not exist" for 1 .. 3;
is-deeply @b[$_]:exists, False, "does element $_ not exist" for 5..10;
is @b.elems, 5, 'did we get right number of elements after unshift';
is @b.end, 4, 'did we get right last element after unshift';
}, 'test holes in arrays';
# vim: expandtab shiftwidth=4