🐛 Mise en évidence de la mauvaise implémentation des périodes
parent
eed6c574db
commit
d92c383fa4
|
@ -131,18 +131,24 @@ export let treatVariableTransforms = (rules, rule) => parseResult => {
|
|||
let calledPeriod = ruleToTransform['période'] || environmentPeriod
|
||||
|
||||
let transformedNodeValue =
|
||||
callingPeriod === 'mois' && calledPeriod === 'année'
|
||||
? nodeValue / 12
|
||||
: callingPeriod === 'année' && calledPeriod === 'mois'
|
||||
? nodeValue * 12
|
||||
: nodeValue
|
||||
callingPeriod === 'mois' && calledPeriod === 'année'
|
||||
? nodeValue / 12
|
||||
: callingPeriod === 'année' && calledPeriod === 'mois'
|
||||
? nodeValue * 12
|
||||
: nodeValue,
|
||||
periodTransform = nodeValue !== transformedNodeValue
|
||||
|
||||
return rewriteNode(
|
||||
filteredNode,
|
||||
let result = rewriteNode(
|
||||
{
|
||||
...filteredNode,
|
||||
periodTransform: periodTransform,
|
||||
...(periodTransform ? { originPeriodValue: nodeValue } : {})
|
||||
},
|
||||
transformedNodeValue,
|
||||
filteredNode.explanation,
|
||||
filteredNode.missingVariables
|
||||
)
|
||||
return result
|
||||
}
|
||||
let node = treatVariable(rules, rule, parseResult.filter)(
|
||||
parseResult.variable || parseResult
|
||||
|
|
|
@ -128,17 +128,18 @@ describe('library', function() {
|
|||
expect(value).to.equal(7253.26)
|
||||
})
|
||||
it('should let let user define a rule base on a completely different subject', function() {
|
||||
let target = 'impact'
|
||||
let targets = ['impact']
|
||||
|
||||
let value = Syso.evaluate(
|
||||
target,
|
||||
targets,
|
||||
{
|
||||
'nombre de douches': 30,
|
||||
'chauffage . type': 'gaz',
|
||||
'durée de la douche': 7
|
||||
'durée de la douche': 10
|
||||
},
|
||||
{ base: co2 }
|
||||
{ base: co2, debug: true }
|
||||
)
|
||||
console.log(JSON.stringify(value.targets[0], null, 4))
|
||||
expect(value).to.equal(7253.26)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,6 +1,34 @@
|
|||
# This is not a mecanism test, but we make use of the simplicity of declaring tests in YAML, only available for mecanisms for now
|
||||
|
||||
|
||||
- test: impact des douches
|
||||
période: année
|
||||
formule: 1 * nombre de douches
|
||||
|
||||
exemples:
|
||||
- situation:
|
||||
nombre de douches: 30
|
||||
valeur attendue: 360
|
||||
|
||||
- nom: nombre de douches
|
||||
période: mois
|
||||
question: Combien prenez-vous de douches par mois ?
|
||||
format: nombre
|
||||
suggestions:
|
||||
- 30
|
||||
|
||||
- nom: impact par douche
|
||||
formule: 1
|
||||
unité: kgCO2e
|
||||
|
||||
- test: impact des douches erroné
|
||||
période: année
|
||||
formule: impact par douche * nombre de douches
|
||||
exemples:
|
||||
- situation:
|
||||
nombre de douches: 30
|
||||
valeur attendue: 360
|
||||
|
||||
- nom: assiette mensuelle
|
||||
période: mois
|
||||
format: €
|
||||
|
|
Loading…
Reference in New Issue