Tester getObjectives

pull/14/head
Laurent Bossavit 2017-06-28 16:12:10 +02:00
parent c1624d3a84
commit 777ddbc7b7
2 changed files with 24 additions and 2 deletions

View File

@ -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')
});
});

View File

@ -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)
}