Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Sources/PropertyBased/Gen+Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@ extension Gen where Value: OptionSet & Sendable, Value.RawValue: FixedWidthInteg
/// - Parameter options: The options to choose from.
/// - Returns: A generator of option sets.
public static func optionSet(of options: Value) -> Generator<Value, Shrink.Bitwise<Value.RawValue>> {
Gen<Value.RawValue>.bitSet.map { Value(rawValue: $0 & options.rawValue) }
Gen<Value.RawValue>.bitSet(mask: options.rawValue).map { Value(rawValue: $0) }
}
}
12 changes: 10 additions & 2 deletions Sources/PropertyBased/Gen+Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ extension Gen where Value: FixedWidthInteger & Sendable {
///
/// The associated shrinker will remove every bit, but will never set bits that are unset in the original value.
@inlinable
public static var bitSet: Generator<Value, Shrink.Bitwise<Value>> {
public static var bitSet: Generator<Value, Shrink.Bitwise<Value>> { bitSet() }

/// Produces a generator of random integers within the given bit mask.
///
/// The associated shrinker will remove every bit, but will never set bits that are unset in the original value.
/// - Parameter mask: The bit mask to apply to each generated value.
/// - Returns: A generator of random values.
@inlinable
public static func bitSet(mask: Value = ~0) -> Generator<Value, Shrink.Bitwise<Value>> {
return .init(
run: { rng in Value.random(in: .min ... .max, using: &rng) },
run: { rng in Value.random(in: .min ... .max, using: &rng) & mask },
shrink: { .init($0) }
)
}
Expand Down