mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add random sample
This commit is contained in:
parent
3d37a94aaf
commit
6ae817d4bc
1 changed files with 36 additions and 0 deletions
|
@ -56,5 +56,41 @@ module Spectator
|
|||
::Spectator::SpecBuilder.end_group
|
||||
end
|
||||
end
|
||||
|
||||
macro random_sample(collection, count = nil, &block)
|
||||
{% name = block.args.empty? ? :value.id : block.args.first.id %}
|
||||
|
||||
def %collection
|
||||
{{collection}}
|
||||
end
|
||||
|
||||
def %to_a
|
||||
{% if count %}
|
||||
%collection.first({{count}})
|
||||
{% else %}
|
||||
%collection.to_a
|
||||
{% end %}
|
||||
end
|
||||
|
||||
class Context%sample < {{@type.id}}
|
||||
::Spectator::SpecBuilder.start_sample_group({{collection.stringify}}, :%sample, {{name.stringify}}) do |values|
|
||||
sample = {{@type.id}}.new(values)
|
||||
collection = sample.%to_a
|
||||
{% if count %}
|
||||
collection.sample({{count}}, ::Spectator.random)
|
||||
{% else %}
|
||||
collection.shuffle(::Spectator.random)
|
||||
{% end %}
|
||||
end
|
||||
|
||||
def {{name}}
|
||||
@spectator_test_values.get_value(:%sample, typeof(%to_a.first))
|
||||
end
|
||||
|
||||
{{block.body}}
|
||||
|
||||
::Spectator::SpecBuilder.end_group
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue