Implement coerce extension functions for unsigned types

This commit is contained in:
Abduqodiri Qurbonzoda
2019-03-12 21:37:32 +03:00
parent a369496aca
commit 35c6f09886
5 changed files with 297 additions and 34 deletions
@@ -28,6 +28,12 @@ class ComparableOps {
assertPrints(10.coerceAtLeast(20), "20")
}
@Sample
fun coerceAtLeastUnsigned() {
assertPrints(10u.coerceAtLeast(5u), "10")
assertPrints(10u.coerceAtLeast(20u), "20")
}
@Sample
fun coerceAtLeastComparable() {
assertPrints(DayOfWeek.WEDNESDAY.coerceAtLeast(DayOfWeek.MONDAY), "WEDNESDAY")
@@ -40,6 +46,11 @@ class ComparableOps {
assertPrints(10.coerceAtMost(20), "10")
}
@Sample
fun coerceAtMostUnsigned() {
assertPrints(10u.coerceAtMost(5u), "5")
assertPrints(10u.coerceAtMost(20u), "10")
}
@Sample
fun coerceAtMostComparable() {
@@ -58,6 +69,17 @@ class ComparableOps {
}
}
@Sample
fun coerceInUnsigned() {
assertPrints(10u.coerceIn(1u, 100u), "10")
assertPrints(10u.coerceIn(1u..100u), "10")
assertPrints(0u.coerceIn(1u, 100u), "1")
assertPrints(500u.coerceIn(1u, 100u), "100")
assertFailsWith<IllegalArgumentException> {
10u.coerceIn(100u, 0u)
}
}
@Sample
fun coerceInComparable() {
val workingDays = DayOfWeek.MONDAY..DayOfWeek.FRIDAY