🐛 Répare la collecte des variables manquantes des logiques numériques

pull/21/head
Laurent Bossavit 2017-07-28 11:42:57 +02:00
parent fcd68fe72c
commit d5a1e08c72
2 changed files with 59 additions and 3 deletions

View File

@ -137,8 +137,12 @@ export let mecanismNumericalLogic = (recurse, k,v) => {
consequenceNode = mecanismNumericalLogic(recurse, condition, consequence)
let evaluate = (situationGate, parsedRules, node) => {
let collectMissing = node =>
R.concat(collectNodeMissing(conditionNode),collectNodeMissing(consequenceNode))
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),
@ -179,7 +183,11 @@ export let mecanismNumericalLogic = (recurse, k,v) => {
choice = R.find(node => node.condValue, explanation),
nodeValue = choice ? choice.nodeValue : null
let collectMissing = node => R.chain(collectNodeMissing,node.explanation)
let collectMissing = node => {
let choice = R.find(node => node.condValue, node.explanation)
return choice ? collectNodeMissing(choice) : R.chain(collectNodeMissing,node.explanation)
}
return rewriteNode(node,nodeValue,explanation,collectMissing)
}

View File

@ -77,6 +77,54 @@ describe('collectMissingVariables', function() {
expect(result).to.be.empty
});
it('should report missing variables in switch statements', function() {
let rawRules = [
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
{ nom: "logic", formule: {"logique numérique": {
"11 > dix":"1000%",
"3 > dix":"1100%",
"1 > dix":"1200%"
}}, 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')
});
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: {"logique numérique": {
"11 > 10":"1000%",
"3 > 1":"1100%",
"1 > 2":"dix"
}}, espace: "top"},
{nom: "dix", espace: "top"}],
rules = rawRules.map(enrichRule),
situation = analyseTopDown(rules,"startHere")(stateSelector),
result = collectMissingVariables()(stateSelector,situation)
expect(result).to.be.empty
});
it('should not report missing variables when a switch short-circuits', function() {
let rawRules = [
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
{ nom: "logic", formule: {"logique numérique": {
"11 > 10":"1000%",
"3 > dix":"1100%",
"1 > dix":"1200%"
}}, espace: "top"},
{nom: "dix", espace: "top"}],
rules = rawRules.map(enrichRule),
situation = analyseTopDown(rules,"startHere")(stateSelector),
result = collectMissingVariables()(stateSelector,situation)
expect(result).to.be.empty
});
});
describe('buildNextSteps', function() {