-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
30 lines (26 loc) · 856 Bytes
/
Copy pathmain_test.go
File metadata and controls
30 lines (26 loc) · 856 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
package main
import "testing"
func TestClampPageWindow(t *testing.T) {
t.Parallel()
tests := []struct {
name string
page int
pageSize int
total int
wantFrom int
wantTo int
}{
{name: "first page", page: 1, pageSize: 2, total: 5, wantFrom: 0, wantTo: 2},
{name: "after last page", page: 10, pageSize: 2, total: 5, wantFrom: 5, wantTo: 5},
{name: "very large page", page: int(^uint(0) >> 1), pageSize: 2, total: 5, wantFrom: 5, wantTo: 5},
{name: "very large page size", page: 1, pageSize: int(^uint(0) >> 1), total: 5, wantFrom: 0, wantTo: 5},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
from, to := clampPageWindow(tt.page, tt.pageSize, tt.total)
if from != tt.wantFrom || to != tt.wantTo {
t.Fatalf("expected (%d,%d), got (%d,%d)", tt.wantFrom, tt.wantTo, from, to)
}
})
}
}