From 7ccc8e4e1f787bcb87775686b6c8feeb07ff76b9 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Fri, 28 Jul 2017 15:33:35 +0200 Subject: [PATCH] :white_check_mark: Tester les variables manquantes dans les variations --- source/engine/mecanisms.js | 6 +++-- test/generateQuestions.test.js | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 418212a2a..20a4025ad 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -97,8 +97,10 @@ let devariate = (recurse, k, v) => { nodeValue = choice ? choice.nodeValue : null let collectMissing = node => { - let choice = R.find(node => node.condition.nodeValue, node.explanation) - return choice ? collectNodeMissing(choice) : R.chain(collectNodeMissing,node.explanation) + let choice = R.find(node => node.condition.nodeValue, node.explanation), + leftMissing = choice ? [] : R.chain(collectNodeMissing,R.pluck("condition",node.explanation)), + rightMissing = choice ? collectNodeMissing(choice) : R.chain(collectNodeMissing,node.explanation) + return R.concat(leftMissing,rightMissing) } return rewriteNode(node,nodeValue,explanation,collectMissing) diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index e229be9dc..133a38eae 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -86,6 +86,46 @@ describe('collectMissingVariables', function() { expect(result).to.have.property('top . dix') }); + it('should report missing variables in variations', function() { + let rawRules = [ + {nom: "startHere", formule: {somme: ["variations"]}, espace: "top"}, + {nom: "variations", espace: "top", formule: {"barème": { + assiette:2008, + "multiplicateur des tranches":1000, + "variations":[ + {si: "dix", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: "deux"}, ,{"au-dessus de":2, taux: 10}]}, + {si: "3 > 4", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: 1.8}, ,{"au-dessus de":2, taux: 10}]}, + ] + }}}, + {nom: "dix", espace: "top"}, + {nom: "deux", 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 . deux') - this is a TODO + }); + + it('should not report missing variables in irrelevant variations', function() { + let rawRules = [ + {nom: "startHere", formule: {somme: ["variations"]}, espace: "top"}, + {nom: "variations", espace: "top", formule: {"barème": { + assiette:2008, + "multiplicateur des tranches":1000, + "variations":[ + {si: "dix", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: "deux"}, ,{"au-dessus de":2, taux: 10}]}, + {si: "3 > 2", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: 1.8}, ,{"au-dessus de":2, taux: 10}]}, + ] + }}}, + {nom: "dix", espace: "top"}], + rules = rawRules.map(enrichRule), + situation = analyseTopDown(rules,"startHere")(stateSelector), + result = collectMissingVariables()(stateSelector,situation) + + expect(result).to.deep.equal({}) + }); + it('should not report missing variables in switch for consequences of false conditions', function() { let rawRules = [ { nom: "startHere", formule: {"aiguillage numérique": {