-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_stack_test.go
73 lines (71 loc) · 1.5 KB
/
session_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package transaction_manager
import (
. "github.com/xormplus/xorm"
"testing"
)
func TestStackIsEmpty(t *testing.T) {
stack := NewSessionStack()
stack.Push(new(Session))
if stack.IsEmpty() {
t.Errorf("the size of stack should be one")
}
stack.Pop()
if !stack.IsEmpty() {
t.Errorf("the size of stack should be zero")
}
}
func TestStackPop(t *testing.T) {
stack := NewSessionStack()
for i := 0; i < 10; i++ {
stack.Push(new(Session))
}
for i := 0; i < 10; i++ {
stack.Pop()
}
if _, ok := stack.Pop(); ok {
t.Errorf("stack pop function should return false")
}
}
func TestStackEqual(t *testing.T) {
stack := NewSessionStack()
session := new(Session)
stack.Push(session)
sourceSession, _ := stack.Pop()
if session != sourceSession {
t.Errorf("session should be equal")
}
}
func TestStackSize(t *testing.T) {
stack := NewSessionStack()
size := 10
for i := 0; i < size; i++ {
stack.Push(new(Session))
}
if stack.Size() != size {
t.Errorf("the size of stack should be equal")
}
}
func TestStackTop(t *testing.T) {
stack := NewSessionStack()
if _, ok := stack.Top(); ok {
t.Errorf("top should return false")
}
for i := 0; i < 10; i++ {
stack.Push(new(Session))
}
s := new(Session)
stack.Push(s)
if sourceSession, _ := stack.Top(); sourceSession != s {
t.Errorf("session should be equal")
}
}
func TestStackPush(t *testing.T) {
stack := NewSessionStack()
size := 20
for i := 0; i < size; i++ {
stack.Push(new(Session))
if stack.Size() != i+1 {
t.Errorf("push func error")
}
}
}