✅ Tester getObjectives
parent
c1624d3a84
commit
777ddbc7b7
|
@ -1,5 +1,8 @@
|
|||
import {expect} from 'chai'
|
||||
import {enrichRule} from '../source/engine/rules'
|
||||
import {enrichRule, collectMissingVariables, getObjectives} from '../source/engine/rules'
|
||||
import {analyseSituation} from '../source/engine/traverse'
|
||||
|
||||
let stateSelector = (state, name) => null
|
||||
|
||||
describe('enrichRule', function() {
|
||||
|
||||
|
@ -19,3 +22,20 @@ describe('enrichRule', function() {
|
|||
expect(enrichRule(rule)).to.have.property('subquestion','<p><strong>wut</strong></p>\n')
|
||||
});
|
||||
});
|
||||
|
||||
describe('collectMissingVariables', function() {
|
||||
|
||||
it('should derive objectives from the root rule', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [3259, "dix"]}, espace: "top"},
|
||||
{nom: "dix", formule: "cinq", espace: "top"},
|
||||
{nom: "cinq", espace: "top"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
situation = analyseSituation(rules,"startHere")(stateSelector),
|
||||
result = getObjectives(situation)
|
||||
|
||||
expect(result).to.have.lengthOf(1)
|
||||
expect(result[0]).to.have.property('name','dix')
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -117,12 +117,14 @@ export let getObjectives = analysedSituation => {
|
|||
let formuleType = R.path(["formule", "explanation", "name"])(
|
||||
analysedSituation
|
||||
)
|
||||
return formuleType == "somme"
|
||||
let result = formuleType == "somme"
|
||||
? R.pluck(
|
||||
"explanation",
|
||||
R.path(["formule", "explanation", "explanation"])(analysedSituation)
|
||||
)
|
||||
: formuleType ? [analysedSituation] : null
|
||||
|
||||
return R.reject(R.isNil)(result)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue