July 2024
Intermediate to advanced
360 pages
9h 45m
English
This appendix uses the Sudoku solver project from chapter 6. Consider the completed IsValid method. The method is fairly long—more than 60 lines. I could divide it into smaller chunks, which would allow testing of individual methods, but I don’t want those methods to be part of the public API. In .NET, you can give tests access to internal (non-public) members and types. The rows, cols, and sqrt variables are used in all the checks, so it would be helpful to make them fields in the Solver, as shown in the following listing. You can get the values for these fields in the constructor with only the validation logic in the IsValid method.
Listing E.1 Moving rows, cols, and sqrt variables to fields in the Solver ...
Read now
Unlock full access