-
-
Notifications
You must be signed in to change notification settings - Fork 36
SudokuValidator submission #1
base: master
Are you sure you want to change the base?
Conversation
Basic spec file working with no tests.
Add .gitignore and get rid of swap files Add SudokuBoard class and implement access to a single element.
New class reads input file and creates game board; Methods to return a specific element, row, or column.
Expose game board for analysis; test for missing elements (zeros); Set up initial structure for testing validity.
Now need to display error information. Refactored the sub_grid_start computation of row/col.
Modified SudokuValidator methods to return error values and convert to strings for reporting CLI program not printing those results yet have some duplication to be taken care of before that step.
report_errors now a separate method to generate error strings.
Duplication removed from check_<element>_validity methods.
1. Remove unnecessary to_s conversion in valid_element? method 2. Change invalid sudoku result spec to test for include, not eq, so that we can add error descriptions.
Works for invalid/complete sudokus; next is incomplete sudokus.
Ignore missing (zero) elements in board.
|
The bin file is missing but you did a very great work! For your I thinks it's better to give an array with rows and columns instead of You have one test file but the files with code. I thinks it's better to split it. In your executable file, I think you can place a method to build the message in the validator class. You probably should had more spaces in your spec file too. In your spec file, you do You have an empty before block in your tests. You did that At least, I think you can move the |
|
@GCorbel - thank you very much for your comments; much appreciated. I'll respond here to each of your points and then go dig into the code for a bit.
Thanks again for your feedback! |
Remove empty before block Add spacing between describe/it blocks Split specs for SudokuBoard and SudokuValidator into two files.
First part of eliminating Law of Demeter violation (@game.game.board[0][0] constructs). First, reference the SudokuBoard instance as 'board', not 'game'.
Add []= method to SudokuBoard for cleaner access to board array, then use that in the specs for modifying the board for tests. This finishes the cleanup of the old @game.board.board[0][0] code.
lib/sudoku_board.rb
Outdated
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.
it's a pet peeve, but i don't think these should be left as comments in the file. git history can be used if necessary.
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.
Agreed, @elubin; I overlooked them and will delete them.
Clean up SudokuBoard#sub_grid method by extracting code to get a sub_grid row.
spec/sudoku_board_spec.rb
Outdated
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 about creating own describe block for each method? Something like this:
describe SudokuBoard do
describe '#row' do
...
end
end
I think that it improves readability of tests and you can group tests for each method together.
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 @mrhead... I wasn't sure at first if I thought this was a good idea: I like the idea of a describe block to separate complete/incomplete board examples - that's the way I started my development. However, after some reflection I think your suggested refactoring makes sense... while not immediately necessary, in the long run it will more clearly isolate the individual elements being tested. I'll work on that fairly soon.
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.
OK; done. The only thing I'm not sure I like about this is the before block which now loads the valid_complete file and the invalid_incomplete file to support the different tests, creating @game_vc & @game_ii instances. I don't think that creating additional describe blocks makes sense -- lots more code and repeated before blocks.
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.
I've stopped using before and let some time ago. Purely because of this: https://github.com/thoughtbot/guides/tree/master/best-practices#testing
From beginning I did not know how to replace it, but now I create my own methods to prepare objects for me. So unlike in before block I call them just when I need them. And unlike the let, I can pass arguments to it... So in your case you can do something like:
describe SudokuBoard do
... your tests ...
def game_vc
SudokuBoard.new("valid_complete.sudoku")
end
def game_ii
SudokuBoard.new("invalid_incomplete.sudoku")
end
end
And then you just call `game_vc` instead of `@game_vc` which doesn't looks right to me.
Anyway this is just something what I made up from different codes and probably also thoughtbot TDD workshop (I really do not remember).
And I would also like to see different opinion on this.
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.
I see what you mean. I'd like to see some explanation as to why some if these are considered the way to do things...
Sent from my iPhone
On Oct 22, 2013, at 7:06 AM, Patrik Bóna notifications@github.com wrote:
thoughtbot
Reorganize examples by method as suggested for improved readability.
Great challenge! Here's my take on the SudokuValidator. I'm looking forward to feedback. while I continue to work on improving the code.