Skip to content

feat(quickcheck): add Arbitrary impl for Map to match HashMap#3585

Open
bobzhang wants to merge 2 commits into
mainfrom
feat/map-arbitrary
Open

feat(quickcheck): add Arbitrary impl for Map to match HashMap#3585
bobzhang wants to merge 2 commits into
mainfrom
feat/map-arbitrary

Conversation

@bobzhang

Copy link
Copy Markdown
Contributor

Summary

Adds impl @quickcheck.Arbitrary for Map[K, V] in quickcheck/arbitrary.mbt alongside the other builtin type impls.

Motivation

HashMap already has an Arbitrary impl in hashmap/hashmap.mbt, but the equivalent Map (LinkedHashMap in builtin) was missing one.

Changes

  • Added impl Arbitrary for Map[K, V] to quickcheck/arbitrary.mbt
  • Generates keys and values independently (avoids a circular dependency with the tuple package)
  • Updated pkg.generated.mbti

Map (LinkedHashMap) was missing the @quickcheck.Arbitrary impl that HashMap
already has. Added to quickcheck/arbitrary.mbt alongside other builtin type
impls. Generates keys/values independently to avoid a circular dependency
with the tuple package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 09:11
@coveralls

coveralls commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 4338

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.001%) to 94.294%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15790
Covered Lines: 14889
Line Coverage: 94.29%
Coverage Strength: 217492.01 hits per line

💛 - Coveralls

Copilot AI 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.

Pull request overview

Adds @quickcheck.Arbitrary support for the builtin Map[K, V] (linked hash map) so property-based tests can generate Map values similarly to the existing HashMap support.

Changes:

  • Added pub impl Arbitrary for Map[K, V] in quickcheck/arbitrary.mbt.
  • Updated quickcheck/pkg.generated.mbti to expose the new impl in generated package metadata.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
quickcheck/arbitrary.mbt Introduces the Arbitrary implementation for Map[K, V] and accompanying doc example.
quickcheck/pkg.generated.mbti Registers the new Map[K, V] Arbitrary impl in generated package interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread quickcheck/arbitrary.mbt Outdated
Comment on lines +189 to +190
for _ in 0..<len {
m.set(K::arbitrary(size, rs), V::arbitrary(size, rs))
Comment thread quickcheck/arbitrary.mbt
Comment on lines +172 to +183
///|
/// Returns a randomly generated map containing arbitrary key-value pairs.
///
/// Example:
///
/// ```mbt check
/// test {
/// let samples : Array[Map[Int, String]] = @quickcheck.samples(5)
/// inspect(samples.length(), content="5")
/// }
/// ```
pub impl[K : Arbitrary + Hash + Eq, V : Arbitrary] Arbitrary for Map[K, V] with arbitrary(
Per codex review: pass loop index i as the size argument to K::arbitrary
and V::arbitrary, matching the pattern used by Array::makei. This prevents
infinite recursion when Map appears inside a recursive Arbitrary type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bobzhang bobzhang enabled auto-merge (squash) May 13, 2026 09:33
@bobzhang bobzhang disabled auto-merge May 14, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants