feat(quickcheck): add Arbitrary impl for Map to match HashMap#3585
Open
bobzhang wants to merge 2 commits into
Open
feat(quickcheck): add Arbitrary impl for Map to match HashMap#3585bobzhang wants to merge 2 commits into
bobzhang wants to merge 2 commits into
Conversation
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>
Collaborator
Coverage Report for CI Build 4338Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.001%) to 94.294%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Contributor
There was a problem hiding this comment.
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]inquickcheck/arbitrary.mbt. - Updated
quickcheck/pkg.generated.mbtito 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 on lines
+189
to
+190
| for _ in 0..<len { | ||
| m.set(K::arbitrary(size, rs), V::arbitrary(size, rs)) |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
impl @quickcheck.Arbitrary for Map[K, V]inquickcheck/arbitrary.mbtalongside the other builtin type impls.Motivation
HashMapalready has anArbitraryimpl inhashmap/hashmap.mbt, but the equivalentMap(LinkedHashMap inbuiltin) was missing one.Changes
impl Arbitrary for Map[K, V]toquickcheck/arbitrary.mbttuplepackage)pkg.generated.mbti