From 358e2200af31b4880bb1f1d8017f48cb7c0d33f2 Mon Sep 17 00:00:00 2001 From: mama Date: Wed, 2 Aug 2017 14:41:00 +0200 Subject: [PATCH] =?UTF-8?q?Changement=20de=20comportement=20sur=20"logique?= =?UTF-8?q?=20num=C3=A9rique"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Retour au même algo de collecte des variables manquantes: même si la condition est non résolue (il manque une variable), on collecte quand même les variables manquantes de sa conséquence. Ajout d'un test --- source/engine/mecanisms.js | 40 +++++++++++++++++----------------- test/generateQuestions.test.js | 30 +++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 6a82194d7..d58d6f5b2 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -136,28 +136,28 @@ export let mecanismNumericalLogic = (recurse, k,v) => { conditionNode = recurse(condition), // can be a 'comparison', a 'variable', TODO a 'negation' consequenceNode = mecanismNumericalLogic(recurse, condition, consequence) - let evaluate = (situationGate, parsedRules, node) => { - let collectMissing = node => { - let leftMissing = collectNodeMissing(node.explanation.condition), - investigate = node.explanation.condition.nodeValue == true, - rightMissing = investigate ? collectNodeMissing(node.explanation.consequence) : [] - return R.concat(leftMissing, rightMissing) - } - - let explanation = R.evolve({ - condition: R.curry(evaluateNode)(situationGate, parsedRules), - consequence: R.curry(evaluateNode)(situationGate, parsedRules) - },node.explanation) - - return { - ...node, - collectMissing, - explanation, - nodeValue: explanation.consequence.nodeValue, - condValue: explanation.condition.nodeValue - } + let evaluate = (situationGate, parsedRules, node) => { + let collectMissing = node => { + let missingOnTheLeft = collectNodeMissing(node.explanation.condition), + investigate = node.explanation.condition.nodeValue !== false, + missingOnTheRight = investigate ? collectNodeMissing(node.explanation.consequence) : [] + return R.concat(missingOnTheLeft, missingOnTheRight) } + let explanation = R.evolve({ + condition: R.curry(evaluateNode)(situationGate, parsedRules), + consequence: R.curry(evaluateNode)(situationGate, parsedRules) + },node.explanation) + + return { + ...node, + collectMissing, + explanation, + nodeValue: explanation.consequence.nodeValue, + condValue: explanation.condition.nodeValue + } + } + let jsx = (nodeValue, {condition, consequence}) =>
{makeJsx(condition)} diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index 655c673de..bf1d0b4cd 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -109,6 +109,32 @@ describe('collectMissingVariables', function() { expect(result).to.deep.equal({}) }); + it('should report missing variables in consequence even if its condition is unresolved', function() { + let rawRules = [ + { nom: "startHere", formule: { somme: ["logic"] }, espace: "top" }, + { nom: "logic", + formule: { + "logique numérique": { + "10 > 11": "1000%", + "3 > dix": { + "douze": "560%", + "1 > 2": "75015%" } + } + }, + espace: "top" + }, + { nom: "douze", espace: "top" }, + { nom: "dix", espace: "top" } + ], + rules = rawRules.map(enrichRule), + situation = analyseTopDown(rules, "startHere")(stateSelector), + result = collectMissingVariables()(stateSelector, situation); + + + expect(result).to.have.property('top . dix') + expect(result).to.have.property('top . douze') + }); + it('should not report missing variables when a switch short-circuits', function() { let rawRules = [ { nom: "startHere", formule: {somme: ["logic"]}, espace: "top"}, @@ -155,8 +181,8 @@ describe('buildNextSteps', function() { expect(R.path(["question","props","label"])(result[1])).to.equal("Quel est le motif de recours au CDD ?") expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est le salaire brut ?") expect(R.path(["question","props","label"])(result[3])).to.equal("Est-ce un contrat jeune vacances ?") - expect(R.path(["question","props","label"])(result[4])).to.equal("Combien de jours de congés ne seront pas pris ?") - expect(R.path(["question","props","label"])(result[5])).to.equal("Quelle est la durée du contrat ?") + expect(R.path(["question","props","label"])(result[4])).to.equal("Quelle est la durée du contrat ?") + expect(R.path(["question","props","label"])(result[5])).to.equal("Combien de jours de congés ne seront pas pris ?") }); });