Add FloatStrategy to control generated Float value range#87
Conversation
- Introduce FloatStrategy in dev.appoutlet.some.config to allow constraining generated Float values via a ClosedFloatingPointRange or a fixed value. - Update FloatResolver to consume the active FloatStrategy from StrategyProvider. - Register FloatStrategy in SomeConfig.defaultStrategies() and update wiring in SomeConfig.buildResolvers(). - Update KDoc in Strategy.kt and SomeConfigBuilder.kt with FloatStrategy details and examples. - Add comprehensive unit tests for FloatStrategy and updated tests for FloatResolver. Co-authored-by: MessiasLima <10220064+MessiasLima@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces FloatStrategy and updates FloatResolver to respect the configured float generation strategy. The review feedback suggests reverting the default value of strategies in SomeConfig to emptyMap() to maintain consistency with the DSL builder and avoid redundant allocations. Additionally, it recommends adding validation to FloatStrategy to ensure that the range bounds are finite, preventing potential runtime errors during random float generation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| data class SomeConfig( | ||
| val strategies: Map<KClass<out Strategy>, Strategy> = emptyMap(), | ||
| val strategies: Map<KClass<out Strategy>, Strategy> = defaultStrategies(), |
There was a problem hiding this comment.
By changing the default value of strategies to defaultStrategies(), an inconsistency is introduced between direct instantiation and DSL-based building. Specifically, SomeConfig() will have a populated strategies map, whereas buildSomeConfig { } (which uses SomeConfigBuilder starting with an empty map) will produce a SomeConfig with an empty strategies map.
Since all resolvers (including the new FloatResolver) already correctly fall back to their respective .default strategies when the strategy is missing from the provider, we don't need to pre-populate strategies with defaults. Reverting this to emptyMap() maintains consistency, simplifies the configuration, and avoids redundant map allocations.
| data class SomeConfig( | |
| val strategies: Map<KClass<out Strategy>, Strategy> = emptyMap(), | |
| val strategies: Map<KClass<out Strategy>, Strategy> = defaultStrategies(), | |
| data class SomeConfig( | |
| val strategies: Map<KClass<out Strategy>, Strategy> = emptyMap(), |
| companion object { | ||
| /** | ||
| * Returns the default strategies for fixture generation. | ||
| */ | ||
| fun defaultStrategies(): Map<KClass<out Strategy>, Strategy> = mapOf( | ||
| NullableStrategy::class to NullableStrategy.default, | ||
| StringStrategy::class to StringStrategy.default, | ||
| CollectionStrategy::class to CollectionStrategy.default, | ||
| FloatStrategy::class to FloatStrategy.default, | ||
| DefaultValueStrategy::class to DefaultValueStrategy.default, | ||
| ) | ||
| } |
| init { | ||
| require(range.start <= range.endInclusive) { "range.start must be less than or equal to range.endInclusive" } | ||
| } |
There was a problem hiding this comment.
It is a good practice to ensure that the range bounds are finite (Float.isFinite()). If a user passes Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY, generating a random value in FloatResolver using Random.nextDouble will fail or produce unexpected results (like NaN or Infinity) because uniform sampling over an infinite range is not supported.
| init { | |
| require(range.start <= range.endInclusive) { "range.start must be less than or equal to range.endInclusive" } | |
| } | |
| init { | |
| require(range.start.isFinite() && range.endInclusive.isFinite()) { "range bounds must be finite" } | |
| require(range.start <= range.endInclusive) { "range.start must be less than or equal to range.endInclusive" } | |
| } |
This PR introduces
FloatStrategy, enabling users to constrain the range of randomly generatedFloatvalues during fixture generation.Key changes:
FloatStrategydata class added todev.appoutlet.some.configwith support for ranges and fixed values.FloatResolvernow respects the configuredFloatStrategy, falling back to a default range of0.0f..1.0fto maintain backward compatibility.SomeConfigupdated to includeFloatStrategyin its default strategies map and properly wire it toFloatResolver.FloatStrategyin the list of built-in strategies.Fixes #69
PR created automatically by Jules for task 9804220812499711518 started by @MessiasLima