From f0a913bf0939e3bf0c8327b11d9871dd33d57654 Mon Sep 17 00:00:00 2001 From: Balthazar Wilson <wilsonba@etu.utc.fr> Date: Sun, 15 Oct 2023 19:25:46 +0200 Subject: [PATCH] fix: handle both swf/scf error and tb error --- comsoc/TieBreak.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/comsoc/TieBreak.go b/comsoc/TieBreak.go index 1edf29a..78f89aa 100644 --- a/comsoc/TieBreak.go +++ b/comsoc/TieBreak.go @@ -28,9 +28,9 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern return func(p Profile) ([]Alternative, error) { //récupération du décompte - count, err := swf(p) - if err != nil { - return nil, err + count, errSWF := swf(p) + if errSWF != nil { + return nil, errSWF } //préparation de la sortie var sortedAlts []Alternative @@ -45,7 +45,10 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern } //Départage for len(bestAlts) > 0 { - bestAlt, _ := tb(bestAlts) + bestAlt, errTB := tb(bestAlts) + if errTB != nil { + return nil, errTB + } //ajout de la meilleure alternative post-tie break sortedAlts = append(sortedAlts, bestAlt) //suppression de l'alternative dans bestAlts @@ -82,16 +85,13 @@ func Test_sWFFactory() { func SCFFactory(scf func(p Profile) ([]Alternative, error), tb func([]Alternative) (Alternative, error)) func(Profile) (Alternative, error) { return func(p Profile) (Alternative, error) { //récupération des meilleures alternatives - bestAlts, err1 := scf(p) - if err1 != nil { - return Alternative(0), err1 + bestAlts, errSCF := scf(p) + if errSCF != nil { + return Alternative(0), errSCF } //récupération de la meilleure alternative - bestAlt, err2 := tb(bestAlts) - if err2 != nil { - return Alternative(0), err2 - } - return bestAlt, nil + bestAlt, errTB := tb(bestAlts) + return bestAlt, errTB } } func Test_sCFFactory() { -- GitLab