repochecker: Ensure hint and choice_cost are not higher than gain

This commit is contained in:
nemunaire 2024-03-17 18:10:21 +01:00
parent 09c1111135
commit 7fbe2f3f8e
2 changed files with 20 additions and 6 deletions

View File

@ -123,7 +123,15 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExc
func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, error) {
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
return buildExerciceHints(i, exercice, exceptions)
hints, errs := buildExerciceHints(i, exercice, exceptions)
for _, hint := range hints {
if hint.Hint.Cost >= exercice.Gain {
errs = multierr.Append(errs, NewHintError(exercice, hint.Hint, hint.Line, fmt.Errorf("hint's cost is higher than exercice gain")))
}
}
return hints, errs
}
// SyncExerciceHints reads the content of files/ directories and import it as EHint for the given challenge.

View File

@ -555,13 +555,19 @@ func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exce
}
}
// Check dependency to flag optional flag
if fk, ok := flag.Flag.(*fic.FlagKey); ok && fk.BonusGain == 0 {
for _, nf := range flag.FlagsDeps {
if fk2, ok := flags[nf].Flag.(*fic.FlagKey); ok && fk2.BonusGain != 0 {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag is not optional but depend on flag id=%d which is optional", nf)))
if fk, ok := flag.Flag.(*fic.FlagKey); ok {
// Check dependency to flag optional flag
if fk.BonusGain == 0 {
for _, nf := range flag.FlagsDeps {
if fk2, ok := flags[nf].Flag.(*fic.FlagKey); ok && fk2.BonusGain != 0 {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag is not optional but depend on flag id=%d which is optional", nf)))
}
}
}
if int64(fk.ChoicesCost) >= exercice.Gain {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag's choice_cost is higher than exercice gain")))
}
}
// Check dependency loop