Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Commit

Permalink
Fix #9: RandomController conversion generating out-of-bounds indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
robingustafsson committed Feb 27, 2019
1 parent fd9c04e commit 660ab68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/element/RandomController.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ${ind(strip(logic))}
}
result.logic = `\n\n`
if (settings.comment) result.logic += `/* ${settings.comment} */\n`
const index = `Math.floor(Math.random()*(${blocks.length}+1))`
const index = `Math.floor(Math.random()*(${blocks.length}))`
result.logic += '' +
`{ const index = ${index}; switch (index) {
${ind(blocks.join('\n'))}
Expand Down
2 changes: 1 addition & 1 deletion test/int/element/RandomController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('convert', t => {
const result = RandomController(node)
t.is(result.logic, `
{ const index = Math.floor(Math.random()*(3+1)); switch (index) {
{ const index = Math.floor(Math.random()*(3)); switch (index) {
case 0:
// Fake
break
Expand Down

0 comments on commit 660ab68

Please sign in to comment.