blob: 0f7e4c849edad3b8cb963c1b6962fc18df55b0ac (
plain)
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
|
import unittest
include ../src/stack
suite "Stack":
test "Pop":
var empty = NewStack()
check empty[].Pop() == 0
var simple = NewStack()
simple.data[0] = 1
simple.data[1] = 5
simple.height = 2
check simple[].Pop() == 5
check simple[].Pop() == 1
check simple[].Pop() == 0
test "Push":
var s = NewStack()
check s.height == 0
check s.data[0] == 0
check s.data[1] == 0
check s.data[2] == 0
s[].Push(5)
check s.height == 1
check s.data[0] == 5
check s.data[1] == 0
check s.data[2] == 0
s[].Push(-2)
check s.height == 2
check s.data[0] == 5
check s.data[1] == -2
check s.data[2] == 0
for i in 0..30:
s[].Push(i)
check s.size == 64
test "PopVector":
var empty = NewStack()
check empty[].PopVector() == (0, 0)
check empty.height == 0
var some = NewStack()
some[].Push(2)
check some[].PopVector() == (0, 2)
check some.height == 0
var full = NewStack()
full[].Push(1)
full[].Push(2)
full[].Push(3)
check full[].PopVector() == (2, 3)
check full.height == 1
test "PushVector":
var s = NewStack()
check s.height == 0
check s.data[0] == 0
check s.data[1] == 0
check s.data[2] == 0
s[].PushVector((5, -3))
check s.height == 2
check s.data[0] == 5
check s.data[1] == -3
check s.data[2] == 0
for i in 0..15:
s[].PushVector((i, i+1))
check s.size == 64
test "Clear":
var empty: Stack
empty.Clear()
check empty.height == 0
var some = NewStack()
some[].Push(1)
some[].Push(2)
some[].Clear()
check some.height == 0
test "Duplicate":
var empty = NewStack()
empty[].Duplicate()
check empty.height == 2
check empty.data[0] == 0
check empty.data[1] == 0
var some = NewStack()
some[].Push(2)
some[].Push(-4)
some[].Duplicate()
check some.height == 3
check some.data[0] == 2
check some.data[1] == -4
check some.data[2] == -4
check some.data[3] == 0
test "Swap":
var empty = NewStack()
empty[].Swap()
check empty.height == 2
check empty.data[0] == 0
check empty.data[1] == 0
var some = NewStack()
some[].Push(2)
some[].Push(-4)
some[].Push(7)
some[].Swap()
check some.height == 3
check some.data[0] == 2
check some.data[1] == 7
check some.data[2] == -4
check some.data[3] == 0
test "Transfert":
var empty = NewStack()
var empty2 = NewStack()
empty[].Transfert(empty2[], 4)
check empty.height == 4
check empty2.height == 0
check empty.data[0] == 0
check empty.data[1] == 0
check empty.data[2] == 0
check empty.data[3] == 0
empty = NewStack()
var some = NewStack()
some[].Push(2)
empty[].Transfert(some[], 3)
check empty.height == 3
check some.height == 0
check empty.data[0] == 0
check empty.data[1] == 0
check empty.data[2] == 2
empty = NewStack()
var full = NewStack()
full[].Push(1)
full[].Push(2)
full[].Push(3)
empty[].Transfert(full[], 2)
check empty.height == 2
check full.height == 1
check full.data[0] == 1
check empty.data[0] == 2
check empty.data[1] == 3
test "Next":
var empty = NewStack()
check empty[].Next() == nil
var some = NewStack(next = empty)
check some[].Next() == empty
|