-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Board unit tests; Add
must_match_array
assertion
To support testing Board#clamp_coordinates, I wanted to use the `must_match_array` assertion, vs just `must_equal`, when comparing the starting and ending Coordinates arrays. This is ... more correct. It prevents variations in sort order from causing test failures. - For more detail: https://stackoverflow.com/a/20334260/171183 - But, to support this, I had to implement sorting on Coordinates (by defining the `<=>` operator). Then I added tests for this as well. - I considered, but chose not to `include Comparable` into Coordinates. This would add `<`, `<=`, `>`, `>=`, etc operators for free, based on the `<=>` operator... but it's not needed, so would just be bloat. Here's a test for it, though, in case we do want to add this in the future for some reason: ``` it "returns the expected results for X/Y comparisons" do # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands _(unit_class[0, 0] < unit_class[0, 0]).must_equal(false) _(unit_class[0, 0] < unit_class[0, 1]).must_equal(true) _(unit_class[0, 0] < unit_class[1, 0]).must_equal(true) _(unit_class[0, 0] == unit_class[0, 0]).must_equal(true) _(unit_class[0, 0] == unit_class[0, 1]).must_equal(false) _(unit_class[0, 0] == unit_class[1, 0]).must_equal(false) _(unit_class[0, 0] > unit_class[0, 0]).must_equal(false) _(unit_class[0, 1] > unit_class[0, 0]).must_equal(true) _(unit_class[1, 0] > unit_class[0, 0]).must_equal(true) # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands end ``` Also, fix a few small issues found while writing the unit tests for Board. - Board#clamp_coordinates was being too lenient on the upper bounds of our columns and rows ranges. Fix: change `..` to `...` on the Range syntax. - Raise an exception when attempting to place mines on a new Board record. - Only allow Board#check_for_victory when the associated Game is in status Sweep in Progress. (Shouldn't be possible when the associated Game is in status Standing By.)
- Loading branch information
Showing
5 changed files
with
273 additions
and
36 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
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
Oops, something went wrong.