repochecker: Ensure hint and choice_cost are not higher than gain
This commit is contained in:
parent
09c1111135
commit
7fbe2f3f8e
2 changed files with 20 additions and 6 deletions
|
@ -123,7 +123,15 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExc
|
||||||
func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, error) {
|
func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, error) {
|
||||||
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
|
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.
|
// SyncExerciceHints reads the content of files/ directories and import it as EHint for the given challenge.
|
||||||
|
|
|
@ -555,8 +555,9 @@ func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fk, ok := flag.Flag.(*fic.FlagKey); ok {
|
||||||
// Check dependency to flag optional flag
|
// Check dependency to flag optional flag
|
||||||
if fk, ok := flag.Flag.(*fic.FlagKey); ok && fk.BonusGain == 0 {
|
if fk.BonusGain == 0 {
|
||||||
for _, nf := range flag.FlagsDeps {
|
for _, nf := range flag.FlagsDeps {
|
||||||
if fk2, ok := flags[nf].Flag.(*fic.FlagKey); ok && fk2.BonusGain != 0 {
|
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)))
|
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)))
|
||||||
|
@ -564,6 +565,11 @@ func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// Check dependency loop
|
||||||
deps := flag.FlagsDeps
|
deps := flag.FlagsDeps
|
||||||
for i := 0; i < len(deps); i++ {
|
for i := 0; i < len(deps); i++ {
|
||||||
|
|
Reference in a new issue