This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Simulates roll of a die (#223)
Returns a value between 1 and 6 none
- Loading branch information
1 parent
8bd0450
commit 3282f0d
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default rollDice | ||
|
||
/** | ||
* Original Source: https://stackoverflow.com/questions/15603217/random-dice-nr-javascript | ||
* | ||
* This method will return a random value from rolling a dice. | ||
* | ||
* @return {number} - Random number between 1 and 6 | ||
*/ | ||
|
||
function rollDice() { | ||
return Math.floor(6 * Math.random()) + 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from 'ava' | ||
import { rollDice } from '../src' | ||
|
||
test('Dice value should not be greater than 6', t => { | ||
const max = 6 | ||
const diceValue = rollDice() | ||
t.false(diceValue > max) | ||
}) | ||
|
||
test('Dice value should not be less than 1', t => { | ||
const min = 1 | ||
const diceValue = rollDice() | ||
t.false(diceValue < min) | ||
}) |