0

这一个正在引起悲伤;我想掌握 CUnit。

已使用以下说明安装它:http: //macappstore.org/cunit/

我在命令行使用以下内容: gcc myprog.c -Wall -Wfloat-equal -Wextra -O2 -pedantic -ansi -lm -lcunit -o myprog

它编译没有错误,我继续以下操作:./myprog

我的代码中有以下内容:

#include <stdio.h>
#include <math.h>
#include <CUnit/CUnit.h>

int maxi(int i1, int i2);
void test_maxi(void);
struct code{
   char words[5][5];
   int cnt; /* Current Word Counter*/
};
typedef struct code Code;

int main(void){
  test_maxi();   

   return 0;
}

int maxi(int i1, int i2){
   return (i1 > i2) ? i1 : i2;
}

void test_maxi(void){
   CU_ASSERT(maxi(0,2) == 2);
   CU_ASSERT(maxi(0,-2) == 0);
   CU_ASSERT(maxi(2,2) == 2);
}

我的假设是这应该在同一目录中生成某种 .txt 或替代文件。这个假设不正确吗?我应该寻找什么?

更新:我目前在命令行上得到以下信息;“断言失败:(NULL!= f_pCurSuite),函数 CU_assertImplementation,文件 TestRun.c,第 162 行。中止陷阱:6”

(全面披露:编程新手......所以要温柔:P)

4

1 回答 1

0

You're not calling test_maxi in main() so it just exists as a function, but it is not being run. You need to run it in main. – Eli Sadoff

You need to create a test suite as explained here. – pbn

于 2019-01-11T12:11:15.107 回答