lib/prop_check/generators.rb in prop_check-0.12.1 vs lib/prop_check/generators.rb in prop_check-0.13.0
- old
+ new
@@ -80,15 +80,23 @@
# => 5795
# >> r = Random.new(42); Generators.integer.sample(size: 20000, rng: r)
# => [-4205, -19140, 18158, -8716, -13735, -3150, 17194, 1962, -3977, -18315]
def integer
Generator.new do |size:, rng:, **|
+ ensure_proper_size!(size)
+
val = rng.rand(-size..size)
LazyTree.new(val, integer_shrink(val))
end
end
+ private def ensure_proper_size!(size)
+ return if size.is_a?(Integer) && size >= 0
+
+ raise ArgumentError, "`size:` should be a nonnegative integer but got `#{size.inspect}`"
+ end
+
##
# Only returns integers that are zero or larger.
# See `integer` for more information.
def nonnegative_integer
integer.map(&:abs)
@@ -260,10 +268,10 @@
end
if max.nil?
nonnegative_integer.bind(&res)
else
- proc.call(max)
+ res.call(max)
end
end
##
# Generates a hash of key->values,