Refactor flags

Both QCM and Key are Flag
This commit is contained in:
nemunaire 2019-01-02 21:51:09 +01:00
commit a66d6885e7
13 changed files with 315 additions and 246 deletions

View file

@ -1,6 +1,7 @@
package fic
import (
"errors"
"fmt"
"time"
)
@ -175,13 +176,30 @@ func (e Exercice) WipeMCQs() (int64, error) {
}
}
// AddDepend insert a new dependency to a given flag.
func (m MCQ) AddDepend(j Flag) (err error) {
return errors.New("Dependancy type not implemented for this flag.")
}
// GetDepends retrieve the flag's dependency list.
func (m MCQ) GetDepends() ([]Flag, error) {
return nil, errors.New("Dependancy not implemented for MCQs.")
}
// GetJustifiedFlag searchs for a flag in the scope of the given exercice.
func (c MCQ_entry) GetJustifiedFlag(e Exercice) (Flag, error) {
return e.GetFlagByLabel(fmt.Sprintf("\\%%%d\\%%%%", c.Id))
func (c MCQ_entry) GetJustifiedFlag(e Exercice) (FlagKey, error) {
return e.GetFlagKeyByLabel(fmt.Sprintf("\\%%%d\\%%%%", c.Id))
}
// Check if the given vals are the expected ones to validate this flag.
func (m MCQ) Check(vals map[int64]bool) int {
func (m MCQ) Check(v interface{}) int {
var vals map[int64]bool
if va, ok := v.(map[int64]bool); !ok {
return -1
} else {
vals = va
}
diff := 0
for _, n := range m.Entries {