-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pagination_test.go
executable file
·200 lines (196 loc) · 4.98 KB
/
Pagination_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package acccore
import (
"testing"
)
type PageTest struct {
RequestForPageNo int
RequestForItemSize int
TotalResultSet int
TotalEntries int
TotalPages int
Page int
PageSize int
NextPage int
PreviousPage int
FirstPage int
LastPage int
IsFirst bool
IsLast bool
HavePrev bool
HaveNext bool
Offset int
}
var (
testPageData = []PageTest{
{
RequestForPageNo: 0,
RequestForItemSize: 0,
TotalResultSet: 0,
TotalEntries: 0,
TotalPages: 1,
Page: 1,
PageSize: 0,
NextPage: 1,
PreviousPage: 1,
FirstPage: 1,
LastPage: 1,
IsFirst: true,
IsLast: true,
HavePrev: false,
HaveNext: false,
Offset: 0,
},
{
RequestForPageNo: 0,
RequestForItemSize: 10,
TotalResultSet: 0,
TotalEntries: 0,
TotalPages: 1,
Page: 1,
PageSize: 0,
NextPage: 1,
PreviousPage: 1,
FirstPage: 1,
LastPage: 1,
IsFirst: true,
IsLast: true,
HavePrev: false,
HaveNext: false,
Offset: 0,
},
{
RequestForPageNo: 0,
RequestForItemSize: 10,
TotalResultSet: 10,
TotalEntries: 10,
TotalPages: 1,
Page: 1,
PageSize: 10,
NextPage: 1,
PreviousPage: 1,
FirstPage: 1,
LastPage: 1,
IsFirst: true,
IsLast: true,
HavePrev: false,
HaveNext: false,
Offset: 0,
},
{
RequestForPageNo: 0,
RequestForItemSize: 10,
TotalResultSet: 15,
TotalEntries: 15,
TotalPages: 2,
Page: 1,
PageSize: 10,
NextPage: 2,
PreviousPage: 1,
FirstPage: 1,
LastPage: 2,
IsFirst: true,
IsLast: false,
HavePrev: false,
HaveNext: true,
Offset: 0,
},
{
RequestForPageNo: 1,
RequestForItemSize: 10,
TotalResultSet: 15,
TotalEntries: 15,
TotalPages: 2,
Page: 1,
PageSize: 10,
NextPage: 2,
PreviousPage: 1,
FirstPage: 1,
LastPage: 2,
IsFirst: true,
IsLast: false,
HavePrev: false,
HaveNext: true,
Offset: 0,
},
{
RequestForPageNo: 2,
RequestForItemSize: 10,
TotalResultSet: 15,
TotalEntries: 15,
TotalPages: 2,
Page: 2,
PageSize: 5,
NextPage: 2,
PreviousPage: 1,
FirstPage: 1,
LastPage: 2,
IsFirst: false,
IsLast: true,
HavePrev: true,
HaveNext: false,
Offset: 10,
},
}
)
func TestPageResultFor(t *testing.T) {
for i, tst := range testPageData {
req := PageRequest{
PageNo: tst.RequestForPageNo,
ItemSize: tst.RequestForItemSize,
Sorts: nil,
}
pr := PageResultFor(req, tst.TotalResultSet)
if pr.IsLast != tst.IsLast {
t.Errorf("#%d : Expect IsLast %v but %v", i, tst.IsLast, pr.IsLast)
t.FailNow()
}
if pr.IsFirst != tst.IsFirst {
t.Errorf("#%d : Expect IsFirst %v but %v", i, tst.IsFirst, pr.IsFirst)
t.FailNow()
}
if pr.HavePrev != tst.HavePrev {
t.Errorf("#%d : Expect HavePrev %v but %v", i, tst.HavePrev, pr.HavePrev)
t.FailNow()
}
if pr.HaveNext != tst.HaveNext {
t.Errorf("#%d : Expect HaveNext %v but %v", i, tst.HaveNext, pr.HaveNext)
t.FailNow()
}
if pr.TotalEntries != tst.TotalEntries {
t.Errorf("#%d : Expect TotalEntries %v but %v", i, tst.TotalEntries, pr.TotalEntries)
t.FailNow()
}
if pr.PageSize != tst.PageSize {
t.Errorf("#%d : Expect PageSize %v but %v", i, tst.PageSize, pr.PageSize)
t.FailNow()
}
if pr.Page != tst.Page {
t.Errorf("#%d : Expect Page %v but %v", i, tst.Page, pr.Page)
t.FailNow()
}
if pr.Offset != tst.Offset {
t.Errorf("#%d : Expect Offset %v but %v", i, tst.Offset, pr.Offset)
t.FailNow()
}
if pr.LastPage != tst.LastPage {
t.Errorf("#%d : Expect LastPage %v but %v", i, tst.LastPage, pr.LastPage)
t.FailNow()
}
if pr.FirstPage != tst.FirstPage {
t.Errorf("#%d : Expect FirstPage %v but %v", i, tst.FirstPage, pr.FirstPage)
t.FailNow()
}
if pr.NextPage != tst.NextPage {
t.Errorf("#%d : Expect NextPage %v but %v", i, tst.NextPage, pr.NextPage)
t.FailNow()
}
if pr.PreviousPage != tst.PreviousPage {
t.Errorf("#%d : Expect PreviousPage %v but %v", i, tst.PreviousPage, pr.PreviousPage)
t.FailNow()
}
if pr.TotalPages != tst.TotalPages {
t.Errorf("#%d : Expect TotalPages %v but %v", i, tst.TotalPages, pr.TotalPages)
t.FailNow()
}
}
}