-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArray.pi
More file actions
40 lines (28 loc) · 704 Bytes
/
Array.pi
File metadata and controls
40 lines (28 loc) · 704 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
// Start with a clean state
clear
// Test empty array
depth toarray [] == assert
// Test single element array
1 depth toarray [1] == assert
// Test multiple element array
1 2 3 depth toarray [1 2 3] == assert
// Clean up before next test
clear
// expand the array, leaving the size of the expanded array on the stack
[11 22 33] expand 3 == assert
depth 3 == assert
3 toarray [11 22 33] == assert
clear
depth 0 == assert
// Test complex array manipulation
1 2 3 4
2 toarray // stack: 1 2 [3 4]
rot // stack: 2 [3 4] 1
rot // stack: [3 4] 1 2
2 toarray // stack: [3 4] [1 2]
[1 2] == assert
[3 4] == assert
// Verify stack is empty at the end
depth 0 == assert
// Clean up at the end
clear