From 9a7d2efd496b70e1e67093f07b0efff569f5cd28 Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Mon, 11 Sep 2023 19:28:02 +0300 Subject: [PATCH] Make `map` and `except` apply transformer/filter to ALL value providers --- .../kotlin/org/utbot/fuzzing/Providers.kt | 25 ++++++++----------- .../decorators/ValueProviderDecorator.kt | 5 ---- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Providers.kt b/utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Providers.kt index f64fb7d996..0a47c42624 100644 --- a/utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Providers.kt +++ b/utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Providers.kt @@ -92,26 +92,16 @@ fun interface ValueProvider> { } /** - * Removes `anotherValueProviders) -> Boolean): ValueProvider { - return if (this is Combined) { - Combined(providers.map { it.unwrapIfFallback() }.filterNot(filter)) - } else { - Combined(if (filter(unwrapIfFallback())) emptyList() else listOf(this)) - } - } + fun except(filter: (ValueProvider) -> Boolean): ValueProvider = + map { if (filter(it)) Combined(emptyList()) else it } /** * Applies [transform] for current provider */ - fun map(transform: (ValueProvider) -> ValueProvider): ValueProvider { - return if (this is Combined) { - Combined(providers.map(transform)) - } else { - transform(this) - } - } + fun map(transform: (ValueProvider) -> ValueProvider): ValueProvider = + transform(this) /** * Uses fallback value provider in case when 'this' one failed to generate any value. @@ -167,6 +157,8 @@ fun interface ValueProvider> { } } + override fun map(transform: (ValueProvider) -> ValueProvider): ValueProvider = + transform(Fallback(provider.map(transform), fallback.map(transform))) } /** @@ -200,6 +192,9 @@ fun interface ValueProvider> { } } } + + override fun map(transform: (ValueProvider) -> ValueProvider): ValueProvider = + transform(Combined(providers.map { it.map(transform) })) } companion object { diff --git a/utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/ValueProviderDecorator.kt b/utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/ValueProviderDecorator.kt index 030d3bcd81..142c6c82d8 100644 --- a/utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/ValueProviderDecorator.kt +++ b/utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/ValueProviderDecorator.kt @@ -19,11 +19,6 @@ abstract class ValueProviderDecorator>( override fun generate(description: D, type: T): Sequence> = delegate.generate(description, type) - override fun except(filter: (ValueProvider) -> Boolean): ValueProvider { - val res = wrap(delegate.except(filter)) - return if (filter(res)) ValueProvider.of(emptyList()) else res - } - override fun map(transform: (ValueProvider) -> ValueProvider): ValueProvider = transform(wrap(delegate.map(transform))) } \ No newline at end of file