-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
dachlatten-primitives/src/main/kotlin/de/sipgate/dachlatten/primitives/EnumExt.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,5 @@ | ||
package de.sipgate.dachlatten.primitives | ||
|
||
inline fun <reified T : Enum<T>> T.isAnyOf(vararg values: T) = values.any { this == it } | ||
|
||
inline fun <reified T : Enum<T>> T.isNoneOf(vararg values: T) = values.none { this == it } |
51 changes: 51 additions & 0 deletions
51
dachlatten-primitives/src/test/kotlin/de/sipgate/dachlatten/primitives/EnumExtTest.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,51 @@ | ||
package de.sipgate.dachlatten.primitives | ||
|
||
import de.sipgate.dachlatten.primitives.EnumExtTest.SomeValues.A | ||
import de.sipgate.dachlatten.primitives.EnumExtTest.SomeValues.B | ||
import de.sipgate.dachlatten.primitives.EnumExtTest.SomeValues.C | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class EnumExtTest { | ||
enum class SomeValues { | ||
A, | ||
B, | ||
C, | ||
} | ||
|
||
@Test | ||
fun testIsAnyOfSelf() { | ||
assertTrue(A.isAnyOf(A)) | ||
} | ||
|
||
@Test | ||
fun testIsAnyOfWithSubset() { | ||
assertTrue(A.isAnyOf(A, B)) | ||
} | ||
|
||
@Test | ||
fun testIsAnyOfFullEnum() { | ||
assertTrue(A.isAnyOf(*SomeValues.entries.toTypedArray())) | ||
} | ||
|
||
@Test | ||
fun testIsAnyOfNotContained() { | ||
assertFalse(A.isAnyOf(B, C)) | ||
} | ||
|
||
@Test | ||
fun testIsNoneOfSelfIsFalse() { | ||
assertFalse(A.isNoneOf(A)) | ||
} | ||
|
||
@Test | ||
fun testIsNoneOfOther() { | ||
assertTrue(A.isNoneOf(B)) | ||
} | ||
|
||
@Test | ||
fun testIsNoneOfNotContained() { | ||
assertTrue(A.isNoneOf(B, C)) | ||
} | ||
} |