diff --git a/source/engine/evaluation.js b/source/engine/evaluation.js index b15556d14..03d3771c5 100644 --- a/source/engine/evaluation.js +++ b/source/engine/evaluation.js @@ -79,6 +79,13 @@ export let evaluateArrayWithFilter = (evaluationFilter, reducer, start) => ( return rewriteNode(node, nodeValue, explanation, missingVariables) } +export let defaultNode = nodeValue => ({ + nodeValue, + // eslint-disable-next-line + jsx: nodeValue => {nodeValue}, + isDefault: true +}) + export let parseObject = (recurse, objectShape, value) => { let recurseOne = key => defaultValue => { if (!value[key] && !defaultValue) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index ab844fb80..d4383c6d3 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -48,7 +48,8 @@ import { collectNodeMissing, mergeAllMissing, mergeMissing, - bonus + bonus, + defaultNode } from './evaluation' import { findRuleByName, @@ -68,12 +69,6 @@ import { trancheValue } from './mecanisms/barème' import buildSelectionView from './mecanismViews/Selection' import uniroot from './uniroot' -let constantNode = constant => ({ - nodeValue: constant, - // eslint-disable-next-line - jsx: nodeValue => {nodeValue} -}) - let decompose = (recurse, k, v) => { let subProps = dissoc('composantes')(v), explanation = v.composantes.map(c => ({ @@ -583,8 +578,8 @@ export let mecanismSum = (recurse, k, v) => { export let mecanismReduction = (recurse, k, v) => { let objectShape = { assiette: false, - abattement: constantNode(0), - franchise: constantNode(0), + abattement: defaultNode(0), + franchise: defaultNode(0) } let effect = ({ assiette, abattement, franchise, décote }) => { @@ -650,9 +645,9 @@ export let mecanismProduct = (recurse, k, v) => { let objectShape = { assiette: false, - taux: constantNode(1), - facteur: constantNode(1), - plafond: constantNode(Infinity) + taux: defaultNode(1), + facteur: defaultNode(1), + plafond: defaultNode(Infinity) } let effect = ({ assiette, taux, facteur, plafond }) => { let mult = (base, rate, facteur, plafond) => @@ -684,7 +679,7 @@ export let mecanismProduct = (recurse, k, v) => { {makeJsx(explanation.assiette)} - {explanation.taux.explanation && ( + {!explanation.taux.isDefault && (
  • taux:{' '} @@ -692,7 +687,7 @@ export let mecanismProduct = (recurse, k, v) => { {makeJsx(explanation.taux)}
  • )} - {explanation.facteur.explanation && ( + {!explanation.facteur.isDefault && (
  • facteur:{' '} @@ -700,7 +695,7 @@ export let mecanismProduct = (recurse, k, v) => { {makeJsx(explanation.facteur)}
  • )} - {explanation.plafond.explanation && ( + {!explanation.plafond.isDefault && (
  • plafond:{' '} @@ -800,7 +795,7 @@ export let mecanismScale = (recurse, k, v) => { let tranches = desugarScale(recurse)(v['tranches']), objectShape = { assiette: false, - multiplicateur: constantNode(1) + multiplicateur: defaultNode(1) } let effect = ({ assiette, multiplicateur: multiplicateur, tranches }) => { @@ -831,7 +826,7 @@ export let mecanismScale = (recurse, k, v) => { export let mecanismContinuousScale = (recurse, k, v) => { let objectShape = { assiette: false, - multiplicateur: constantNode(1) + multiplicateur: defaultNode(1) } let effect = ({ assiette, multiplicateur, points }) => { if (anyNull([assiette, multiplicateur])) return null diff --git a/test/mécanismes/multiplication.yaml b/test/mécanismes/multiplication.yaml index 1dcfec6ea..9327ab07a 100644 --- a/test/mécanismes/multiplication.yaml +++ b/test/mécanismes/multiplication.yaml @@ -84,18 +84,21 @@ valeur attendue: 1 -# TODO implémenter les taux variables -# - nom: mon taux -# format: pourcentage -# - test: Multiplication simple -# formule: -# multiplication: -# assiette: mon assiette -# taux: mon taux -# -# exemples: -# - nom: exemple -# situation: -# mon assiette: 100 -# mon taux: 3% -# valeur attendue: 3 +# This should work, but with the use of objectShape & co, the short circuits are not performed +- test: Multiplication complète + formule: + multiplication: + assiette: mon assiette + facteur: mon facteur + plafond: mon plafond + taux: 0.5% + + exemples: + - nom: Assiette manquante + situation: + mon facteur: 0 + mon plafond: 100 + valeur attendue: 0 + variables manquantes: [] + +