Skip to content

Commit

Permalink
Fix test and number underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxCapacitor2 committed Jul 21, 2024
1 parent dd5e831 commit c356e35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/server/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func urlWithParam(url *url.URL, key string, value string) string {
return url.String()
}

func createPagination(url *url.URL, page uint32, pageCount uint32) []resultsPage {
func createPagination(url *url.URL, page int32, pageCount int32) []resultsPage {
pages := make([]resultsPage, 0, int(math.Min(12, float64(pageCount+4))))

if pageCount == 1 {
Expand All @@ -40,8 +40,8 @@ func createPagination(url *url.URL, page uint32, pageCount uint32) []resultsPage
})

startIndex := page - 5

endIndex := page + 5

if startIndex < 0 {
startIndex = 0
}
Expand Down
6 changes: 3 additions & 3 deletions app/server/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestPagination(t *testing.T) {
}

table := []struct {
page int
pageCount int
page int32
pageCount int32
want []resultsPage
}{
// When the cursor is at the start
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestPagination(t *testing.T) {
for i, testCase := range table {
actual := createPagination(url, testCase.page, testCase.pageCount)
if !reflect.DeepEqual(testCase.want, actual) {
t.Fatalf("test case %v failed: wanted %v, got %+v", i+1, testCase.want, actual)
t.Fatalf("test case %v failed: wanted %+v, got %+v", i+1, testCase.want, actual)
}
}
}
4 changes: 2 additions & 2 deletions app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ func renderTemplateWithResults(db database.Database, config *config.Config, req
}

ceil := math.Ceil(float64(*total) / 10.0)
pageCount := uint32(math.Min(ceil, math.MaxUint32))
pageCount := int32(math.Min(ceil, math.MaxInt32))
if pageCount < 1 {
pageCount = 1
}
pages := createPagination(req.URL, uint32(page), pageCount)
pages := createPagination(req.URL, int32(page), pageCount)

mappedResults := make([]searchResult, len(results))
for i, res := range results {
Expand Down

0 comments on commit c356e35

Please sign in to comment.