Skip to content

Commit 712d21e

Browse files
committed
add test for vector
1 parent 58b6642 commit 712d21e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/lib/vector-push-pop.lsts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import LIB/default.lsts;
3+
4+
let v = mk-vector(type(String), 4);
5+
6+
print("part 0 done\n");
7+
8+
let ai = 0_u64;
9+
while ai < 128 {
10+
v = v.push(to-smart-string(ai));
11+
ai = ai + 1;
12+
};
13+
14+
print("part 1 done\n");
15+
16+
assert(v.length == 128);
17+
let last-cap = v.capacity;
18+
19+
ai = 0_u64;
20+
for x in v.iter() {
21+
assert(x == to-smart-string(ai));
22+
ai = ai + 1;
23+
};
24+
25+
print("part 2 done\n");
26+
27+
ai = 0_u64;
28+
while ai < 100 {
29+
v = v.pop().first;
30+
ai = ai + 1;
31+
};
32+
33+
print("part 3 done\n");
34+
35+
# should have shrunk from the pop() s
36+
assert(v.capacity < last-cap);
37+
last-cap = v.capacity;
38+
39+
ai = 0_u64;
40+
for x in v.iter() {
41+
assert(x == to-smart-string(ai));
42+
ai = ai + 1;
43+
};
44+
45+
print("part 4 done\n");
46+
47+

0 commit comments

Comments
 (0)