#include #include #include "Sudoku.h" using namespace std; // Here is a function that allows you to print out a text version of // the current Sudoku board. void print_sudoku( Sudoku const& game ) { int n = game.n(); int n_squared = n*n; if ( n <= 3 ) { std::string outline( n_squared+4, '-' ); for ( unsigned int r=0; r const& numbers ) { cout << "Possible numbers for (" << r << ", " << c << "): "; if ( numbers.empty() ) cout << " -none- \n"; else { for ( unsigned int i=0; i numbers; game1.possible_numbers(0, 0, numbers); output_numbers( 0, 0, numbers ); game1.possible_numbers(1, 4, numbers); output_numbers( 1, 4, numbers ); game1.possible_numbers(2, 7, numbers); output_numbers( 2, 7, numbers ); cout << "\n======================\nTest copy constructor\n======================" << endl; Sudoku copy1(game1); // test copy constructor cout << "game1's board" << endl; print_sudoku( game1 ); cout << "copy1's board, should be precisely the same as above" << endl; //uncomment print_sudoku to see print_sudoku(copy1); // see if the print out is the same as print_sudoku(game1) above cout << endl; cout << "\n======================\ngame2\n======================" << endl; Sudoku game2( 4 ); cout << "game2.n() returns " << game2.n() << " <-- should be 4" << endl; cout << "game2.n_squared() returns " << game2.n_squared() << " <-- should be 16" << endl; cout << "Populating the board ... " << endl; game2.assign( 0, 1, 12 ); game2.assign( 0, 5, 7 ); game2.assign( 0, 10, 16 ); game2.assign( 0, 11, 15 ); game2.assign( 0, 13, 5 ); game2.assign( 1, 3, 8 ); game2.assign( 1, 4, 6 ); game2.assign( 1, 5, 16 ); game2.assign( 1, 11, 13 ); game2.assign( 4, 7, 1 ); game2.assign( 4, 4, 13 ); game2.assign( 4, 5, 6 ); game2.assign( 4, 15, 13 ); //print_sudoku( game2 ); cout << endl; cout << "game2.is_assigned(4, 7) returns " << game2.is_assigned(4, 7) << " <-- should be 1" << endl; cout << "game2.is_assigned(4, 17) returns " << game2.is_assigned(4, 17) << " <-- should be 0" << endl; cout << "game2.is_assigned(40, 7) returns " << game2.is_assigned(40, 7) << " <-- should be 0" << endl; cout << "game2.is_assigned(0, 0) returns " << game2.is_assigned(0, 0) << " <-- should be 0" << endl; //print_sudoku( game2 ); cout << "\nChecking validity of 13 at (4,5): " << game2.valid_assignment( 4, 5, 13 ) << " <-- should be 0" << endl; int val = 0; cout << "calling game2.get_number(4, 4, val)" << flush; game2.get_number(4, 4, val); cout << " number at [4][4] is " << val << " <-- should be 13" << endl; cout << "calling game2.unassign(4,4)" << endl; game2.unassign(4,4); cout << "\nChecking validity of 13 at (4,5): " << game2.valid_assignment( 4, 5, 13 ) << " <-- should be 0" << endl; cout << "calling game2.get_number(4, 15, val)" << flush; game2.get_number(4, 15, val); cout << " number at [4][15] is " << val << " <-- should also be 13" << endl; cout << "calling game2.unassign(4,15)" << endl; game2.unassign(4,15); cout << "\nChecking validity of 13 at (4,5): " << game2.valid_assignment( 4, 5, 13 ) << " <-- should be 1" << endl; cout << "calling game2.assign(4, 5, 13)" << endl; game2.assign(4, 5, 13); cout << "calling game2.get_number(4, 5, val)" << flush; game2.get_number(4, 5, val); cout << " number at [4][5] is " << val << " <-- should be 13" << endl; cout << endl; if(game2.is_grid_valid()) cout << "grid is valid" << endl; else cout << "grid is NOT valid. Something is wrong with your code." << endl; //print_sudoku( game2 ); game2.possible_numbers(0, 8, numbers); output_numbers(0, 8, numbers); cout << "Correct output: 1 2 3 4 6 8 9 10 11 14" << endl; cout << "calling game2.assign(0, 8, 1)" << endl; game2.assign(0, 8, 1); //print_sudoku( game2 ); cout << endl; game2.possible_numbers(4, 8, numbers); output_numbers(4, 8, numbers); cout << "Correct output: 2 3 4 5 6 7 8 9 10 11 12 14 15 16" << endl; cout << "calling game2.assign(4, 8, 150)" << endl; game2.assign(4, 8, 150); // can't assign here because 150 is too large, should be unsuccessful cout << endl; if(game2.is_grid_valid()) cout << "grid is valid" << endl; else cout << "grid is NOT valid. Something is wrong with your code." << endl; cout << "calling game2.assign(4, 8, 15)" << endl; game2.assign(4, 8, 15); // OK //print_sudoku( game2 ); return 0; }