-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_test.go
79 lines (71 loc) · 1.33 KB
/
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
79
package ds
import (
_ "fmt"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_Stack(t *testing.T) {
Convey("Test Stacks", t, func() {
var a Stack_I
a = MakeStack()
So(a.Size(), ShouldEqual, 0)
a.Push(1)
So(a.Size(), ShouldEqual, 1)
So(a.Top(), ShouldEqual, 1)
a.Push(2)
So(a.Size(), ShouldEqual, 2)
So(a.Top(), ShouldEqual, 2)
a.Push(3)
So(a.Size(), ShouldEqual, 3)
So(a.Top(), ShouldEqual, 3)
a.Pop()
So(a.Size(), ShouldEqual, 2)
So(a.Top(), ShouldEqual, 2)
a.Pop()
So(a.Size(), ShouldEqual, 1)
So(a.Top(), ShouldEqual, 1)
a.Push(2)
So(a.Size(), ShouldEqual, 2)
So(a.Top(), ShouldEqual, 2)
a.Push(3)
So(a.Size(), ShouldEqual, 3)
So(a.Top(), ShouldEqual, 3)
a.Pop()
So(a.Size(), ShouldEqual, 2)
var b Stack_I
b = MakeStack()
b.Pop()
b.Pop()
b.Pop()
So(b.Size(), ShouldEqual, 0)
So(b.Top(), ShouldEqual, 0)
})
}
func BenchmarkStackPushAndPop(b *testing.B) {
var a Stack_I
a = MakeStack()
for i := 0; i < b.N; i++ {
a.Push(i)
}
for i := 0; i < b.N; i++ {
a.Pop()
}
}
func BenchmarkStackPush(b *testing.B) {
var a Stack_I
a = MakeStack()
for i := 0; i < b.N; i++ {
a.Push(i)
}
}
func BenchmarkStackPop(b *testing.B) {
var a Stack_I
a = MakeStack()
for i := 0; i < b.N; i++ {
a.Push(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.Pop()
}
}