Implement coerce extension functions for unsigned types
This commit is contained in:
@@ -10,7 +10,12 @@ sourceSets {
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jdkHome = JDK_18
|
||||
kotlinOptions {
|
||||
jdkHome = JDK_18
|
||||
freeCompilerArgs = [
|
||||
"-Xuse-experimental=kotlin.ExperimentalUnsignedTypes"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user