#include "pch.h"
#include "share.h"
using namespace std;
namespace TestSudokuChecker
{
int test_sudoku[10][10] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0,0,
0,2, 6, 8 ,4, 7 ,3 ,9, 5 ,1,
0,3 ,4 ,1 ,9 ,6 ,5 ,2 ,7 ,8,
0,7 ,9, 5 ,8 ,1 ,2 ,3 ,6 ,4,
0,5 ,7 ,4 ,6 ,2 ,1 ,8 ,3 ,9,
0,1 ,3 ,9, 5 ,4 ,8 ,6 ,2 ,7,
0,8 ,2 ,6 ,3 ,9 ,7 ,4 ,1 ,5,
0,9 ,1 ,7, 2, 8 ,6 ,5 ,4 ,3,
0,6 ,8 ,3, 1 ,5 ,4 ,7 ,9 ,2,
0,4, 5 ,2, 7 ,3, 9, 1 ,8, 6,
};
TEST(SudokuChecker_Test, Grid)
{
int** s = new int* [N_ROW_SUDOKU];
s[0] = new int[10];
for (int i = 0; i < 10; i++)
{
s[i] = new int[10];
for (int j = 0; j < 10; j++)
s[i][j] = test_sudoku[i][j];
}
EXPECT_EQ(checkGrid(s), 0);
s[1][3] = 4;
EXPECT_EQ(checkGrid(s), 22);
s[1][3] = 8;//复原
s[1][1] = 8;
EXPECT_EQ(checkGrid(s), 13);
s[1][1] = 2;
s[5][6] = 3;
EXPECT_EQ(checkGrid(s), 64);
for (int j = 0; j < 10; j++)
delete[] s[j];
delete[] s;
}
TEST(SudokuChecker_Test, RowCol)
{
int** s = new int* [N_ROW_SUDOKU];
s[0] = new int[10];
for (int i = 0; i < 10; i++)
{
s[i] = new int[10];
for (int j = 0; j < 10; j++)
s[i][j] = test_sudoku[i][j];
}
EXPECT_EQ(checkRowCol(s), 0);
s[1][3] = 4;
EXPECT_EQ(checkRowCol(s), 14);
s[1][3] = 8;//复原
s[1][1] = 8;
EXPECT_EQ(checkRowCol(s), 13);
s[1][1] = 2;
s[5][6] = 3;
EXPECT_EQ(checkRowCol(s), 56);
for (int j = 0; j < 10; j++)
delete[] s[j];
delete[] s;
}
TEST(SudokuChecker_Test, All)
{
int** s = new int* [N_ROW_SUDOKU];
s[0] = new int[10];
for (int i = 0; i < 10; i++)
{
s[i] = new int[10];
for (int j = 0; j < 10; j++)
s[i][j] = test_sudoku[i][j];
}
EXPECT_EQ(checkSudoku(s), 0);
s[1][3] = 4;
EXPECT_EQ(checkSudoku(s), -22);
s[1][3] = 8;//复原
s[1][1] = 8;
EXPECT_EQ(checkSudoku(s), -13);
s[1][1] = 2;
s[5][6] = 3;
EXPECT_EQ(checkSudoku(s), -64);
for (int j = 0; j < 10; j++)
delete[] s[j];
delete[] s;
}
}