Skip to content

Commit 44fd6ba

Browse files
committed
Update tests with test for file not existing
1 parent c43ca9b commit 44fd6ba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_sudoku_solver.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ void test_puzzle_initial_state_isnt_set_due_to_incorrect_values() {
9797
if (exception_not_thrown) assert(false);
9898
}
9999

100+
void test_exception_is_thrown_if_file_doesnt_exist() {
101+
/* We check if the set_initial_state_from_file() function
102+
* throws an std::invalid_argument exception if the file doesn't exist. */
103+
104+
bool exception_not_thrown = true;
105+
sudoku::Grid grid_from_file;
106+
107+
try {
108+
grid_from_file.set_initial_state_from_file("some_random_thing.txt");
109+
} catch (std::invalid_argument ia) {
110+
exception_not_thrown = false;
111+
}
112+
113+
if (exception_not_thrown) assert(false);
114+
}
115+
100116
void test_value_exists_in_column() {
101117
/* We check functionality of the value_exists_in_column function. */
102118
sudoku::Grid grid({{
@@ -354,6 +370,7 @@ int main() {
354370
test_puzzle_initial_state_is_set_correctly,
355371
test_puzzle_initial_state_is_set_correctly_from_file,
356372
test_puzzle_initial_state_isnt_set_due_to_incorrect_values,
373+
test_exception_is_thrown_if_file_doesnt_exist,
357374
test_value_exists_in_column,
358375
test_value_exists_in_row,
359376
test_value_exists_in_3x3_grid,

0 commit comments

Comments
 (0)