From 863d6a71986e4ed27d4c1e0bb9474d8311f9a343 Mon Sep 17 00:00:00 2001 From: mama Date: Wed, 16 Aug 2017 15:47:12 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20R=C3=A9solution=20du=20bug=20de=20getOb?= =?UTF-8?q?jectives=20qui=20demandait=20un=20hack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notamment dans generateQuestions.js --- source/engine/generateQuestions.js | 8 +++---- test/generateQuestions.test.js | 29 ++++++++--------------- test/mecanisms.test.js | 6 ++--- test/mécanismes/aiguillage-numérique.yaml | 7 ++++++ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index 7facf3168..89e8525bd 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -41,18 +41,16 @@ export let analyse = rootVariable => R.pipe( */ // On peut travailler sur une somme, les objectifs sont alors les variables de cette somme. -// Ou sur une variable unique ayant une formule, elle est elle-même le seul objectif +// Ou sur une variable unique ayant une formule ou une conodition 'non applicable si', elle est elle-même le seul objectif export let getObjectives = (situationGate, root, parsedRules) => { - let formuleType = R.path(["formule", "explanation", "name"])( - root - ) + let formuleType = R.path(["formule", "explanation", "name"])(root) let targets = formuleType == "somme" ? R.pluck( "dottedName", R.path(["formule", "explanation", "explanation"])(root) ) - : formuleType ? [root] : null, + : (root.formule || root['non applicable si']) ? [root.dottedName] : null, names = targets ? R.reject(R.isNil)(targets) : [] let findAndEvaluate = name => evaluateNode(situationGate,parsedRules,findRuleByDottedName(parsedRules,name)) diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index 9fb5fa91f..e229be9dc 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -10,8 +10,7 @@ describe('getObjectives', function() { it('should derive objectives from the root rule', function() { let rawRules = [ - {nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"}, - {nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"}, + {nom: "startHere", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"}, {nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"}, {nom: "ko", espace: "sum . evt"}], rules = rawRules.map(enrichRule), @@ -19,7 +18,7 @@ describe('getObjectives', function() { result = getObjectives(stateSelector, root, parsedRules) expect(result).to.have.lengthOf(1) - expect(result[0]).to.have.property('name','deux') + expect(result[0]).to.have.property('name','startHere') }); }); @@ -28,8 +27,7 @@ describe('collectMissingVariables', function() { it('should identify missing variables', function() { let rawRules = [ - {nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"}, - {nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"}, + {nom: "startHere", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"}, {nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"}, {nom: "ko", espace: "sum . evt"}], rules = rawRules.map(enrichRule), @@ -40,8 +38,7 @@ describe('collectMissingVariables', function() { it('should identify missing variables mentioned in expressions', function() { let rawRules = [ - {nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"}, - {nom: "deux", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"}, + {nom: "startHere", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"}, {nom: "nope", espace: "sum . evt"}, {nom: "nyet", espace: "sum . evt"}], rules = rawRules.map(enrichRule), @@ -54,8 +51,7 @@ describe('collectMissingVariables', function() { it('should ignore missing variables in the formula if not applicable', function() { let rawRules = [ - {nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"}, - {nom: "deux", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"}, + {nom: "startHere", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"}, {nom: "trois", espace: "sum"}], rules = rawRules.map(enrichRule), situation = analyseTopDown(rules,"startHere")(stateSelector), @@ -66,8 +62,7 @@ describe('collectMissingVariables', function() { it('should not report missing variables when "one of these" short-circuits', function() { let rawRules = [ - {nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"}, - {nom: "deux", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"}, + {nom: "startHere", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"}, {nom: "trois", espace: "sum"}], rules = rawRules.map(enrichRule), situation = analyseTopDown(rules,"startHere")(stateSelector), @@ -78,8 +73,7 @@ describe('collectMissingVariables', function() { it('should report missing variables in switch statements', function() { let rawRules = [ - { nom: "startHere", formule: {somme: ["logic"]}, espace: "top"}, - { nom: "logic", formule: {"aiguillage numérique": { + { nom: "startHere", formule: {"aiguillage numérique": { "11 > dix":"1000%", "3 > dix":"1100%", "1 > dix":"1200%" @@ -94,8 +88,7 @@ describe('collectMissingVariables', function() { it('should not report missing variables in switch for consequences of false conditions', function() { let rawRules = [ - { nom: "startHere", formule: {somme: ["logic"]}, espace: "top"}, - { nom: "logic", formule: {"aiguillage numérique": { + { nom: "startHere", formule: {"aiguillage numérique": { "8 > 10":"1000%", "1 > 2":"dix" }}, espace: "top"}, @@ -109,8 +102,7 @@ describe('collectMissingVariables', function() { it('should report missing variables in consequence when its condition is unresolved', function() { let rawRules = [ - { nom: "startHere", formule: { somme: ["logic"] }, espace: "top" }, - { nom: "logic", + { nom: "startHere", formule: { "aiguillage numérique": { "10 > 11": "1000%", @@ -135,8 +127,7 @@ describe('collectMissingVariables', function() { it('should not report missing variables when a switch short-circuits', function() { let rawRules = [ - { nom: "startHere", formule: {somme: ["logic"]}, espace: "top"}, - { nom: "logic", formule: {"aiguillage numérique": { + { nom: "startHere", formule: {"aiguillage numérique": { "11 > 10":"1000%", "3 > dix":"1100%", "1 > dix":"1200%" diff --git a/test/mecanisms.test.js b/test/mecanisms.test.js index b18e38df2..f2eac3361 100644 --- a/test/mecanisms.test.js +++ b/test/mecanisms.test.js @@ -18,10 +18,10 @@ describe('Mécanismes', () => exemples.map(({nom: testTexte, situation, 'valeur attendue': valeur, 'variables manquantes': expectedMissing}) => it(testTexte + '', () => { - let rules = [...battery, {nom: "startHereHack", formule: {somme: [nom]}}].map(enrichRule), + let rules = [...battery].map(enrichRule), state = situation || {}, stateSelector = name => state[name], - analysis = analyseTopDown(rules, "startHereHack")(stateSelector), + analysis = analyseTopDown(rules, nom)(stateSelector), missing = collectMissingVariables()(stateSelector,analysis) // console.log('JSON.stringify(analysis', JSON.stringify(analysis)) @@ -33,7 +33,7 @@ describe('Mécanismes', () => ) if (expectedMissing) { - expect(R.keys(missing)).to.eql(expectedMissing) + expect(R.keys(missing).sort()).to.eql(expectedMissing.sort()) } }) diff --git a/test/mécanismes/aiguillage-numérique.yaml b/test/mécanismes/aiguillage-numérique.yaml index feebd429e..2cdbe345b 100644 --- a/test/mécanismes/aiguillage-numérique.yaml +++ b/test/mécanismes/aiguillage-numérique.yaml @@ -65,6 +65,13 @@ - dégradation mineure - dégradation majeure - montant caution + - nom: variables manquantes même si innaccessibles + situation: + dégradation mineure: non + valeur attendue: null + variables manquantes: + - dégradation majeure + - montant caution