-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_test.go
57 lines (44 loc) · 866 Bytes
/
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
package chipeight
import (
"reflect"
"testing"
)
func TestStack_Push(t *testing.T) {
s := Stack{}
s.Push(0)
s.Push(1)
s.Push(2)
want := []interface{}{0, 1, 2}
if !reflect.DeepEqual(s.elements, want) {
t.Errorf("Expected %v but got %v", want, s.elements)
}
}
func TestStack_Pop(t *testing.T) {
s := Stack{}
s.Push(0)
s.Push(1)
s.Push(2)
s.Pop()
want := []interface{}{0, 1}
if !reflect.DeepEqual(s.elements, want) {
t.Errorf("Expected %v but got %v", want, s.elements)
}
}
func TestStack_PopEmpty(t *testing.T) {
s := Stack{}
s.Pop()
}
func TestStack_Top(t *testing.T) {
s := Stack{}
s.Push(0)
s.Push(1)
if value, _ := s.Top(); value != 1 {
t.Errorf("Expected 1 but got %v", value)
}
}
func TestStack_TopEmpty(t *testing.T) {
s := Stack{}
if _, err := s.Top(); err == nil {
t.Errorf("expected error but it was nil")
}
}