Create realistic number of Matches

When match_count is -1 the number of matches generated is automatically
2 ^ stage.level -> This is the amount of stages present in a "real"
tournament stage. When supplying a positive number, it generates that
many matches like before.

This also now adds the position to the match list after creating them
This commit is contained in:
Daniel Schädler 2019-05-09 16:21:49 +02:00
parent 31a57572dc
commit b5d71f33ca
1 changed files with 4 additions and 1 deletions

View File

@ -19,7 +19,10 @@ FactoryBot.define do
match_count { 4 }
end
after(:create) do |stage, evaluator|
stage.matches = create_list(:match, evaluator.match_count)
# match_count -1 automatically generates 2 ^ stage.level matches
# (as this would be the amount of stages present in the real world)
stage.matches = create_list(:match, evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count)
stage.matches.each_with_index { |match, i| match.position = i }
end
end
end