From 777ddbc7b79e83905abda7aefa352401d85921df Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Wed, 28 Jun 2017 16:12:10 +0200 Subject: [PATCH] :white_check_mark: Tester getObjectives --- __tests__/rules.test.js | 22 +++++++++++++++++++++- source/engine/rules.js | 4 +++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/__tests__/rules.test.js b/__tests__/rules.test.js index 786e75918..796ea56ec 100644 --- a/__tests__/rules.test.js +++ b/__tests__/rules.test.js @@ -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','

wut

\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') + }); + +}); diff --git a/source/engine/rules.js b/source/engine/rules.js index a3e999caf..190b933ce 100644 --- a/source/engine/rules.js +++ b/source/engine/rules.js @@ -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) }