computer science MATRIX ASSIGNMENT
PA201/main.c
// TODO - Nothing! Do not modify this file #include <stdio.h> #include <stdlib.h> #include "tools.h" extern void runAllTests(); int main() { printf("Welcome to PA201\n\n"); runAllTests(); return EXIT_SUCCESS; }
PA201/PA201.cbp
PA201/PA201.depend
| # depslib dependency file v1.0 | |
| 1317253011 source:y:\3515 - it program design - oa - v4\w07 - 201 -\solution\pa201\tests.c | |
| 1317252893 source:y:\3515 - it program design - oa - v4\w07 - 201 -\solution\pa201\tools.c | |
| tools.h | |
| 1317253037 y:\3515 - it program design - oa - v4\w07 - 201 -\solution\pa201\tools.h | |
| tests.h | |
| 1317254045 y:\3515 - it program design - oa - v4\w07 - 201 -\solution\pa201\tests.h | |
| 1349866271 source:x:\bs it\3515 - it program design - oa - v5\w07 - 201 - pa201\students\pa201\tests.c | |
| <stdlib.h> | |
| tests.h | |
| 1349901036 x:\bs it\3515 - it program design - oa - v5\w07 - 201 - pa201\students\pa201\tests.h | |
| 1349866214 source:x:\bs it\3515 - it program design - oa - v5\w07 - 201 - pa201\students\pa201\tools.c | |
| <stdlib.h> | |
| tests.h | |
| 1317252812 source:x:\bs it\3515 - it program design - oa - v5\w07 - 201 - pa201\students\pa201\main.c | |
| <stdio.h> | |
| <stdlib.h> | |
| tools.h | |
| tests.h | |
| 1317253037 x:\bs it\3515 - it program design - oa - v5\w07 - 201 - pa201\students\pa201\tools.h | |
| tests.h | |
| 1408421500 source:c:\users\alessiolpt\desktop\workbench\201\pa201\testlib.c | |
| <stdlib.h> | |
| <stdio.h> | |
| testlib.h | |
| 1408406793 c:\users\alessiolpt\desktop\workbench\201\pa201\testlib.h | |
| 1408423427 source:c:\users\alessiolpt\desktop\workbench\201\pa201\main.c | |
| <stdio.h> | |
| <stdlib.h> | |
| tools.h | |
| 1408423397 c:\users\alessiolpt\desktop\workbench\201\pa201\tools.h | |
| 1408423551 source:c:\users\alessiolpt\desktop\workbench\201\pa201\tests.c | |
| <stdlib.h> | |
| tools.h | |
| testlib.h | |
| 1408423427 source:c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\main.c | |
| <stdio.h> | |
| <stdlib.h> | |
| tools.h | |
| 1408508555 c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\tools.h | |
| 1408421500 source:c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\testlib.c | |
| <stdlib.h> | |
| <stdio.h> | |
| testlib.h | |
| 1408514693 c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\testlib.h | |
| 1408508652 source:c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\tests.c | |
| <stdlib.h> | |
| tools.h | |
| testlib.h | |
| 1408508699 source:c:\users\alessiolpt\desktop\workbench\ongoing stuff\201\pa201\tools.c | |
| <stdlib.h> | |
| tools.h | |
PA201/PA201.layout
PA201/testlib.c
// TODO - nothing, do not modify this file #include <stdlib.h> #include <stdio.h> #include "testlib.h" void TEST(const char * const shortDescription, int boolexp){ // keep track of tests numbers static int testNumber = 0; testNumber++; // string representing the outcome of the test char* testResult = NULL; // determining the outcome if(boolexp){ testResult = "OK"; }else{ testResult = "FAILS"; } printf("[Test] #%3d --> %-5.5s\t%-50.50s\n", testNumber, testResult, shortDescription); fflush(stdout); }
PA201/testlib.h
// TODO - nothing, do not modify this file #ifndef TESTLIB_H_INCLUDED #define TESTLIB_H_INCLUDED void TEST(const char * const shortDescription, int boolexp); /* ROLE This function display information about the test being "OK" or "FAILED" based on whether the condition used as parameter is respectively true or false PARAMETERS shortDescription a string describing the test. 45 characters long maximum boolexp the result of evaluating a boolean expression representing what we are testing. If it evaluates to true, the function will display that the test succeeded. Otherwise, it will display that the test failed. */ #endif // TESTLIB_H_INCLUDED
PA201/tests.c
// TODO - Implement your tests in this file using testlib functions #include <stdlib.h> #include "tools.h" #include "testlib.h" void test_is_sorted_1(){ // Example test function int matrix[NB_ROWS][NB_COLS] = {{1 , 2 , 3 , 4 , 5} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} }; TEST("Already sorted matrix", isMatrixSorted(matrix) == 1); } void test_sort_1(){ // Example test function int matrix[NB_ROWS][NB_COLS] = {{1 , 2 , 5 , 4 , 3} , {6 , 7 , 8 , 9 , 10} , {11, 12, 13, 14, 15} }; matrixSort(matrix); TEST("test_sort_1",isMatrixSorted(matrix)); } void runAllTests(){ // This is how you would use the above test functions // test_is_sorted_1(); // test_sort_1(); }
PA201/tools.c
// TODO - Implement the functions in this file #include <stdlib.h> #include "tools.h" int isMatrixSorted( int data[NB_ROWS][NB_COLS] ){ return 0; // modify this } void matrixSort( int data[NB_ROWS][NB_COLS]){ return; // modify this }
PA201/tools.h
// TODO - Nothing! Do not modify this file #ifndef _TOOLS_H_ #define _TOOLS_H_ #define NB_ROWS 3 #define NB_COLS 5 extern int isMatrixSorted( int data[NB_ROWS][NB_COLS] ); /* ROLE Determines whether the matrix passed as parameter is sorted with the smallest value in data[0][0], the second smallest value in data[0][1], and so on and so forth with the largest value in data[NB_ROWS-1][NB_COLS-1] RETURNS 0 if the matrix data is not sorted 1 if it is PARAMETERS data the two dimensional matrix to be sorted */ extern void matrixSort(int data[NB_ROWS][NB_COLS]); /* ROLE sorts the integers in a two dimensional matrix so that the smallest value is in data[0][0], the second smallest one in data[0][1], and so on so forth with the largest value in data[NB_ROWS-1][NB_COLS-1] PARAMETERS data the two dimensional matrix to be sorted */ #endif