From 7a347cef20379753f4e55769e8cde7521a43ebf3 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 14 Apr 2018 13:24:35 +0200 Subject: [PATCH] =?UTF-8?q?Corrige=20l'=C3=A9valuation=20des=20variables?= =?UTF-8?q?=20manquantes=20des=20variations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/mecanisms.js | 4 +++- test/generateQuestions.test.js | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 56255c970..6b1836992 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -21,6 +21,7 @@ import { evolve, curry, filter, + all, pipe, head, isEmpty, @@ -152,6 +153,7 @@ let devariate = (recurse, k, v) => { } let explanation = map(evaluateOne, node.explanation), + candidates = filter(node => node.condition.nodeValue !== false, explanation), satisfied = filter(node => node.condition.nodeValue, explanation), choice = head(satisfied), nodeValue = choice ? choice.nodeValue : null @@ -159,7 +161,7 @@ let devariate = (recurse, k, v) => { let leftMissing = choice ? {} : mergeAllMissing(pluck('condition', explanation)), - rightMissing = mergeAllMissing(satisfied), + rightMissing = mergeAllMissing(candidates), missingVariables = mergeMissing(bonus(leftMissing), rightMissing) return rewriteNode(node, nodeValue, explanation, missingVariables) diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index e170835a0..3b804f8f2 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -160,19 +160,20 @@ describe('collectMissingVariables', function() { formule: { barème: { assiette: 2008, - 'multiplicateur des tranches': 1000, variations: [ { si: 'dix', + 'multiplicateur des tranches': 'deux', tranches: [ { 'en-dessous de': 1, taux: 0.1 }, - { de: 1, à: 2, taux: 'deux' }, + { de: 1, à: 2, taux: 'trois' }, , { 'au-dessus de': 2, taux: 10 } ] }, { si: '3 > 4', + 'multiplicateur des tranches': 'quatre', tranches: [ { 'en-dessous de': 1, taux: 0.1 }, { de: 1, à: 2, taux: 1.8 }, @@ -185,14 +186,19 @@ describe('collectMissingVariables', function() { } }, { nom: 'dix', espace: 'top' }, - { nom: 'deux', espace: 'top' } + { nom: 'deux', espace: 'top' }, + { nom: 'trois', espace: 'top' }, + { nom: 'quatre', espace: 'top' } ], rules = parseAll(rawRules.map(enrichRule)), analysis = analyse(rules, 'startHere')(stateSelector), result = collectMissingVariables(analysis.targets) expect(result).to.have.property('top . dix') - // expect(result).to.have.property('top . deux') - this is a TODO + expect(result).to.have.property('top . deux') + expect(result).not.to.have.property('top . quatre') + // TODO + // expect(result).to.have.property('top . trois') }) it('should not report missing variables in irrelevant variations', function() {