From 9ca8b930cfdaa5a8983a74c30a2389a785018c5f Mon Sep 17 00:00:00 2001 From: Mael Date: Wed, 13 Jun 2018 18:50:51 +0200 Subject: [PATCH] Reparation des tests de regles --- source/components/rule/Examples.js | 2 +- test/real-rules.test.js | 42 +++++++++++++++---- ...reducers.test.js => selectorsttestTODO.js} | 0 3 files changed, 35 insertions(+), 9 deletions(-) rename test/{reducers.test.js => selectorsttestTODO.js} (100%) diff --git a/source/components/rule/Examples.js b/source/components/rule/Examples.js index 375456631..8ef3ac520 100644 --- a/source/components/rule/Examples.js +++ b/source/components/rule/Examples.js @@ -65,7 +65,7 @@ export default class Examples extends Component { } let Example = ({ - ex: { nom, 'valeur attendue': expected, situation }, + ex: { nom, situation }, rule, currentExample, setExample, diff --git a/test/real-rules.test.js b/test/real-rules.test.js index b10d9f164..58ca4b246 100644 --- a/test/real-rules.test.js +++ b/test/real-rules.test.js @@ -4,20 +4,46 @@ puis on teste idéalement tous ses comportements sans en faire intervenir d'autres. */ -import { expect, AssertionError } from 'chai' -import { enrichRule, rules } from '../source/engine/rules' -import { analyse, parseAll } from '../source/engine/traverse' -import { collectMissingVariables } from '../source/engine/generateQuestions' -import testSuites from './load-mecanism-tests' -import R from 'ramda' -import { runExamples, isFloat } from '../source/components/rule/Examples' +import { AssertionError } from 'chai' +import { rules } from '../source/engine/rules' +import { parseAll } from '../source/engine/traverse' +import { exampleAnalysisSelector } from 'Selectors/analyseSelectors' +import { merge } from 'ramda' + +// les variables dans les tests peuvent être exprimées relativement à l'espace de nom de la règle, +// comme dans sa formule +let runExamples = (examples, rule) => + examples.map(ex => { + let runExample = exampleAnalysisSelector( + { + currentExample: { + situation: ex.situation, + dottedName: rule.dottedName + } + }, + { dottedName: rule.dottedName } + ), + exampleValue = runExample.nodeValue, + goal = ex['valeur attendue'], + ok = + exampleValue === goal + ? true + : typeof goal === 'number' + ? Math.abs((exampleValue - goal) / goal) < 0.001 + : goal === null && exampleValue === 0 + + return merge(ex, { + ok, + rule: runExample + }) + }) let parsedRules = parseAll(rules) describe('Tests des règles de notre base de règles', () => parsedRules.map(rule => { if (!rule.exemples) return null describe(rule.name, () => { - let examples = runExamples(rule.exemples, rule, parsedRules) + let examples = runExamples(rule.exemples, rule) examples.map(example => it(example.nom + '', () => { if (!example.ok) diff --git a/test/reducers.test.js b/test/selectorsttestTODO.js similarity index 100% rename from test/reducers.test.js rename to test/selectorsttestTODO.js