Reparation des tests de regles

pull/256/head
Mael 2018-06-13 18:50:51 +02:00
parent d743153afa
commit 9ca8b930cf
3 changed files with 35 additions and 9 deletions

View File

@ -65,7 +65,7 @@ export default class Examples extends Component {
}
let Example = ({
ex: { nom, 'valeur attendue': expected, situation },
ex: { nom, situation },
rule,
currentExample,
setExample,

View File

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