-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_test.go
55 lines (40 loc) · 1 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
package collections
import "testing"
func TestStack(t *testing.T) {
var s Stack
if s.Size() != 0 {
t.Errorf("Length of stack should be 0, but got %d", s.Size())
}
s.Push(1)
if s.Size() != 1 {
t.Errorf("Length of stack should be 1, but got %d", s.Size())
}
if s.Peek() != 1 {
t.Errorf("Peek should return 1, but got %d", s.Peek())
}
s.Push(2)
if s.Size() != 2 {
t.Errorf("Length of stack should be 2, but got %d", s.Size())
}
if s.Peek() != 2 {
t.Errorf("Peek should return 2, but got %d", s.Peek())
}
if s.Pop() != 2 {
t.Errorf("Pop should return 2, but got %d", s.Pop())
}
if s.Size() != 1 {
t.Errorf("Length of stack should be 1, but got %d", s.Size())
}
if s.Peek() != 1 {
t.Errorf("Peek should return 1, but got %d", s.Peek())
}
if s.Pop() != 1 {
t.Errorf("Pop should return 1, but got %d", s.Pop())
}
if s.Size() != 0 {
t.Errorf("Length of stack should be 0, but got %d", s.Size())
}
if !s.IsEmpty() {
t.Errorf("Stack should be empty, but got %d", s.Size())
}
}