Skip to content
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

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Improve dnd-character tests #407

merged 2 commits into from
Nov 15, 2023

Conversation

ryanplusplus
Copy link
Member

This removes some unnecessary checks and fixes the argument order in an assertion.

Comment on lines -176 to +170
assert.equal(character.hitpoints, 10 + dnd.modifier(character.constitution))
assert.equal(10 + dnd.modifier(character.constitution), character.hitpoints)
Copy link
Member Author

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)
Copy link
Member Author

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.

Copy link
Contributor

@keiravillekode keiravillekode Nov 13, 2023

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.

Copy link
Member Author

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.

@keiravillekode
Copy link
Contributor

lgtm

@imolein imolein merged commit e3fe1cd into main Nov 15, 2023
3 checks passed
@imolein imolein deleted the improve-dnd-character-tests branch November 15, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants