repochecker: Test number step are in phase with response precision
Closes: https://gitlab.cri.epita.fr/ing/majeures/srs/fic/server/-/issues/36
This commit is contained in:
parent
04e938ff73
commit
954cf84f0f
2 changed files with 60 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ package sync
|
|||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"go.uber.org/multierr"
|
||||
|
|
@ -78,6 +79,41 @@ func (f ExerciceFlag) RawString() []string {
|
|||
}
|
||||
}
|
||||
|
||||
func (f ExerciceFlag) RawNumber() ([]float64, error) {
|
||||
switch f.Raw.(type) {
|
||||
case float64:
|
||||
return []float64{f.Raw.(float64)}, nil
|
||||
case []float64:
|
||||
return f.Raw.([]float64), nil
|
||||
case int64:
|
||||
return []float64{float64(f.Raw.(int64))}, nil
|
||||
case []int64:
|
||||
var res []float64
|
||||
for _, raw := range f.Raw.([]int64) {
|
||||
res = append(res, float64(raw))
|
||||
}
|
||||
return res, nil
|
||||
case string:
|
||||
if v, err := strconv.ParseFloat(f.Raw.(string), 64); err == nil {
|
||||
return []float64{v}, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
case []string:
|
||||
var res []float64
|
||||
for _, raw := range f.Raw.([]string) {
|
||||
if v, err := strconv.ParseFloat(raw, 64); err == nil {
|
||||
res = append(res, v)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid raw type: %T", f.Raw)
|
||||
}
|
||||
}
|
||||
|
||||
// ExerciceFlagChoice holds informations about a choice (for MCQ and UCQ).
|
||||
type ExerciceFlagChoice struct {
|
||||
ExerciceFlag
|
||||
|
|
|
|||
Reference in a new issue