-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
72 lines (56 loc) · 923 Bytes
/
stack_test.go
File metadata and controls
72 lines (56 loc) · 923 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
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
package stack_test
import (
"github.com/mangelin/stack"
"testing"
)
func CreateTestSet() *stack.Stack {
s := new(stack.Stack)
s.Push(42)
s.Push("String")
s.Push(20.5)
return s
}
func TestStackCreate(t *testing.T) {
var s stack.Stack
for i := 0; i < 1000; i++ {
s.Push(i)
}
if s.Size() != 1000 {
t.Fail()
}
if s.Top().Value().(int) != 999 {
t.Fail()
}
}
func TestStackSize(t *testing.T) {
s := CreateTestSet()
if s.Size() != 3 {
t.Fail()
}
}
func TestStackPop(t *testing.T) {
s := CreateTestSet()
e := s.Pop()
if e.Value().(float64) != 20.5 {
t.Fail()
}
if s.Size() != 2 {
t.Fail()
}
}
func TestEmptyStack(t *testing.T) {
s := CreateTestSet()
for e := s.Pop(); e != nil; e = s.Pop() {
}
if s.Size() != 0 {
t.Fail()
}
}
func TestListCompliance(t *testing.T) {
s := CreateTestSet()
for e := s.Front(); e != nil; e = s.Next() {
}
if s.Size() != 0 {
t.Fail()
}
}