Skip to content

Add FloatStrategy to control generated Float value range#87

Closed
MessiasLima wants to merge 1 commit into
mainfrom
feature/float-strategy-9804220812499711518
Closed

Add FloatStrategy to control generated Float value range#87
MessiasLima wants to merge 1 commit into
mainfrom
feature/float-strategy-9804220812499711518

Conversation

@MessiasLima

Copy link
Copy Markdown
Owner

This PR introduces FloatStrategy, enabling users to constrain the range of randomly generated Float values during fixture generation.

Key changes:

  • FloatStrategy data class added to dev.appoutlet.some.config with support for ranges and fixed values.
  • FloatResolver now respects the configured FloatStrategy, falling back to a default range of 0.0f..1.0f to maintain backward compatibility.
  • SomeConfig updated to include FloatStrategy in its default strategies map and properly wire it to FloatResolver.
  • Documentation updated to include FloatStrategy in the list of built-in strategies.
  • Unit tests added to verify strategy validation, constructors, and resolver behavior.

Fixes #69


PR created automatically by Jules for task 9804220812499711518 started by @MessiasLima

- 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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 57 to +58
data class SomeConfig(
val strategies: Map<KClass<out Strategy>, Strategy> = emptyMap(),
val strategies: Map<KClass<out Strategy>, Strategy> = defaultStrategies(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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(),

Comment on lines +198 to +209
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,
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since we are reverting strategies to default to emptyMap(), the defaultStrategies() helper and the companion object are no longer needed and can be safely removed.

Comment on lines +13 to +15
init {
require(range.start <= range.endInclusive) { "range.start must be less than or equal to range.endInclusive" }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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" }
}

@github-project-automation github-project-automation Bot moved this from Ready to Done in Some Jun 22, 2026
@MessiasLima MessiasLima deleted the feature/float-strategy-9804220812499711518 branch June 22, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add FloatStrategy to control generated Float value range

1 participant