-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path_bounded_stack_test.v
More file actions
72 lines (64 loc) · 1.31 KB
/
_bounded_stack_test.v
File metadata and controls
72 lines (64 loc) · 1.31 KB
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
module gui
fn test_bounded_stack_push_pop() {
mut stack := BoundedStack[int]{
max_size: 3
}
stack.push(1)
stack.push(2)
stack.push(3)
assert stack.len() == 3
assert stack.pop()? == 3
assert stack.pop()? == 2
assert stack.pop()? == 1
assert stack.is_empty()
}
fn test_bounded_stack_overflow_evicts_oldest() {
mut stack := BoundedStack[int]{
max_size: 3
}
stack.push(1)
stack.push(2)
stack.push(3)
stack.push(4) // should evict 1
assert stack.len() == 3
assert stack.pop()? == 4
assert stack.pop()? == 3
assert stack.pop()? == 2
assert stack.pop() == none
}
fn test_bounded_stack_pop_empty() {
mut stack := BoundedStack[int]{
max_size: 3
}
assert stack.pop() == none
assert stack.is_empty()
}
fn test_bounded_stack_clear() {
mut stack := BoundedStack[int]{
max_size: 3
}
stack.push(1)
stack.push(2)
stack.clear()
assert stack.is_empty()
assert stack.len() == 0
}
fn test_bounded_stack_default_size() {
stack := BoundedStack[int]{}
assert stack.max_size == 50
}
fn test_bounded_stack_many_pushes() {
mut stack := BoundedStack[int]{
max_size: 5
}
for i in 0 .. 100 {
stack.push(i)
}
// should only have last 5: 95,96,97,98,99
assert stack.len() == 5
assert stack.pop()? == 99
assert stack.pop()? == 98
assert stack.pop()? == 97
assert stack.pop()? == 96
assert stack.pop()? == 95
}