so I'm still fairly new to C programming and I'm having a difficult time how to create a unit test for this matrix equality function. I have two c files, one which implements the equality function while the other is the unit test. The unit test I'm looking to do is to basically print " PASS(2/2) : MatrixEquals() " in the unit test file whenever the given matrices are equivalent. This code below is the implementation of the matrix equality
int mat1[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int mat2[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int MatrixEquals(float mat1[3][3], float mat2[3][3]) //prototype function in header
{
int flag = 1;
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
if(mat1[i][j] != mat2[i][j])
{
flag = 0;
break;
}
}
}
if(flag == 1);
}
What code should I do in the unit test file to validate that only when MatrixEquals is true, then it would print " PASS(2/2) : MatrixEquals() " I'm using an if statement to do so, but what and how do I reference the condition that MatrixEquals is true or 1 in the if statement
int main()
{
BOARD_Init();
if(MatrixEquals == 1){
printf("PASSED (2/2): MatrixEquals()\n");
}
else{
printf("PASSED (1/2): MatrixEquals()\n");
}
Aucun commentaire:
Enregistrer un commentaire