2017-11-06 17:05:45 +00:00
|
|
|
import { expect } from "chai"
|
|
|
|
import { enrichRule } from "../source/engine/rules"
|
|
|
|
import { analyseSituation } from "../source/engine/traverse"
|
|
|
|
import yaml from "js-yaml"
|
|
|
|
import dedent from 'dedent-js'
|
|
|
|
|
|
|
|
describe("inversions", () => {
|
|
|
|
/*
|
|
|
|
it("should handle non inverted example", () => {
|
|
|
|
let fakeState = { brut: 2300 }
|
|
|
|
let stateSelector = name => fakeState[name]
|
|
|
|
|
|
|
|
let
|
|
|
|
rawRules = dedent`
|
|
|
|
- nom: net
|
|
|
|
formule:
|
|
|
|
multiplication:
|
|
|
|
assiette: brut
|
|
|
|
taux: 77%
|
|
|
|
|
|
|
|
- nom: brut
|
|
|
|
format: euro
|
|
|
|
`,
|
|
|
|
rules = yaml.safeLoad(rawRules).map(enrichRule),
|
|
|
|
analysis = analyseSituation(rules, "net")(stateSelector)
|
|
|
|
|
|
|
|
expect(analysis.nodeValue).to.be.closeTo(1771, 0.001)
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
|
|
|
|
it("should handle inversions", () => {
|
|
|
|
let fakeState = { net: 2000 }
|
|
|
|
let stateSelector = name => fakeState[name]
|
|
|
|
|
|
|
|
let
|
|
|
|
rawRules = dedent`
|
|
|
|
- nom: net
|
|
|
|
formule:
|
|
|
|
multiplication:
|
|
|
|
assiette: brut
|
|
|
|
taux: 77%
|
|
|
|
|
|
|
|
- nom: brut
|
|
|
|
format: euro
|
2017-11-06 19:12:08 +00:00
|
|
|
inversions possibles:
|
2017-11-06 17:05:45 +00:00
|
|
|
- net
|
|
|
|
`,
|
|
|
|
rules = yaml.safeLoad(rawRules).map(enrichRule),
|
|
|
|
analysis = analyseSituation(rules, "brut")(stateSelector)
|
|
|
|
|
2017-11-06 19:12:08 +00:00
|
|
|
expect(analysis.nodeValue).to.be.closeTo(2000/(77/100), 0.0001*2000)
|
2017-11-06 17:05:45 +00:00
|
|
|
})
|
|
|
|
})
|