Skip to content

Commit

Permalink
fix: Allow 0 weights
Browse files Browse the repository at this point in the history
  • Loading branch information
enudler committed Oct 21, 2020
1 parent 93db22f commit d67d547
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
3 changes: 2 additions & 1 deletion core/lib/weighted-pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d67d547

Please sign in to comment.