-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 18 #50
Issue 18 #50
Conversation
Hello @KingFruit85, here is a proposal for the refactoring of Weight and Height calculation. I also added some JEST tests to validate Weight in the folder test. To run the tests you must add to your package.json the following fragments: "scripts": {
"test": "jest"
}, "devDependencies": {
"jest": "^24.9.0"
} Then run npm install. After the installation type npm test and the tests in folder will be executed with an output like this:
If you like we can add Travis to run this automatically and then add a nice badge to README like this one: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Cadesh I really appreciate you contributing to this project :)
I have reviewed and requested some changes. Please let me know if you need any more info.
* @param {Number} diceSides - integer for the number of sides 2, 4, 6, 8, 10, 12, 20, ... | ||
* @returns {Number} integer with the result of dice throw. | ||
*///------------------------------------------------------------------------------ | ||
function diceThrow (diceQuantity = 1, diceSides) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for diceQuantity = 1, does it provide any benefit over just diceQuantity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a default value, actually it would be better if it was
function diceThrow (diceSides, diceQuantity = 1 )
this way you could call the function as diceThrow(8) and get a return of 1d8
test('tiefling weight in range', () => { | ||
expect(calculateCharacterWeight('tiefling')).toBeGreaterThanOrEqual(114); | ||
expect(calculateCharacterWeight('tiefling')).toBeLessThanOrEqual(238); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great, nice to see how the tests work :) however I think they are going to require a bit of tweaking.
Using a Dwarf as an example:
The max weight of 211 is never going to be reached, even if both d6's roll max: 115 + 12 = 127
The minimum weight can also fail if the result of the 2 x d6 rolls add up to less than 3 (1 - 1 / 2 - 1).
The issue is with the way you have calculated the characters weight, and to be fair the table you linked is quite misleading! I'll leave a comment on the calculateCharacterWeight() function that explains why these numbers don't match up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a doubt I had when checking the table here
It says the weight range, these are the numbers I used in the tests. I noticed that there were something wrong with the calculations but I did not want to change your original calculations. If you know the correct ones please send me a link and I will update the pull request.
* @param {String} race - the character race. | ||
* @returns {Number} the calculated weight in lbs. | ||
*///------------------------------------------------------------------------------ | ||
function calculateCharacterWeight(race) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the table you used as a source didn't explain how the weight figure is calculated, and my previous code was also incorrect so I wasn't helping you out there either!
While a player can just roll or pick a random number, the method described in the players hand book to calculate height and weight is as follows:
First step is to calculate the players height, using a hill dwarf as an example:
Base Height: 3'8"
Height Modifier: 2d4
Base Weight: 115lb
Weight Modifier: (result of Height Modifier) x 2d6
So if I rolled a height modifier of 6 I would calculate the players weight as 115 + (6 x 2d6)
This would also explain the weight ranges described in your source table, rolling minimum values on both height modifier and weight modifier would result in : 115 + (2x2) = 119
And max values would be 115 + (8x12) = 211
hopefully that makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, great I will fix it and then send a new commit to this PR.
break; | ||
default: return "invalid race provided as function arguement [returnCharacterHeight()]"; | ||
} | ||
return finalHeight; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is correct, I will also add this change to the next PR
[REFACTOR] returnHeightAndWeight()
Description of pull request
Util.js
Core.js
Resolves #18
Has it been tested?