-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from InsanusMokrassar/0.20.51
0.20.51
- Loading branch information
Showing
9 changed files
with
163 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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
72 changes: 72 additions & 0 deletions
72
...on/common/src/commonTest/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationPaging.kt
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,72 @@ | ||
package dev.inmo.micro_utils.pagination.utils | ||
|
||
import dev.inmo.micro_utils.pagination.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class PaginationPaging { | ||
@Test | ||
fun testPaginateOnList() { | ||
val list = (0 until 7).toList() | ||
val startPagination = FirstPagePagination(2) | ||
|
||
var lastPageHappened = false | ||
doForAllWithNextPaging(startPagination) { | ||
val result = list.paginate(it) | ||
|
||
if (result.isLastPage) { | ||
lastPageHappened = true | ||
assertTrue(result.results.size == 1) | ||
} | ||
|
||
val testSublist = list.subList(it.firstIndex, minOf(it.lastIndexExclusive, list.size)) | ||
assertEquals(result.results, testSublist) | ||
|
||
result | ||
} | ||
|
||
assertTrue(lastPageHappened) | ||
} | ||
@Test | ||
fun testEmptyPaginateOnList() { | ||
val list = listOf<Int>() | ||
val startPagination = FirstPagePagination(2) | ||
|
||
var paginationHappend = false | ||
doForAllWithNextPaging(startPagination) { | ||
val resultPagination = list.paginate(it) | ||
|
||
assertEquals(resultPagination, emptyPaginationResult(it, list.size)) | ||
|
||
assertFalse(paginationHappend) | ||
|
||
paginationHappend = true | ||
|
||
resultPagination | ||
} | ||
|
||
assertTrue(paginationHappend) | ||
} | ||
@Test | ||
fun testRightOutPaginateOnList() { | ||
val list = (0 until 7).toList() | ||
val startPagination = SimplePagination(page = 4, size = 2) | ||
|
||
var paginationHappend = false | ||
doForAllWithNextPaging(startPagination) { | ||
val resultPagination = list.paginate(it) | ||
|
||
assertEquals(resultPagination, emptyPaginationResult(it, list.size)) | ||
|
||
assertFalse(paginationHappend) | ||
|
||
paginationHappend = true | ||
|
||
resultPagination | ||
} | ||
|
||
assertTrue(paginationHappend) | ||
} | ||
} |