dave08
09/09/2024, 3:37 PMpublic fun <T> Array<out T>.random(random: Random): T
for Prepared's random... I don't know if this is good practice, but currently I just did:
FooEnum.entries.toTypedArray().random(random.accessUnsafe())
CLOVIS
09/09/2024, 9:21 PMdave08
09/10/2024, 2:22 AMCLOVIS
09/10/2024, 7:31 AMCLOVIS
09/10/2024, 7:32 AMsuspend fun <T> TestDsl.randomOf(array: Array<T>) =
array.random(random.accessUnsafe())
but I can't do anything much better before context parametersdave08
09/10/2024, 8:07 AMSince it's an enum, wouldn't it be better to brute-force all cases?In this case it doesn't involve any logic... so I just randomize it so that my hard-coded TDD first test won't pass...
Anyone you can write: ...Yeah, I was wondering if accessUnsafe() was safe over here. And yeah... I guess until context params come out things are less pleasant... I didn't think of that that you needed the TestDsl context too 🤷🏼♂️.
CLOVIS
09/10/2024, 8:19 AMCLOVIS
09/10/2024, 8:20 AMCLOVIS
09/10/2024, 8:20 AMI didn't think of that that you needed the TestDsl context tooGuess what!
random
is a prepared value internally 😅dave08
09/10/2024, 8:23 AMval TestDsl.random: Random
get() = Random(this)
It creates a new instance for each call to random?CLOVIS
09/10/2024, 9:25 AMCLOVIS
09/10/2024, 9:25 AMdave08
09/10/2024, 9:25 AMdave08
09/10/2024, 9:26 AMCLOVIS
09/10/2024, 9:26 AMdave08
09/10/2024, 9:26 AMCLOVIS
09/10/2024, 9:26 AMtime
and other helpers do the same)CLOVIS
09/10/2024, 9:27 AMdave08
09/10/2024, 9:28 AMCLOVIS
09/10/2024, 9:28 AMtime
since it takes 2 argumentsdave08
09/10/2024, 9:31 AMescape analysis will remove it anywayI guess if that's so, then it's not a problem... I always tried making such wrappers value classes, but I'm not such an expert on compiler optimisations... interesting to know this...!
CLOVIS
09/10/2024, 9:32 AMjava.lang.Optional