From d454e94ef6df2f789b4bdeed2d634d8ae102341b Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 16 Dec 2017 12:01:51 +0100 Subject: [PATCH] :white_check_mark: Ajoute un test de performance --- source/reducers.js | 4 ---- test/inversion.test.js | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/reducers.js b/source/reducers.js index 8d25baf33..504eaba0c 100644 --- a/source/reducers.js +++ b/source/reducers.js @@ -64,11 +64,8 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( let parsedRules = R.path(['analysis', 'parsedRules'], state), - date = Date.now(), analysis = analyseMany(state.parsedRules, targetNames)(situationWithDefaults(state)), - yaya = console.log('Date.now(', Date.now() - date), nextWithDefaults = getNextSteps(situationWithDefaults(state), analysis), - yaaya = console.log('Date.now2(', Date.now() - date), assumptionsMade = !R.isEmpty(rulesDefaults), done = nextWithDefaults.length == 0 @@ -86,7 +83,6 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( nextWithoutDefaults(state, analysis, targetNames, intermediateSituation) : {currentQuestion: head(nextWithDefaults), nextSteps: nextWithDefaults, }) } - console.log('Date.now3(', Date.now() - date) if (action.type == START_CONVERSATION) { return { diff --git a/test/inversion.test.js b/test/inversion.test.js index fbd62963d..8cec08fb7 100644 --- a/test/inversion.test.js +++ b/test/inversion.test.js @@ -1,6 +1,6 @@ import { expect } from "chai" -import { enrichRule } from "../source/engine/rules" -import { analyse, parseAll } from "../source/engine/traverse" +import { rules as realRules, enrichRule } from '../source/engine/rules' +import { analyse, analyseMany, parseAll } from "../source/engine/traverse" import { collectMissingVariables } from "../source/engine/generateQuestions" import yaml from "js-yaml" import dedent from "dedent-js" @@ -198,3 +198,15 @@ it("complex inversion with composantes", () => { expect(analysis.targets[0].nodeValue).to.equal(3750) expect(missing).to.be.empty }) + +it('should collect missing variables fast', function() { + let stateSelector = (name) => ({"contrat salariƩ . salaire net":"2300"})[name] + + let rules = parseAll(realRules.map(enrichRule)), + analysis = analyseMany(rules,["salaire brut","salaire total"])(stateSelector) + + let start = Date.now() + let missing = collectMissingVariables(analysis.targets) + let elapsed = Date.now()-start + expect(elapsed).to.be.below(200) +});