Skip to content

feat: float strategy#89

Merged
MessiasLima merged 3 commits into
mainfrom
69-add-floatstrategy-to-control-generated-float-value-range
Jun 22, 2026
Merged

feat: float strategy#89
MessiasLima merged 3 commits into
mainfrom
69-add-floatstrategy-to-control-generated-float-value-range

Conversation

@MessiasLima

@MessiasLima MessiasLima commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Introduces a FloatStrategy so users can constrain the range of randomly generated Float values during fixture generation. Until now, FloatResolver always called random.nextFloat(), producing values in [0.0, 1.0) with no way to widen, shift, or pin the range without writing a custom resolver or factory.

This follows the same pattern as CollectionStrategy: a data class wrapping a ClosedFloatingPointRange<Float> with input validation, a companion object default, and a corresponding resolver update that consumes the active strategy via StrategyProvider. The default range 0.0f..1.0f preserves the current behavior of FloatResolver to avoid a breaking change for existing users. A secondary constructor FloatStrategy(fixed: Float) is provided as a convenience for callers who want to pin generation to a single value.

Closes #69.

What changed

  • New core/src/main/kotlin/dev/appoutlet/some/config/FloatStrategy.kt — data class with primary constructor FloatStrategy(range: ClosedFloatingPointRange<Float> = 0.0f..1.0f), secondary constructor FloatStrategy(fixed: Float), validation that throws IllegalArgumentException when range.start > range.endInclusive (zero-width ranges allowed), and a companion object exposing FloatStrategy.default.
  • Updated FloatResolver to accept a StrategyProvider and produce values within the configured range. Zero-width ranges return the fixed value directly; non-zero-width ranges use start + random.nextFloat() * (endInclusive - start) (exclusive end, matching random.nextDouble(from, until) semantics).
  • Updated SomeConfig.buildResolvers() to wire FloatResolver(strategyProvider, random).
  • Updated KDoc in Strategy.kt and SomeConfigBuilder.kt to list FloatStrategy alongside the other built-in strategies.
  • New FloatStrategyTest covering default range, validation of inverted ranges, zero-width behavior, and secondary constructor equivalence.
  • Updated FloatResolverTest to cover the new constructor signature, default range, custom range, negative range, fixed value, zero-width range, and SomeConfig integration.
  • New docs/configuration/float-strategy.md documenting configuration, fixed-value constructor, default, affected types, and validation. Linked from the configuration index defaults table, the supported-types.md Float row, and added to the zensical.toml Configuration nav.

Checklist

  • Tests were added or updated when needed
  • Documentation was updated when needed

@MessiasLima MessiasLima linked an issue Jun 22, 2026 that may be closed by this pull request
7 tasks
@github-project-automation github-project-automation Bot moved this to Ready in Some Jun 22, 2026

@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 support configurable ranges for generated Float values, complete with documentation and unit tests. The feedback highlights two key improvements: resolving a potential float overflow issue during random generation for very wide ranges by performing intermediate calculations in Double precision, and optimizing FloatStrategy.default to be a stored property rather than a custom getter to prevent unnecessary object allocations.

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 thread core/src/main/kotlin/dev/appoutlet/some/resolver/FloatResolver.kt
Comment thread core/src/main/kotlin/dev/appoutlet/some/config/FloatStrategy.kt Outdated
@MessiasLima MessiasLima merged commit b23ff24 into main Jun 22, 2026
1 check passed
@MessiasLima MessiasLima deleted the 69-add-floatstrategy-to-control-generated-float-value-range branch June 22, 2026 13:21
@github-project-automation github-project-automation Bot moved this from Ready to Done in Some Jun 22, 2026
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