Skip to content

dataconnect(test): add sum partition and optional variable Arbs - #8539

Draft
dconeybe wants to merge 1 commit into
mainfrom
dconeybe/dataconnect/TestHelpers
Draft

dataconnect(test): add sum partition and optional variable Arbs#8539
dconeybe wants to merge 1 commit into
mainfrom
dconeybe/dataconnect/TestHelpers

Conversation

@dconeybe

@dconeybe dconeybe commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This PR introduces several property-based testing utilities to firebase-dataconnect, including a Kotest Arb for integer sum partitioning and generators for OptionalVariable types.

There should be no noticeable side effects to customers; this is internal test utility code.

Highlights

  • Sum Partition Arbitrary: Added SumPartitionArb, a Kotest Arb that generates random partitions of a non-negative integer sum into a fixed number of non-negative summands, including edge cases for zeroes, ascending order, and descending order.
  • OptionalVariable Generators: Added optionalVariable and nullableOptionalVariable arbitrary generators to DataConnectArb to generate OptionalVariable instances with configurable probabilities for undefined and null states.
  • Kotest Test Helpers: Added PropTestConfig.withEdgeConfigEdgeCasesOnly() for running tests solely against generated edge cases, and registered custom printer formatting for Apache Commons SignificanceResult.
  • Testing & Distribution Verification: Added comprehensive unit and property-based test suites, including Chi-Square goodness-of-fit tests to verify uniform distributions of generated edge case types and probabilities.
Changelog
  • KotestTestutilPrinters.kt
    • Registered custom printer support for Apache Commons SignificanceResult.
  • PropTestConfigExts.kt
    • Added withEdgeConfigEdgeCasesOnly() extension on PropTestConfig.
  • SumPartitionArb.kt
    • New Kotest Arb implementation for partitioning an integer sum into a fixed count of non-negative summands.
  • arbs.kt
    • Added optionalVariable and nullableOptionalVariable arbitrary generator functions to DataConnectArb.
  • SumPartitionArbUnitTest.kt
    • Added unit and property-based tests for SumPartitionArb.
  • arbsUnitTest.kt
    • Added unit and property-based tests for optionalVariable and nullableOptionalVariable.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@dconeybe dconeybe changed the title dataconnect(test): add a few generally-useful testing utilities dataconnect(test): add sum partition and optional variable arbitraries Aug 18, 2026
@dconeybe dconeybe changed the title dataconnect(test): add sum partition and optional variable arbitraries dataconnect(test): add sum partition and optional variable Arbs Aug 18, 2026
@dconeybe

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 test utilities and Kotest generators for the Firebase Data Connect SDK. Specifically, it adds a SumPartitionArb generator to partition an integer into a fixed number of summands, along with custom optionalVariable and nullableOptionalVariable generators in DataConnectArb. It also includes corresponding unit tests and Kotest printers. The review feedback suggests simplifying the initialization of edgeCaseZeroesCountArb using Kotlin's by lazy delegation, and addressing a potential floating-point precision issue in the probability sum validation within nullableOptionalVariable by adding a small tolerance.

Comment on lines +56 to +62
private val edgeCaseZeroesCountArb: Arb<Int> = run {
if (sum == 0) {
arbitrary { throw IllegalStateException("internal error h5zagzq8g4: should never get here") }
} else {
Arb.int(1 until summandCount)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using by lazy simplifies the initialization of edgeCaseZeroesCountArb and avoids the need for a dummy error-throwing Arb when sum == 0. Since edgeCaseZeroesCountArb is only accessed inside edgecase when summandCount >= 2 and sum > 0, we are guaranteed that 1 until summandCount is a valid, non-empty range when the lazy property is initialized.

  private val edgeCaseZeroesCountArb: Arb<Int> by lazy {
    Arb.int(1 until summandCount)
  }

Comment on lines +362 to +363
val probabilitiesSum = undefinedProbability + nullableProbability
require(probabilitiesSum <= 1.0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Due to floating-point precision limits, adding two valid probabilities that mathematically sum to 1.0 (such as 0.56 and 0.44) can result in a sum slightly greater than 1.0 (e.g., 1.0000000000000002). This causes the require check to throw an IllegalArgumentException unexpectedly. Adding a tiny tolerance (e.g., 1e-9) prevents these precision-related failures while still rejecting genuinely invalid inputs.

Suggested change
val probabilitiesSum = undefinedProbability + nullableProbability
require(probabilitiesSum <= 1.0) {
val probabilitiesSum = undefinedProbability + nullableProbability
require(probabilitiesSum <= 1.0 + 1e-9) {

@github-actions

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant