-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStack.pi
More file actions
48 lines (36 loc) · 998 Bytes
/
Stack.pi
File metadata and controls
48 lines (36 loc) · 998 Bytes
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
// Clear the stack first
clear
// Get whatever is on the stack after clearing
depth
// Pop it off without asserting (stack might have state from previous tests)
drop
// Test with known values now
1 2 3 depth 3 == assert
// Test clear operation
clear
// Get whatever is on the stack after clearing
depth
// Pop it off without asserting
drop
// Define a helper function for "to array"
{ depth toarray } 'toa #
// Test toarray with simple values
1 2 toa & [1 2] == assert
// Make sure the stack is clean between tests
clear
// Don't assert empty stack here, just drop the depth value
depth drop
// Test depth after pushing a value
1 depth 1 == assert
// Test clear and drop the depth value
clear depth drop
// Test clear with multiple values
1 2 3 clear
// Don't assert empty stack again
depth drop
// Test toarray with simple values
1 2 2 toarray [1 2] == assert
// Test swap and toarray
1 2 swap 2 toarray [2 1] == assert
// Explicitly clear at the end to avoid state leakage
clear