// 解答6.3 test_func2.c #include #include typedef int (*Func)(int,int*) ; // テスト対象関数 // 配列の要素数 #define CNT(x) (sizeof(x)/sizeof(x[0])) typedef struct { int expected; // 期待される結果 int argc; // 引数の個数 int *argv; // 引数配列 } TestElem; typedef struct { Func testfunc; // 関数 char *funcname; // 関数名 int testcnt; // テストデータ個数 TestElem *testdata; // テストデータ配列 } TestUnit; // テスト対象関数 int add(int,int*); int sub(int,int*); // 引数ベクトル int v0[] = { 2, 1}; int v1[] = { 2, 3}; int v2[] = { 2, 3, 4}; // add用テストデータ TestElem add_elem[] = { 3, CNT(v0), v0, 5, CNT(v1), v1, 9, CNT(v2), v2 }; // sub用テストデータ TestElem sub_elem[] = { 1, CNT(v0), v0, -1, CNT(v1), v1, -5, CNT(v2), v2 }; // テストデータ統合 TestUnit unit[] = { add, "add", CNT(add_elem), add_elem, sub, "sub", CNT(sub_elem), sub_elem }; // 汎用単体テスト関数 void test_unit(int n, TestUnit *u) { for (int i=0;i