-
Notifications
You must be signed in to change notification settings - Fork 5
/
pushdown_stack_test.go
78 lines (63 loc) · 1.42 KB
/
pushdown_stack_test.go
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
package main
import "testing"
func TestPushdownStackPush(t *testing.T) {
stack := NewPushdownStack()
stack.Push(1324)
stack.Push(2435)
if stack.Top.Value != 2435 {
t.Error(`Expected the top of the stack to be 2435, got`, stack.Top.Value)
}
if stack.Top.Next.Value != 1324 {
t.Error(`Expected next in stack to be 1324, got,`, stack.Top.Next.Value)
}
}
func TestPushdownStackPeek(t *testing.T) {
stack := NewPushdownStack()
stack.Push(1324)
stack.Push(2435)
value := stack.Peek()
if value != 2435 {
t.Error(`Expected to peek at 2435, got`, stack.Top.Value)
}
}
func TestPushdownStackPop(t *testing.T) {
stack := NewPushdownStack()
stack.Push(1324)
stack.Push(2435)
value := stack.Pop()
if value != 2435 {
t.Error(`Expected to peek at 2435, got`, stack.Top.Value)
}
if stack.Top.Value != 1324 {
t.Error(`Expected top of stack to be 1324, got`, stack.Top.Value)
}
}
func BenchmarkPushdownStackPush(b *testing.B) {
b.StopTimer()
stack := NewPushdownStack()
b.StartTimer()
for n := 0; n < b.N; n++ {
stack.Push(n)
}
}
func BenchmarkPushdownStackPeek(b *testing.B) {
b.StopTimer()
stack := NewPushdownStack()
stack.Push(1324)
stack.Push(2435)
b.StartTimer()
for n := 0; n < b.N; n++ {
stack.Peek()
}
}
func BenchmarkPushdownStackPop(b *testing.B) {
b.StopTimer()
stack := NewPushdownStack()
for n := 0; n < b.N; n++ {
stack.Push(n)
}
b.StartTimer()
for n := 0; n < b.N; n++ {
stack.Pop()
}
}