-
-
Save aloisdg/ade1990e93a4bc019fa055fb593675e3 to your computer and use it in GitHub Desktop.
(source: https://jsfiddle.net/jyy44uh9/20/)
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
<div id="qunit"></div> | |
<div id="qunit-fixture"></div> | |
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
function splitHitDice(input) { | |
let dices = input.toLowerCase().split('d'); | |
return [...Array(parseInt(dices[0]))].map(_ => parseInt(dices[1])); | |
} | |
function calcHitDice(input) { | |
return [].concat.apply([], input.replace(' ','').split('+').map(splitHitDice)); | |
} | |
QUnit.test( "1d6", function( assert ) { | |
assert.deepEqual(calcHitDice("1d6"), [6], "Passed!" ); | |
}); | |
QUnit.test( "1d8", function( assert ) { | |
assert.deepEqual(calcHitDice("1d8"), [8], "Passed!" ); | |
}); | |
QUnit.test( "1D8", function( assert ) { | |
assert.deepEqual(calcHitDice("1D8"), [8], "Passed!" ); | |
}); | |
QUnit.test( "2d8", function( assert ) { | |
assert.deepEqual(calcHitDice("2d8"), [8,8], "Passed!" ); | |
}); | |
QUnit.test( "3d8", function( assert ) { | |
assert.deepEqual(calcHitDice("3d8"), [8,8,8], "Passed!" ); | |
}); | |
QUnit.test( "1d6+3d8", function( assert ) { | |
assert.deepEqual(calcHitDice("1d6+3d8"), [6,8,8,8], "Passed!" ); | |
}); | |
QUnit.test( "2d6+3d8", function( assert ) { | |
assert.deepEqual(calcHitDice("2d6+3d8"), [6,6,8,8,8], "Passed!" ); | |
}); | |
QUnit.test( "1d4+2d6+3d8", function( assert ) { | |
assert.deepEqual(calcHitDice("1d4+2d6+3d8"), [4,6,6,8,8,8], "Passed!" ); | |
}); | |
QUnit.test( "1d6 + 3d8", function( assert ) { | |
assert.deepEqual(calcHitDice("1d6 + 3d8"), [6,8,8,8], "Passed!" ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://qunitjs.com/intro/