Corrige l'évaluation des variables manquantes des variations

pull/197/head
Laurent Bossavit 2018-04-14 13:24:35 +02:00
parent 2d60dc5136
commit 7a347cef20
2 changed files with 13 additions and 5 deletions

View File

@ -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)

View File

@ -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() {