Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions quickcheck/arbitrary.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,26 @@ pub impl[X : Arbitrary] Arbitrary for Array[X] with arbitrary(size, rs) {
let len = if size == 0 { 0 } else { rs.next_positive_int() % size }
Array::makei(len, x => X::arbitrary(x, rs))
}

///|
/// 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(
Comment on lines +172 to +183
size,
rs,
) {
let m : Map[K, V] = {}
let len = if size == 0 { 0 } else { rs.next_positive_int() % size }
for i in 0..<len {
m.set(K::arbitrary(i, rs), V::arbitrary(i, rs))
}
m
}
1 change: 1 addition & 0 deletions quickcheck/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ pub impl Arbitrary for Bytes
pub impl[X : Arbitrary] Arbitrary for Array[X]
pub impl[A : Arbitrary] Arbitrary for ArrayView[A]
pub impl[X : Arbitrary] Arbitrary for Iter[X]
pub impl[K : Arbitrary + Hash + Eq, V : Arbitrary] Arbitrary for Map[K, V]

Loading