Reparation des tests de regles
parent
d743153afa
commit
9ca8b930cf
|
@ -65,7 +65,7 @@ export default class Examples extends Component {
|
|||
}
|
||||
|
||||
let Example = ({
|
||||
ex: { nom, 'valeur attendue': expected, situation },
|
||||
ex: { nom, situation },
|
||||
rule,
|
||||
currentExample,
|
||||
setExample,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue