-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f53751
commit 11fca8b
Showing
5 changed files
with
188 additions
and
144 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pagorminator | ||
|
||
import "testing" | ||
|
||
func TestPagination_UnPaged(t *testing.T) { | ||
t.Parallel() | ||
tests := map[string]struct { | ||
page int | ||
size int | ||
expected bool | ||
}{ | ||
"page 0 size 0": { | ||
page: 0, | ||
size: 0, | ||
expected: true, | ||
}, | ||
"page zero size not zero": { | ||
page: 0, | ||
size: 1, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
page, err := PageRequest(test.page, test.size) | ||
if err != nil { | ||
t.Errorf("Unexpected error: %s", err) | ||
} | ||
if page.IsUnPaged() != test.expected { | ||
t.Errorf("IsUnPaged() expected %v, got %v", test.expected, page.IsUnPaged()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPagination_CalculateTotalPages(t *testing.T) { | ||
t.Parallel() | ||
tests := map[string]struct { | ||
totalElements int64 | ||
size int | ||
expected int | ||
}{ | ||
"totalElements lower than size": { | ||
totalElements: 2, | ||
size: 4, | ||
expected: 1, | ||
}, | ||
"totalElements greater and not divisible by size": { | ||
totalElements: 3, | ||
size: 2, | ||
expected: 2, | ||
}, | ||
"totalElements greater and divisible by size": { | ||
totalElements: 4, | ||
size: 2, | ||
expected: 2, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
actual := calculateTotalPages(test.totalElements, test.size) | ||
if actual != test.expected { | ||
t.Errorf("totalPages expected %v, got %v", test.expected, actual) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.