⚙️ Retour explicite de true ou false pour les valeurs booléennes

oui | non
pull/281/head
Mael 2018-09-04 21:14:56 +02:00
parent 5d4a7d0d6e
commit 03d950cca7
4 changed files with 12 additions and 12 deletions

View File

@ -237,7 +237,6 @@ let evolveCond = (name, rule, rules) => value => {
),
nodeValue = explanation.nodeValue,
missingVariables = explanation.missingVariables
return rewriteNode(node, nodeValue, explanation, missingVariables)
}

View File

@ -18,8 +18,10 @@ let evaluateBottomUp = situationGate => startingFragments => {
])
: situationGate(query) == expectedResult
}
return rec(startingFragments)
}
let formatBooleanValue = { oui: true, non: false }
/* Evalue la valeur d'une variable
en utilisant la fonction situationGate qui donne accès à la situation courante*/
@ -27,12 +29,11 @@ export let evaluateVariable = (situationGate, variableName, rule) => {
// test rec
let value = situationGate(variableName)
return rule.format != null
? value
: !rule.formule
? // c'est une variante, eg. motifs . classique . accroissement d'activité
evaluateBottomUp(situationGate)(splitName(variableName))
: rule.formule['une possibilité']
? evaluateBottomUp(situationGate)(splitName(variableName))
: value
if (rule.format != null) return value
//boolean variables don't have a format prop, it's the default
if (formatBooleanValue[value] !== undefined) return formatBooleanValue[value]
if (rule.formule && rule.formule['une possibilité'])
return evaluateBottomUp(situationGate)(splitName(variableName))
return value
}

View File

@ -29,4 +29,4 @@
dégradation mineure: non
dégradation majeure: non
valeur attendue: 3000
variables manquantes: []
variables manquantes: []

View File

@ -18,9 +18,9 @@ describe('evaluateVariable', function() {
expect(evaluateVariable(situationGate, 'condition', rule)).to.be.true
})
it("should interpret rules without a formula as boolean-valued, with values other than 'oui' meaning false", function() {
it("should interpret rules without a formula as boolean-valued, with 'non' meaning false", function() {
let rule = {},
state = { condition: 'nope' },
state = { condition: 'non' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'condition', rule)).to.be.false