From d67d5475dd5938adea1c4f3e05162fd29e23503b Mon Sep 17 00:00:00 2001 From: Eli Nudler Date: Wed, 21 Oct 2020 20:03:25 +0300 Subject: [PATCH] fix: Allow 0 weights --- core/lib/runner.js | 2 +- core/lib/weighted-pick.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/lib/runner.js b/core/lib/runner.js index 65ee8fa779..cf9ed5e8bf 100644 --- a/core/lib/runner.js +++ b/core/lib/runner.js @@ -336,7 +336,7 @@ function runScenario(script, intermediate, runState, contextVars) { // if (!runState.compiledScenarios) { _.each(script.scenarios, function(scenario) { - if (!scenario.weight) { + if (typeof scenario.weight === 'undefined') { scenario.weight = 1; } }); diff --git a/core/lib/weighted-pick.js b/core/lib/weighted-pick.js index f6b429437a..e14d6d47f3 100644 --- a/core/lib/weighted-pick.js +++ b/core/lib/weighted-pick.js @@ -25,6 +25,7 @@ function create(list) { function bench() { const items = [ + { weight: 0, value: 'zero' }, { weight: 1, value: 'a' }, { weight: 2, value: 'b' }, { weight: 3, value: 'c' }, @@ -63,7 +64,7 @@ function bench() { console.log('sumWeights = %s', sumWeights); l.each(items, function(p) { - let count = l.where(picks, {value: p.value}).length; + let count = l.filter(picks, {value: p.value}).length; console.log('Count of %s = %s (should be: %s\%, is: %s\%)', p.value, count,