int is_magic_square(Matrix *A){ //Case that rows and columns not the same //Not a Square grid, so cannot be square if (A->rows != A->cols){ printf("Not a square matrix\n"); return 0; } //Getting sum of rows double *allRowSum = row_sum(A); //Get sum of columns double *allColSum = col_sum(A); //Get sum of diagnols double *allDiag = diag_sum(A); //Get total of first row - all others should be the same either way double magic = allRowSum[0]; if (test_rows(allRowSum, A->rows, magic)){ if (test_cols(allColSum, A->cols, magic)){ if (test_diag(allDiag, magic)){ //If rows, cols, and diags are the same //We have a magic square! return 1; } } } return 0; }
int main() { test_table(); test_rows(); test_bitmap(); test_int_key(); test_text_key(); test_cursor(); test_reference(); return 0; }
int main(void) { if (sizeof(SQLLEN) != 8) { printf("Not possible for this platform.\n"); odbc_test_skipped(); return 0; } odbc_use_version3 = 1; odbc_connect(); odbc_command("create table #tmp1 (i int)"); test_params(); test_rows(); odbc_disconnect(); printf("Done\n"); return 0; }
void run_tests(void) { int unsolved[HEIGHT][WIDTH] = { { 5, 3, 0, 0, 7, 0, 0, 0, 0 }, { 6, 0, 0, 1, 9, 5, 0, 0, 0 }, { 0, 9, 8, 0, 0, 0, 0, 6, 0 }, { 8, 0, 0, 0, 6, 0, 0, 0, 3 }, { 4, 0, 0, 8, 0, 3, 0, 0, 1 }, { 7, 0, 0, 0, 2, 0, 0, 0, 6 }, { 0, 6, 0, 0, 0, 0, 2, 8, 0 }, { 0, 0, 0, 4, 1, 9, 0, 0, 5 }, { 0, 0, 0, 0, 8, 0, 0, 7, 9 } }; int illegal[HEIGHT][WIDTH] = { { 5, 3, 5, 2, 7, 6, 7, 8, 9 }, { 6, 1, 0, 1, 9, 5, 0, 0, 0 }, { 0, 9, 8, 0, 0, 0, 0, 6, 0 }, { 8, 2, 2, 0, 6, 0, 0, 0, 3 }, { 4, 4, 0, 8, 0, 3, 6, 0, 1 }, { 7, 0, 5, 0, 2, 0, 0, 0, 6 }, { 0, 6, 0, 0, 0, 0, 2, 8, 0 }, { 0, 0, 0, 4, 1, 9, 0, 0, 5 }, { 4, 0, 0, 0, 8, 0, 0, 7, 9 } }; int solved[HEIGHT][WIDTH] = { { 5, 3, 4, 6, 7, 8, 9, 1, 2 }, { 6, 7, 2, 1, 9, 5, 3, 4, 8 }, { 1, 9, 8, 3, 4, 2, 5, 6, 7 }, { 8, 5, 9, 7, 6, 1, 4, 2, 3 }, { 4, 2, 6, 8, 5, 3, 7, 9, 1 }, { 7, 1, 3, 9, 2, 4, 8, 5, 6 }, { 9, 6, 1, 5, 3, 7, 2, 8, 4 }, { 2, 8, 7, 4, 1, 9, 6, 3, 5 }, { 3, 4, 5, 2, 8, 6, 1, 7, 9 } }; int row[WIDTH]; int column[HEIGHT]; int sub[SUB_HEIGHT][SUB_WIDTH]; puts("Unsolved tests"); test_rows(unsolved, 0); test_columns(unsolved, 0); test_subs(unsolved, 0); test_whole(unsolved, 0); copy_row(unsolved, 0, row); test_row_legality(row, 1); copy_column(unsolved, 0, column); test_column_legality(column, 1); copy_sub(unsolved, 0, 0, sub); test_sub_legality(sub, 1); test_legality(unsolved, 1); int illegal_move[3] = {0, 2, 5}; test_legality_after_move(unsolved, illegal_move, 0); int legal_move[3] = {0, 2, 4}; test_legality_after_move(unsolved, legal_move, 1); puts("Illegal tests"); test_rows(illegal, 0); test_columns(illegal, 0); test_subs(illegal, 0); test_whole(illegal, 0); copy_row(illegal, 0, row); test_row_legality(row, 0); copy_column(illegal, 0, column); test_column_legality(column, 0); copy_sub(illegal, 0, 0, sub); test_sub_legality(sub, 0); test_legality(illegal, 0); puts("Presolved tests"); test_rows(solved, 1); test_columns(solved, 1); test_subs(solved, 1); test_whole(solved, 1); solve(unsolved); puts("Solved tests"); test_rows(unsolved, 1); test_columns(unsolved, 1); test_subs(unsolved, 1); test_whole(unsolved, 1); print_test_results(); }