Chuong
09/15/2024, 10:07 PMval genBlankString: Arb<String> = Arb.string().filter { it.isBlank() }
val genNonBlankString: Arb<String> = Arb.string().filter { it.isNotBlank() }
What are the drawbacks of this approach? Specifically, what are the drawbacks of using filter
? Does it reduce the number of tests that are being run and the comprehensiveness of the tests?LeoColman
09/15/2024, 11:01 PMArb.string()
is lazy and will be filtered as elements are generated.
The problem you will face for your approach specifically is that getting an empty string from all the possible strings is very unlikely, so your test will probably take a long time (if not forever) to generate enough strings to get you plenty of blank strings to work with.
I would instead check the parameters for Arb.string()
as they can be manipulated for your liking:
fun Arb.Companion.string(
minSize: Int = 0,
maxSize: Int = 100,
codepoints: Arb<Codepoint> = Codepoint.printableAscii()
)
----
It's not a filter
issue specifically, but the way generation worksLeoColman
09/15/2024, 11:02 PMChuong
09/15/2024, 11:02 PMChuong
09/15/2024, 11:03 PMLeoColman
09/15/2024, 11:44 PMChuong
09/15/2024, 11:46 PMLeoColman
09/15/2024, 11:50 PMfun Codepoint.Companion.whitespace(): Arb<Codepoint> =
Arb.of(listOf(
9, // TAB
10, // LINE FEED
11, // LINE TABULATION
12, // FORM FEED
13, // CARRIAGE RETURN
32, // SPACE
).map(::Codepoint))
this guy is probably what you want for strings with whitespacesScott Fedorov
09/26/2024, 9:10 PMScott Fedorov
09/26/2024, 9:11 PMChuong
09/26/2024, 9:12 PMScott Fedorov
09/26/2024, 9:18 PM