🐛 Résolution du bug de getObjectives qui demandait un hack
Notamment dans generateQuestions.jspull/37/head
parent
d35ae49274
commit
863d6a7198
|
@ -41,18 +41,16 @@ export let analyse = rootVariable => R.pipe(
|
|||
*/
|
||||
|
||||
// On peut travailler sur une somme, les objectifs sont alors les variables de cette somme.
|
||||
// Ou sur une variable unique ayant une formule, elle est elle-même le seul objectif
|
||||
// Ou sur une variable unique ayant une formule ou une conodition 'non applicable si', elle est elle-même le seul objectif
|
||||
export let getObjectives = (situationGate, root, parsedRules) => {
|
||||
let formuleType = R.path(["formule", "explanation", "name"])(
|
||||
root
|
||||
)
|
||||
let formuleType = R.path(["formule", "explanation", "name"])(root)
|
||||
|
||||
let targets = formuleType == "somme"
|
||||
? R.pluck(
|
||||
"dottedName",
|
||||
R.path(["formule", "explanation", "explanation"])(root)
|
||||
)
|
||||
: formuleType ? [root] : null,
|
||||
: (root.formule || root['non applicable si']) ? [root.dottedName] : null,
|
||||
names = targets ? R.reject(R.isNil)(targets) : []
|
||||
|
||||
let findAndEvaluate = name => evaluateNode(situationGate,parsedRules,findRuleByDottedName(parsedRules,name))
|
||||
|
|
|
@ -10,8 +10,7 @@ describe('getObjectives', function() {
|
|||
|
||||
it('should derive objectives from the root rule', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
||||
{nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
||||
{nom: "startHere", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
||||
{nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
||||
{nom: "ko", espace: "sum . evt"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
|
@ -19,7 +18,7 @@ describe('getObjectives', function() {
|
|||
result = getObjectives(stateSelector, root, parsedRules)
|
||||
|
||||
expect(result).to.have.lengthOf(1)
|
||||
expect(result[0]).to.have.property('name','deux')
|
||||
expect(result[0]).to.have.property('name','startHere')
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -28,8 +27,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should identify missing variables', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
||||
{nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
||||
{nom: "startHere", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
||||
{nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
||||
{nom: "ko", espace: "sum . evt"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
|
@ -40,8 +38,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should identify missing variables mentioned in expressions', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
||||
{nom: "deux", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"},
|
||||
{nom: "startHere", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"},
|
||||
{nom: "nope", espace: "sum . evt"},
|
||||
{nom: "nyet", espace: "sum . evt"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
|
@ -54,8 +51,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should ignore missing variables in the formula if not applicable', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
||||
{nom: "deux", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"},
|
||||
{nom: "startHere", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"},
|
||||
{nom: "trois", espace: "sum"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
||||
|
@ -66,8 +62,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should not report missing variables when "one of these" short-circuits', function() {
|
||||
let rawRules = [
|
||||
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
||||
{nom: "deux", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"},
|
||||
{nom: "startHere", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"},
|
||||
{nom: "trois", espace: "sum"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
||||
|
@ -78,8 +73,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should report missing variables in switch statements', function() {
|
||||
let rawRules = [
|
||||
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
||||
{ nom: "logic", formule: {"aiguillage numérique": {
|
||||
{ nom: "startHere", formule: {"aiguillage numérique": {
|
||||
"11 > dix":"1000%",
|
||||
"3 > dix":"1100%",
|
||||
"1 > dix":"1200%"
|
||||
|
@ -94,8 +88,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should not report missing variables in switch for consequences of false conditions', function() {
|
||||
let rawRules = [
|
||||
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
||||
{ nom: "logic", formule: {"aiguillage numérique": {
|
||||
{ nom: "startHere", formule: {"aiguillage numérique": {
|
||||
"8 > 10":"1000%",
|
||||
"1 > 2":"dix"
|
||||
}}, espace: "top"},
|
||||
|
@ -109,8 +102,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should report missing variables in consequence when its condition is unresolved', function() {
|
||||
let rawRules = [
|
||||
{ nom: "startHere", formule: { somme: ["logic"] }, espace: "top" },
|
||||
{ nom: "logic",
|
||||
{ nom: "startHere",
|
||||
formule: {
|
||||
"aiguillage numérique": {
|
||||
"10 > 11": "1000%",
|
||||
|
@ -135,8 +127,7 @@ describe('collectMissingVariables', function() {
|
|||
|
||||
it('should not report missing variables when a switch short-circuits', function() {
|
||||
let rawRules = [
|
||||
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
||||
{ nom: "logic", formule: {"aiguillage numérique": {
|
||||
{ nom: "startHere", formule: {"aiguillage numérique": {
|
||||
"11 > 10":"1000%",
|
||||
"3 > dix":"1100%",
|
||||
"1 > dix":"1200%"
|
||||
|
|
|
@ -18,10 +18,10 @@ describe('Mécanismes', () =>
|
|||
exemples.map(({nom: testTexte, situation, 'valeur attendue': valeur, 'variables manquantes': expectedMissing}) =>
|
||||
it(testTexte + '', () => {
|
||||
|
||||
let rules = [...battery, {nom: "startHereHack", formule: {somme: [nom]}}].map(enrichRule),
|
||||
let rules = [...battery].map(enrichRule),
|
||||
state = situation || {},
|
||||
stateSelector = name => state[name],
|
||||
analysis = analyseTopDown(rules, "startHereHack")(stateSelector),
|
||||
analysis = analyseTopDown(rules, nom)(stateSelector),
|
||||
missing = collectMissingVariables()(stateSelector,analysis)
|
||||
|
||||
// console.log('JSON.stringify(analysis', JSON.stringify(analysis))
|
||||
|
@ -33,7 +33,7 @@ describe('Mécanismes', () =>
|
|||
)
|
||||
|
||||
if (expectedMissing) {
|
||||
expect(R.keys(missing)).to.eql(expectedMissing)
|
||||
expect(R.keys(missing).sort()).to.eql(expectedMissing.sort())
|
||||
}
|
||||
|
||||
})
|
||||
|
|
|
@ -65,6 +65,13 @@
|
|||
- dégradation mineure
|
||||
- dégradation majeure
|
||||
- montant caution
|
||||
- nom: variables manquantes même si innaccessibles
|
||||
situation:
|
||||
dégradation mineure: non
|
||||
valeur attendue: null
|
||||
variables manquantes:
|
||||
- dégradation majeure
|
||||
- montant caution
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue