Merge pull request #58 from sgmap/fix-caching-filtered
Corrige la mise en cache des variables filtréespull/61/head
commit
f2bb7cf6e1
|
@ -74,7 +74,9 @@ let fillVariableNode = (rules, rule) => (parseResult) => {
|
|||
let dottedName = node.dottedName,
|
||||
// On va vérifier dans le cache courant, dict, si la variable n'a pas été déjà évaluée
|
||||
// En effet, l'évaluation dans le cas d'une variable qui a une formule, est coûteuse !
|
||||
cached = dict[dottedName],
|
||||
filter = situation("sys.filter"),
|
||||
cacheName = dottedName + (filter ? "." + filter: ""),
|
||||
cached = dict[cacheName],
|
||||
// make parsedRules a dict object, that also serves as a cache of evaluation ?
|
||||
variable = cached ? cached : findRuleByDottedName(parsedRules, dottedName),
|
||||
variableIsCalculable = variable.formule != null,
|
||||
|
@ -101,7 +103,7 @@ let fillVariableNode = (rules, rule) => (parseResult) => {
|
|||
...rewriteNode(node,nodeValue,explanation,collectMissing),
|
||||
missingVariables,
|
||||
}
|
||||
dict[dottedName] = result
|
||||
dict[cacheName] = result
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {expect} from 'chai'
|
||||
import {enrichRule} from '../source/engine/rules'
|
||||
import {analyseSituation} from '../source/engine/traverse'
|
||||
import {rules as realRules, enrichRule} from '../source/engine/rules'
|
||||
import {analyseSituation, analyseTopDown} from '../source/engine/traverse'
|
||||
|
||||
let stateSelector = (state, name) => null
|
||||
|
||||
|
@ -219,4 +219,25 @@ describe('analyseSituation with mecanisms', function() {
|
|||
expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',50+400+40)
|
||||
});
|
||||
|
||||
it('should compute consistent values', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", espace: "top", formule: "composed (salarié) + composed (employeur)"},
|
||||
{nom: "orHere", espace: "top", formule: "composed"},
|
||||
{nom: "composed", espace: "top", formule: {"barème": {
|
||||
assiette:2008,
|
||||
"multiplicateur des tranches":1000,
|
||||
composantes: [
|
||||
{tranches:[{"en-dessous de":1, taux: 0.05},{de:1, "à": 2, taux: 0.4}, ,{"au-dessus de":2, taux: 5}],
|
||||
attributs: {"dû par":"salarié"}
|
||||
},
|
||||
{tranches:[{"en-dessous de":1, taux: 0.05},{de:1, "à": 2, taux: 0.8}, ,{"au-dessus de":2, taux: 5}],
|
||||
attributs: {"dû par":"employeur"}
|
||||
}
|
||||
]
|
||||
}}}],
|
||||
rules = rawRules.map(enrichRule)
|
||||
expect(analyseSituation(rules,"orHere")(stateSelector)).to.have.property('nodeValue',100+1200+80)
|
||||
expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',100+1200+80)
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue