**TESTS**

int tests_inputs[NB_TESTS][NB_ROWS][NB_COLS] = { /* Test #0 - this is an already sorted matrix to ensure that our function*/ /* does not mess up a sorted matrix by trying to "sort it again"*/ { {1 , 2 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} } , /* Test #1 - this is a matrix with two elements only being not in order. */ /* both are located inside the same row*/ { {1 , 2 , 5 , 4 , 3} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} }, // test #2 test for negative numbers { {1 , -2 , 3 , 4 , 5} , {6 , 7 , -8 , 9 , 10} , {11, 12, 13, 14, -15} } , // test #3 test last 2 elements { {1 , 2 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 15, 14} } , // test #4 test middle elements { {1 , 2 , 3 , 4 , 5} , {6 , 8 , 9 , 7 , 10} , {11, 12, 13, 14, 15} } , //test #5 matrix is backwards { {15 , 14 , 13 , 12 , 11} , {10 , 9 , 8 , 7 , 6} , {5, 4, 3, 2, 1} } , // test #6 check first 2 { {2 , 1 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} } , // test #7 1st row duplicates { {1 , 2 , 3 , 3 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} } , // test #8 2nd row duplicates { {1 , 2 , 3 , 4 , 5} , {6 , 7 , 9 , 9 , 10} , {11, 12, 13, 14, 15} } , // test #9 3rd row duplicates { {1 , 2 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 12, 14, 15} } , // test #10 all same positive number { {5 , 5 , 5 , 5 , 5} , {5 , 5 , 5 , 5 , 5} , {5 , 5 , 5 , 5 , 5} } , // test #11 all same negative number { {-5 , -5 , -5 , -5 , -5} , {-5 , -5 , -5 , -5 , -5} , {-5 , -5 , -5 , -5 , -5} } , // test #12 all zeroes { {0 , 0 , 0 , 0 , 0} , {0 , 0 , 0 , 0 , 0} , {0 , 0 , 0 , 0 , 0} } , // test #13 leading zero { {0 , 1 , 2 , 3 ,4} , {5 , 6 , 7 , 8, 9} , {10, 11, 12, 13,14} }, // test #14 leading negative numbers { {-1 , -2 , -3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} }, // test #15 1st row duplicates not in order { {3 , 2 , 1 , 3 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} } , // test #16 2nd row duplicates not in order { {1 , 2 , 3 , 4 , 5} , {6 , 9 , 7 , 9 , 10} , {11, 12, 13, 14, 15} } , // test #17 3rd row duplicates not in order { {1 , 2 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 12} } , // test #18 matrix is all negative numbers, backwards order { {-1 , -2 , -3 , -4 , -5} , {-6 , -7 , -8 , -9 , -10} , {-11, -12, -13, -14, -15} } };

**EXPECTED**

int tests_expected[NB_TESTS] = { 1, /* #0 first test is a sorted matrix*/ 0, /* #1 second is not */ 0, // #2 negative numbers are after postives (out of order) 0, // #3 last 2 elements are out of order 0, // #4 3 middle elements are out of order 0, // #5 matrix is in backwards order 0, // #6 1st 2 elements are out of order 1, // #7 duplicates are in order in 1st row 1, // #8 duplicates are in order in 2nd row 1, // #9 duplicates are in order in 3rd row 1, // #10 entire matrix is a single duplicate positive number that is in order 1, // #11 entire matrix is a single duplicate negative number that is in order 1, // #12 entire matrix is filled with zeroes that are in order 1, // #13 leading zero in order 1, // #14 matrix starts with negative numbers and the entire matrix is in order starting from negative 0, // #15 duplicates are in not in order in 1st row 0, // #16 duplicates are in not in order in 2nd row 0, // #17 duplicates are in not in order in 3rd row 0 // #18 matrix is all negative numbers, backwards order };

**Testing algorithm**

int isMatrixSorted( int data[NB_ROWS][NB_COLS] ){ /* PARAMETERS data the two dimensional matrix to be sorted */ for(int i = 0; i < NB_ROWS -1 ; i++){ for(int j =0 ; j < NB_COLS -1; j++){ if (data[i][j] > data[i + 1][j]) return 0; } } return 1; }

**failed tests**

#1

#3

#4

#6

#15

#16

#17

This post has been edited by **Jite25**: 24 June 2013 - 12:14 AM