From 03d950cca754789e1398991b2110098d291b5db2 Mon Sep 17 00:00:00 2001 From: Mael Date: Tue, 4 Sep 2018 21:14:56 +0200 Subject: [PATCH] =?UTF-8?q?:gear:=20Retour=20explicite=20de=20true=20ou=20?= =?UTF-8?q?false=20pour=20les=20valeurs=20bool=C3=A9ennes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit oui | non --- source/engine/traverse.js | 1 - source/engine/variables.js | 17 +++++++++-------- test/mécanismes/une-de-ces-conditions.yaml | 2 +- test/variables.test.js | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/engine/traverse.js b/source/engine/traverse.js index a1b153f64..3a4eb9956 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -237,7 +237,6 @@ let evolveCond = (name, rule, rules) => value => { ), nodeValue = explanation.nodeValue, missingVariables = explanation.missingVariables - return rewriteNode(node, nodeValue, explanation, missingVariables) } diff --git a/source/engine/variables.js b/source/engine/variables.js index 5209f494c..0e0127371 100644 --- a/source/engine/variables.js +++ b/source/engine/variables.js @@ -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 } diff --git a/test/mécanismes/une-de-ces-conditions.yaml b/test/mécanismes/une-de-ces-conditions.yaml index 8a80414de..7f88a5a22 100644 --- a/test/mécanismes/une-de-ces-conditions.yaml +++ b/test/mécanismes/une-de-ces-conditions.yaml @@ -29,4 +29,4 @@ dégradation mineure: non dégradation majeure: non valeur attendue: 3000 - variables manquantes: [] \ No newline at end of file + variables manquantes: [] diff --git a/test/variables.test.js b/test/variables.test.js index d0ecad1a2..e36dd54e7 100644 --- a/test/variables.test.js +++ b/test/variables.test.js @@ -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