WIP Ajout d'un test qui passe inversions + composantes...

... mais qui est inefficace, car l'inversion est faite 4 fois.
WIP : logs à enlever
pull/138/head
mama 2017-11-23 14:48:42 +01:00
parent 42f579fc8a
commit 42e927bc53
4 changed files with 51 additions and 12 deletions

View File

@ -34,8 +34,6 @@ export default class Results extends Component {
let {targets} = analysis
clearDict() // pourquoi ??
let onRulePage = R.contains('/regle/')(location.pathname)
return (
<section ref={el => this.el = el} id="results">

View File

@ -402,7 +402,7 @@ let doInversion = (situationGate, parsedRules, v, dottedName) => {
}
let { fixedObjectiveValue, fixedObjectiveRule } = inversion
let fx = x =>
clearDict() && evaluateNode(
console.log('fx') || clearDict() && evaluateNode(
n => dottedName === n ? x : situationGate(n),
parsedRules,
fixedObjectiveRule
@ -423,7 +423,7 @@ let doInversion = (situationGate, parsedRules, v, dottedName) => {
)
)
}
console.log('uniroot', dottedName, inversion.fixedObjective)
let tolerancePercentage = 0.00001,
// cette fonction détermine la racine d'une fonction sans faire trop d'itérations
nodeValue = uniroot(
@ -448,7 +448,6 @@ export let mecanismInversion = dottedName => (recurse, k, v) => {
// avoid the inversion loop !
situationGate(dottedName) == undefined &&
doInversion(situationGate, parsedRules, v, dottedName)
let
collectMissing = () => inversion.inversionMissingVariables,
nodeValue = inversion.nodeValue

View File

@ -92,7 +92,7 @@ let fillFilteredVariableNode = (rules, rule) => (filter, parseResult) => {
// ne pas laisser trop longtemps cette "optimisation" qui tue l'aspect fonctionnel de l'algo
var dict
export let clearDict = () => (dict = {})
export let clearDict = () => dict = console.log('clear dict') || {}
let fillVariableNode = (rules, rule) => parseResult => {
let evaluate = (situation, parsedRules, node) => {
@ -128,15 +128,17 @@ let fillVariableNode = (rules, rule) => parseResult => {
? collectNodeMissing(parsedRule)
: node.missingVariables
let result = cached
? cached
: {
if (cached) {
return cached
}
else {
dict[cacheName] = {
...rewriteNode(node, nodeValue, explanation, collectMissing),
missingVariables
}
dict[cacheName] = result
return result
return dict[cacheName]
}
}
let { fragments } = parseResult,

View File

@ -158,3 +158,43 @@ describe("inversions", () => {
})
})
it("complex inversion with composantes", () => {
let rawRules = dedent`
- nom: net
formule:
multiplication:
assiette: 67 + brut
taux: 80%
- nom: cotisation
formule:
multiplication:
assiette: 67 + brut
composantes:
- attributs:
par: employeur
taux: 100%
- attributs:
par: salarié
taux: 50%
- nom: total
formule: cotisation (employeur) + cotisation (salarié)
- nom: brut
format: euro
formule:
inversion:
avec:
- net
- total
`,
rules = yaml.safeLoad(rawRules).map(enrichRule),
stateSelector = name => ({ net: 2000 }[name]),
analysis = analyse(rules, "total")(stateSelector),
missing = collectMissingVariables(analysis.targets)
expect(analysis.targets[0].nodeValue).to.equal(3750)
expect(missing).to.be.empty
})