Skip to content

Commit

Permalink
Merge pull request #57 from f3l/056_showAllQuotes
Browse files Browse the repository at this point in the history
Fix pagination and add test
  • Loading branch information
pheerai authored Jan 12, 2019
2 parents 111d6bb + 17b1d9f commit ea17caa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/citesystem/server/paginationinfo.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct PaginationInfo {
@property
size_t lastPage() const {
auto numberOfFullPages = numberOfElements / pagesize;
if (numberOfFullPages % pagesize == 0) {
if (numberOfElements % pagesize != 0) {
return numberOfFullPages + 1;
} else {
return numberOfFullPages;
Expand Down
10 changes: 10 additions & 0 deletions test/citesystem/testpaginationinfo.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ private import citesystem.server.paginationinfo : PaginationInfo;
actualLastPage.shouldEqual(expectedLastPage);
}

@("Last page calculation, actual case")
@system unittest {
const testPaginationInfo = PaginationInfo(1, 10, 52);
const actualLastPage = testPaginationInfo.lastPage;
const expectedLastPage = 6;

actualLastPage.shouldEqual(expectedLastPage);
}


@("Last page calculation, harder case")
@system unittest {
const testPaginationInfo = PaginationInfo(1, 10, 105);
Expand Down

0 comments on commit ea17caa

Please sign in to comment.