-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Improve dnd-character tests #407
Conversation
assert.equal(character.hitpoints, 10 + dnd.modifier(character.constitution)) | ||
assert.equal(10 + dnd.modifier(character.constitution), character.hitpoints) |
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.
The order must be expected, actual in order for the error message to be correct.
@@ -122,7 +122,6 @@ describe('dnd', function() | |||
assert.equal("integer", math.type(strength)) | |||
assert.lteq(3, strength) | |||
assert.lteq(strength, 18) | |||
assert.equal(strength, character.strength) |
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 check is unnecessary because strength
is initialized with character.strength
above.
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.
The problem-specifications say to check "each ability is only calculated once"
Here is a solution we want to reject:
function Character:new(name)
self.__index = function(mytable, key)
return ability(roll_dice())
end
local meta_tbl = {
name = name,
constitution = ability(roll_dice())
}
meta_tbl.hitpoints = 10 + modifier(meta_tbl.constitution)
return setmetatable(meta_tbl, self)
end
Instead of three tests
"description": "random ability is within range",
"description": "random character is valid",
"description": "each ability is only calculated once",
I wrote one test for each ability.
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.
Thanks, I put them back.
lgtm |
This removes some unnecessary checks and fixes the argument order in an assertion.