MCPcopy Create free account
hub / github.com/copernet/copernicus / TestStack

Function TestStack

util/stack_test.go:30–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestStack(t *testing.T) {
31 stack := NewStack()
32 stack.Push(1)
33 stack.Push(2)
34 stack.Push(3)
35 stack.Push(4)
36 stack.Push(5)
37 stack.Push(nil)
38 length := stack.Size()
39 if length != 6 {
40 t.Errorf("get stack size failed , Got %d ,ecpected 5", length)
41 return
42 }
43
44 tmpStack := stack.Copy()
45 if !stack.Equal(tmpStack) {
46 t.Errorf("the stack should equal.")
47 }
48
49 value := stack.Pop()
50 //var nilValue interface{}
51 if reflect.TypeOf(value) != nil {
52 t.Errorf("PopStack failed ,Got %d ,expected 5", value)
53 return
54 }
55 value = stack.Pop()
56 if value.(int) != 5 {
57 t.Errorf("PopStack failed ,Got %d ,expected 5", value)
58 }
59 length = stack.Size()
60 if length != 4 {
61 t.Errorf("get stack size failed , Got %d ,ecpected 4", length)
62 }
63
64 value = stack.Pop()
65 if value.(int) != 4 {
66 t.Errorf("PopStack failed ,Got %d ,expected 4", value)
67 }
68
69 empty := stack.Empty()
70 if empty {
71 t.Errorf("stack is not empty . Got %v, expected false.", empty)
72 }
73 stack.Pop()
74 stack.Pop()
75 stack.Pop()
76 value = stack.Pop()
77 if value != nil {
78 t.Errorf("PopStack failed ,Got %d ,expected 4", value)
79 }
80
81 stack.Push(11)
82 stack.Push(22)
83
84 if ok := stack.Insert(1, 221); ok {
85 v := stack.array[1]
86 if v != 221 {
87 t.Errorf("insert failed, v is:%d", v)

Callers

nothing calls this directly

Calls 13

PushMethod · 0.95
SizeMethod · 0.95
CopyMethod · 0.95
EqualMethod · 0.95
PopMethod · 0.95
EmptyMethod · 0.95
InsertMethod · 0.95
SwapMethod · 0.95
EraseMethod · 0.95
RemoveAtMethod · 0.95
TopMethod · 0.95
SetTopMethod · 0.95

Tested by

no test coverage detected