-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
47 lines (42 loc) · 809 Bytes
/
stack_test.go
File metadata and controls
47 lines (42 loc) · 809 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
41
42
43
44
45
46
47
package stack
import "testing"
func TestEmpty(t *testing.T) {
s := NewStack[int](10)
if !s.Empty() {
t.Errorf("wanted empty, got not empty")
}
}
func TestPush(t *testing.T) {
s := NewStack[int](2)
if !s.Empty() {
t.Errorf("wanted empty, got not empty")
}
s.Push(4)
s.Push(5)
if s.Empty() {
t.Errorf("wanted not empty, got empty")
}
}
func TestPop(t *testing.T) {
s := NewStack[int](2)
_, err := s.Pop()
if err == nil {
t.Errorf("wanted stack is empty error, got %v", err)
}
s.Push(1)
s.Push(2)
_2, err := s.Pop()
if err != nil {
t.Errorf("wanted error nil, but got %v", err)
}
if _2 != 2 {
t.Errorf("wanted 2, got %d", _2)
}
_1, _ := s.Pop()
if _1 != 1 {
t.Errorf("wanted 1, got %d", _1)
}
if !s.Empty() {
t.Errorf("wanted empty stack, got non empty stack")
}
}