lib/prop_check/property.rb in prop_check-0.15.0 vs lib/prop_check/property.rb in prop_check-0.16.0
- old
+ new
@@ -109,10 +109,71 @@
return duplicate.check(&block) if block_given?
duplicate
end
+ ##
+ # Resizes all generators in this property with the given function.
+ #
+ # Shorthand for manually wrapping `PropCheck::Property::Configuration.resize_function` with the new function.
+ def resize(&block)
+ raise '#resize called without a block' unless block_given?
+
+ orig_fun = @config.resize_function
+ with_config(resize_function: block)
+ end
+
+ ##
+ # Resizes all generators in this property. The new size is `2.pow(orig_size)`
+ #
+ # c.f. #resize
+ def growing_exponentially(&block)
+ orig_fun = @config.resize_function
+ fun = proc { |size| 2.pow(orig_fun.call(size)) }
+ with_config(resize_function: fun, &block)
+ end
+
+ ##
+ # Resizes all generators in this property. The new size is `orig_size * orig_size`
+ #
+ # c.f. #resize
+ def growing_quadratically(&block)
+ orig_fun = @config.resize_function
+ fun = proc { |size| orig_fun.call(size).pow(2) }
+ with_config(resize_function: fun, &block)
+ end
+
+ ##
+ # Resizes all generators in this property. The new size is `2 * orig_size`
+ #
+ # c.f. #resize
+ def growing_fast(&block)
+ orig_fun = @config.resize_function
+ fun = proc { |size| orig_fun.call(size) * 2 }
+ with_config(resize_function: fun, &block)
+ end
+
+ ##
+ # Resizes all generators in this property. The new size is `0.5 * orig_size`
+ #
+ # c.f. #resize
+ def growing_slowly(&block)
+ orig_fun = @config.resize_function
+ fun = proc { |size| orig_fun.call(size) * 0.5 }
+ with_config(resize_function: fun, &block)
+ end
+
+ ##
+ # Resizes all generators in this property. The new size is `Math.log2(orig_size)`
+ #
+ # c.f. #resize
+ def growing_logarithmically(&block)
+ orig_fun = @config.resize_function
+ fun = proc { |size| Math.log2(orig_fun.call(size)) }
+ with_config(resize_function: fun, &block)
+ end
+
def with_bindings(*bindings, **kwbindings)
raise ArgumentError, 'No bindings specified!' if bindings.empty? && kwbindings.empty?
duplicate = dup
duplicate.instance_variable_set(:@gen, gen_from_bindings(bindings, kwbindings))
@@ -277,11 +338,12 @@
rng = Random::DEFAULT
size = 1
(0...@config.max_generate_attempts)
.lazy
.map do
+ generator_size = @config.resize_function.call(size).to_i
binding_generator.generate(
- size: size,
+ size: generator_size,
rng: rng,
max_consecutive_attempts: @config.max_consecutive_attempts,
config: @config
)
end