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 8, 2020
1 parent 5163532 commit 3a9eb27
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
7 changes: 7 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,8 @@ 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 +84,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 << ValidationWarning.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
12 changes: 12 additions & 0 deletions WcaOnRails/spec/factories/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
value5 { 0 }
end

trait :fm do
eventId { "333fm" }
formatId { "m" }
average { 3500 }
best { 35 }
value1 { best }
value2 { best }
value3 { best }
value4 { 0 }
value5 { 0 }
end

trait :mo3 do
formatId { "m" }
average { best }
Expand Down
31 changes: 29 additions & 2 deletions WcaOnRails/spec/lib/results_validators/scrambles_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
context "on InboxResult and Result" do
let!(:competition1) { FactoryBot.create(:competition, :past, event_ids: ["333oh", "333mbf"]) }
let!(:competition2) { FactoryBot.create(:competition, :past, event_ids: ["222", "333bf", "333mbf"]) }
let!(:competition3) { FactoryBot.create(:competition, :past, event_ids: ["333fm"]) }

# The idea behind this variable is the following: the validator can be applied
# on either a particular model for given competition ids, or on a set of results.
# We simply want to check it has the expected behavior on all the possible cases.
let(:validator_args) {
[InboxResult, Result].flat_map { |model|
[
{ competition_ids: [competition1.id, competition2.id], model: model },
{ results: model.sorted_for_competitions([competition1.id, competition2.id]), model: model },
{ competition_ids: [competition1.id, competition2.id, competition3.id], model: model },
{ results: model.sorted_for_competitions([competition1.id, competition2.id, competition3.id]), model: model },
]
}
}
Expand Down Expand Up @@ -85,6 +86,32 @@
end
end

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

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

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

expected_warnings = [
RV::ValidationWarning.new(:scrambles, competition3.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)
puts sv.errors
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 3a9eb27

Please sign in to comment.