Skip to content

Commit

Permalink
fixes thewca#5725 added warning for multiple groups of fmc used
Browse files Browse the repository at this point in the history
  • Loading branch information
Jambrose777 authored and Jambrose777 committed Oct 7, 2020
1 parent 5163532 commit e138a27
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions WcaOnRails/lib/results_validators/scrambles_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ScramblesValidator < GenericValidator
UNEXPECTED_SCRAMBLES_FOR_ROUND_ERROR = "[%{round_id}] Too many scrambles. Use Scrambles Matcher to uncheck the unused scrambles."
MISSING_SCRAMBLES_FOR_GROUP_ERROR = "[%{round_id}] Group %{group_id}: missing scrambles, detected only %{actual} instead of %{expected}."
MISSING_SCRAMBLES_FOR_MULTI_ERROR = "[%{round_id}] While you may have multiple groups in 3x3x3 Multi-Blind, at least one of the groups must contain scrambles for all attempts."
MULTIPLE_FMC_GROUPS_WARNING = "[%{round_id}] There are multiple groups of FMC used. If one group of FMC was used, please use the Scrambles Matcher to uncheck the unused scrambles. Otherwise, please include a comment to WRT explaining why multiple groups of FMC were used."

@@desc = "This validator checks that all results have matching scrambles, and if possible, checks that the scrambles have the correct number of attempts compared to the expected round format."

Expand Down Expand Up @@ -82,6 +83,11 @@ def validate(competition_ids: [], model: Result, results: nil)
expected: expected_number_of_scrambles)
end
end
if round_id.start_with?("333fm") && scrambles_by_group_id.size > 1
@warnings << ValidationError.new(:scrambles, competition_id,
MULTIPLE_FMC_GROUPS_WARNING,
round_id: round_id)
end
if round_id.start_with?("333mbf")
unless errors_for_round.size < scrambles_by_group_id.keys.size
@errors << ValidationError.new(:scrambles, competition_id,
Expand Down
25 changes: 25 additions & 0 deletions WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@
end
end

it "correctly (in)validates multiple groups for 333fm" do
FactoryBot.create(:round, competition: competition1, event_id: "333fm", format_id: "m")

[Result, InboxResult].each do |model|
result_kind = model.model_name.singular.to_sym
FactoryBot.create(result_kind, :mbf, competition: competition1)
end

# Create two groups in fmc:
create_scramble_set(3, competitionId: competition1.id, eventId: "333fm", groupId: "A")
create_scramble_set(3, competitionId: competition1.id, eventId: "333fm", groupId: "B")

expected_warnings = [
RV::ValidationWarning.new(:scrambles, competition1.id,
SV::MULTIPLE_FMC_GROUPS_WARNING,
round_id: "333fm-f"),
]

validator_args.each do |arg|
sv = SV.new.validate(arg)
expect(sv.warnings).to match_array(expected_warnings)
expect(sv.errors).to be_empty
end
end

it "correctly (in)validates multiple groups for 333mbf" do
FactoryBot.create(:round, competition: competition1, event_id: "333mbf", format_id: "3")
FactoryBot.create(:round, competition: competition2, event_id: "333mbf", format_id: "3")
Expand Down

0 comments on commit e138a27

Please sign in to comment.