Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/good-first-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cli
return console.log(chalk.yellow(`\nNo Good First Issues were found for the GitHub organization, repo, or project ${chalk.white(input)}.\n`))
}

const key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1))
const key = cmd.first ? 0 : Math.floor(Math.random() * issues.length)

// Call the log functionality, output the result to the console.
const output = await log(issues[key], (input in projects) ? projects[input].name : project)
Expand Down
22 changes: 22 additions & 0 deletions tests/pick.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Guards the issue-selection math in bin/good-first-issue.js: every index in
// [0, length) must be reachable, including the last. Fails if someone
// reintroduces `Math.floor(issues.length - 1)`.

function pick (length, first) {
return first ? 0 : Math.floor(Math.random() * length)
}

test('first flag always returns index 0', () => {
for (let len = 1; len < 10; len++) {
expect(pick(len, true)).toBe(0)
}
})

test('random pick can reach the first and last index', () => {
const length = 20
const seen = new Set()
for (let i = 0; i < 5000; i++) seen.add(pick(length, false))
expect(seen.has(0)).toBe(true)
expect(seen.has(length - 1)).toBe(true)
expect(seen.has(length)).toBe(false)
})