Changement de comportement sur "logique numérique"

Retour au même algo de collecte des variables manquantes: même si la
condition est non résolue (il manque une variable), on collecte quand
même les variables manquantes de sa conséquence.
Ajout d'un test
pull/19/head
mama 2017-08-02 14:41:00 +02:00
parent f884f6a319
commit 358e2200af
2 changed files with 48 additions and 22 deletions

View File

@ -136,28 +136,28 @@ export let mecanismNumericalLogic = (recurse, k,v) => {
conditionNode = recurse(condition), // can be a 'comparison', a 'variable', TODO a 'negation'
consequenceNode = mecanismNumericalLogic(recurse, condition, consequence)
let evaluate = (situationGate, parsedRules, node) => {
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),
consequence: R.curry(evaluateNode)(situationGate, parsedRules)
},node.explanation)
return {
...node,
collectMissing,
explanation,
nodeValue: explanation.consequence.nodeValue,
condValue: explanation.condition.nodeValue
}
let evaluate = (situationGate, parsedRules, node) => {
let collectMissing = node => {
let missingOnTheLeft = collectNodeMissing(node.explanation.condition),
investigate = node.explanation.condition.nodeValue !== false,
missingOnTheRight = investigate ? collectNodeMissing(node.explanation.consequence) : []
return R.concat(missingOnTheLeft, missingOnTheRight)
}
let explanation = R.evolve({
condition: R.curry(evaluateNode)(situationGate, parsedRules),
consequence: R.curry(evaluateNode)(situationGate, parsedRules)
},node.explanation)
return {
...node,
collectMissing,
explanation,
nodeValue: explanation.consequence.nodeValue,
condValue: explanation.condition.nodeValue
}
}
let jsx = (nodeValue, {condition, consequence}) =>
<div className="condition">
{makeJsx(condition)}

View File

@ -109,6 +109,32 @@ describe('collectMissingVariables', function() {
expect(result).to.deep.equal({})
});
it('should report missing variables in consequence even if its condition is unresolved', function() {
let rawRules = [
{ nom: "startHere", formule: { somme: ["logic"] }, espace: "top" },
{ nom: "logic",
formule: {
"logique numérique": {
"10 > 11": "1000%",
"3 > dix": {
"douze": "560%",
"1 > 2": "75015%" }
}
},
espace: "top"
},
{ nom: "douze", 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')
expect(result).to.have.property('top . douze')
});
it('should not report missing variables when a switch short-circuits', function() {
let rawRules = [
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
@ -155,8 +181,8 @@ describe('buildNextSteps', function() {
expect(R.path(["question","props","label"])(result[1])).to.equal("Quel est le motif de recours au CDD ?")
expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est le salaire brut ?")
expect(R.path(["question","props","label"])(result[3])).to.equal("Est-ce un contrat jeune vacances ?")
expect(R.path(["question","props","label"])(result[4])).to.equal("Combien de jours de congés ne seront pas pris ?")
expect(R.path(["question","props","label"])(result[5])).to.equal("Quelle est la durée du contrat ?")
expect(R.path(["question","props","label"])(result[4])).to.equal("Quelle est la durée du contrat ?")
expect(R.path(["question","props","label"])(result[5])).to.equal("Combien de jours de congés ne seront pas pris ?")
});
});