🐛 Ajout d'un test qui casse

Est-ce le tryptique inversion + double filtre ??
pull/513/head
Mael 2019-04-11 18:23:05 +02:00
parent 87837ee2a3
commit 76ddaaf8fb
3 changed files with 96 additions and 19 deletions

View File

@ -1,13 +1,35 @@
import { ShowValuesConsumer } from 'Components/rule/ShowValuesContext';
import { evaluateControls } from 'Engine/controls';
import { chain, cond, evolve, is, keys, map, mergeAll, path, pick, pipe, T } from 'ramda';
import React from 'react';
import { bonus, evaluateNode, makeJsx, mergeMissing, rewriteNode } from './evaluation';
import { Node } from './mecanismViews/common';
import { disambiguateRuleReference, findParentDependency, findRule, findRuleByDottedName } from './rules';
import { anyNull, undefOrTrue, val } from './traverse-common-functions';
import { treatNumber, treatObject, treatOther, treatString } from './treat';
import { ShowValuesConsumer } from 'Components/rule/ShowValuesContext'
import { evaluateControls } from 'Engine/controls'
import {
chain,
cond,
evolve,
is,
keys,
map,
mergeAll,
path,
pick,
pipe,
T
} from 'ramda'
import React from 'react'
import {
bonus,
evaluateNode,
makeJsx,
mergeMissing,
rewriteNode
} from './evaluation'
import { Node } from './mecanismViews/common'
import {
disambiguateRuleReference,
findParentDependency,
findRule,
findRuleByDottedName
} from './rules'
import { anyNull, undefOrTrue, val } from './traverse-common-functions'
import { treatNumber, treatObject, treatOther, treatString } from './treat'
/*
Dans ce fichier, les règles YAML sont parsées.

View File

@ -108,9 +108,7 @@ export let treatVariable = (rules, rule, filter) => parseResult => {
// TODO - the implementations of filters is really bad. It injects a hack in the situation to make the composante mecanism compute only one of its branch. It is then stored in the cache under a new key, dottedName.filter. This mecanism should just query the variable tree to get the active composante's value...
//
window.count = 0
export let treatVariableTransforms = (rules, rule) => parseResult => {
window.count += 1
let evaluateTransforms = originalEval => (
cache,
situation,

View File

@ -2,12 +2,66 @@ import { expect } from 'chai'
import { enrichRule } from 'Engine/rules'
import { rules as realRules } from '../source/engine/rules'
import { analyse, analyseMany, parseAll } from '../source/engine/traverse'
import dedent from 'dedent-js'
import { safeLoad } from 'js-yaml'
describe('bug-analyse-many', function() {
it.only('should compute the same contributions if asked with analyseMany or analyse', function() {
it('complex inversion with composantes', () => {
let rawRules = dedent`
- nom: net
formule: brut - cotisations
- nom: cotisations
formule:
somme:
- cotisation a (salarié)
- cotisation b
- nom: cotisation a
formule:
multiplication:
assiette: brut
composantes:
- attributs:
par: employeur
taux: 10%
- attributs:
par: salarié
taux: 10%
- nom: cotisation b
formule:
multiplication:
assiette: brut
composantes:
- attributs:
impôt sur le revenu: x
taux: 10%
- attributs:
impôt sur le revenu: y
taux: 10%
- nom: brut
format: euro
formule:
inversion numérique:
avec:
- net
`,
rules = parseAll(safeLoad(rawRules).map(enrichRule)),
stateSelector = name => ({ net: 700 }[name])
const targets = ['brut', 'cotisations']
const many = analyseMany(rules, targets)(stateSelector).targets
const one = analyse(rules, 'cotisations')(stateSelector).targets[0]
//console.log(many[0].nodeValue, many[1].nodeValue, one.nodeValue)
expect(many[1].nodeValue).to.be.closeTo(one.nodeValue, 0.1)
})
it('should compute the same contributions if asked with analyseMany or analyse', function() {
const situationSelector = dottedName =>
({
'contrat salarié . salaire . net après impôt': 10000,
'contrat salarié . rémunération . net de cotisations': 3500,
'auto entrepreneur': 'non',
'contrat salarié': 'oui',
'contrat salarié . assimilé salarié': 'oui',
@ -25,14 +79,17 @@ describe('bug-analyse-many', function() {
}[dottedName])
const rules = parseAll(realRules.map(enrichRule))
const targets = [
"entreprise . chiffre d'affaires",
'contrat salarié . cotisations'
'contrat salarié . salaire . brut de base',
'contrat salarié . cotisations . salariales'
]
const analyseManyValue = analyseMany(rules, targets)(situationSelector)
.targets[1]
const analyseValue = analyse(rules, 'contrat salarié . cotisations')(
situationSelector
).targets[0]
const analyseValue = analyse(
rules,
'contrat salarié . cotisations . salariales'
)(situationSelector).targets[0]
console.log(analyseManyValue.nodeValue, analyseValue.nodeValue)
expect(analyseManyValue.nodeValue).to.equal(analyseValue.nodeValue)
})
})