-
Notifications
You must be signed in to change notification settings - Fork 5
/
paging_test.go
105 lines (81 loc) · 2.07 KB
/
paging_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
package main
import (
"testing"
)
func TestPaginationSet(t *testing.T) {
pagination := PageninationWithState("30,3")
if pagination.PageSize != 3 {
t.Error("Expected 3, got ", t)
}
if pagination.PageNumber != 30 {
t.Error("Expected 30, got ", t)
}
}
func TestPaginationValidation(t *testing.T) {
pagination := PageninationWithState("31,3")
listSize := 91
valid := pagination.ValidatePagination(listSize)
if valid != 0 {
t.Error("Expected 0, got ", valid)
}
startIdx, endIdx := pagination.CalculateStartEndIndex(listSize)
if startIdx != 90 {
t.Error("Expected 90, got ", startIdx)
}
if endIdx != 91 {
t.Error("Expected 91, got ", endIdx)
}
}
func TestPaginationValidationFail(t *testing.T) {
pagination := PageninationWithState("32,3")
listSize := 91
valid := pagination.ValidatePagination(listSize)
if valid == 0 {
t.Error("Expected 0, got ", valid)
}
}
func TestPaginationValidation1(t *testing.T) {
pagination := PageninationWithState("1,6")
listSize := 6
valid := pagination.ValidatePagination(listSize)
if valid != 0 {
t.Error("Expected 0, got ", valid)
}
startIdx, endIdx := pagination.CalculateStartEndIndex(listSize)
if startIdx != 0 {
t.Error("Expected 0, got ", startIdx)
}
if endIdx != 6 {
t.Error("Expected 6, got ", endIdx)
}
}
func TestPaginationLastSite(t *testing.T) {
pagination := PageninationWithState("30,3")
listSize := 90
valid := pagination.ValidatePagination(listSize)
if valid != 0 {
t.Error("Expected 0, got ", valid)
}
startIdx, endIdx := pagination.CalculateStartEndIndex(listSize)
if startIdx != 87 {
t.Error("Expected 87, got ", startIdx)
}
if endIdx != 90 {
t.Error("Expected 90, got ", endIdx)
}
}
func TestPaginationFirstSite(t *testing.T) {
pagination := PageninationWithState("1,3")
listSize := 266
valid := pagination.ValidatePagination(listSize)
if valid != 0 {
t.Error("Expected 0, got ", valid)
}
startIdx, endIdx := pagination.CalculateStartEndIndex(listSize)
if startIdx != 0 {
t.Error("Expected 0, got ", startIdx)
}
if endIdx != 3 {
t.Error("Expected 3, got ", endIdx)
}
}