CUnit

C++——STL内存清除

会有一股神秘感。 提交于 2020-12-18 08:42:12
1.vector元素的清除 看代码。在vector中添加若干元素,然后clear() 1 #include<iostream> 2 #include<list> 3 #include<vector> 4 #include<iterator> 5 #include< string > 6 using std::vector; 7 using std::list; 8 using std::iterator; 9 using std:: string ; 10 using std::cout; 11 using std::endl; 12 13 int main() 14 { 15 vector< string > vecStr; 16 string pStr1 = " Robb " ; 17 vecStr.push_back(pStr1); 18 string pStr2 = " Bran " ; 19 vecStr.push_back(pStr2); 20 string pStr3 = " Snow " ; 21 vecStr.push_back(pStr3); 22 string pStr4 = " Sansa " ; 23 vecStr.push_back(pStr4); 24 string pStr5 = " Arya " ; 25 vecStr.push_back

asp dotnet core 不正经的提升效率的单元测试方法

妖精的绣舞 提交于 2020-08-19 16:58:29
在写 asp dotnet core 时,如果没有单元测试保证,需要每个方法都从 web api 的入口开始运行,此时的执行效率是很低的。而如果写单元测试,又有一个坑的问题是写单元测试也是需要时间的。本文告诉大家一些提高效率的方法,这些方法不是正经的用法,但是能提升效率。至于能不能用好不好用就请观众老爷自己决定 CUnit 中文命名单元测试 在写单元测试时,小伙伴说需要让单元测试的方法名符合 条件_执行_结果 而要求这个方法命名为英文,我的英文就超级渣,这一点 少珺 小伙伴可以帮我证明。于是你会看到我写了以下的测试 WhenABuDengYuThree_DokanarkelawNinirahajairi_SetSlj 的命名,而如果要我优化这个单元测试的命名,大家都知道,有些小伙伴和我一样想一个好的命名可能占了开发的一半时间 写单元测试时,大量的单元测试方法命名将会占用大量的时间,让小伙伴不愿意写单元测试。或者写出来的单元测试的只有自己能读懂 在一个团队里面的,如果英文水平参差不齐,如我所在的团队有英文特别厉害的 walterlv 和 天龙 也有英文特别差国语也特别差的大壮哥,还有英文有毒的本渣。此时用英文命名的单元测试就是一个神坑,除非团队能成立一个改名部专门协助命名 一个解决方法是干脆用中文命名单元测试算了,请看下面单元测试 [TestClass] public class

C# dotnet 一个看上去还能用的二进制序列化帮助类

别说谁变了你拦得住时间么 提交于 2020-08-10 00:44:40
这仅是一个辅助方法帮助类,可以协助小伙伴写二进制序列化的效率,代码也还看的过去 在开始之前,我需要说明的是,如果不是必要,不要使用二进制序列化。因为很难做到版本兼容,如果写错了也不知道是哪里写错了,调试难度很大。但是对于性能的提升,其实也不大 /// <summary> /// 二进制序列化 /// </summary> interface IBinarySerializable { void Serialize(BinaryWriter binaryWriter); void Deserialize(BinaryReader binaryReader); } 这个接口用于给对象继承,如果对象继承了,那么就方便进行序列化 这是一些辅助方法 没有用到反射,需要自己手动写转换代码。注意顺序 static class BinarySerialize { /// <summary> /// 写入 uin32 列表 /// </summary> /// <param name="binaryWriter"></param> /// <param name="list"></param> public static void WriteUint32List(this BinaryWriter binaryWriter, List<uint> list) { // 格式先写入列表长度

面向对象程序设计2020第二次作业

孤者浪人 提交于 2020-04-29 18:52:54
面向对象程序设计2020第一次作业 这个作业属于哪个课程 2020面向对象程序设计张栋班 这个作业要求在哪里 寒假作业2 这个作业的目标 完善代码、新建GitHub仓库并上传代码、制作编译脚本、进行单元测试并制作测试脚本、添加文件读取功能 作业正文 第二次作业 其它参考文献 git教程 shell教程 执行脚本的三种方式 C语言命令行参数的使用 C语言文件操作 git和GitHub教程 注: 系统是Mac OS 实践题 创建SSH Key 参考文章 新建仓库 clone到本地 其中仓库地址从这里复制 创建.gitignore文件,配置后传到仓库(具体配置到 gitignore模版 找自己需要的,再复制组合到自己的.gitignore文件中) 将代码放到该文件夹后传到仓库 push时如果出现问题,可参考下图 编程题 一、优化代码 能够输入两位数三位数,如“二十”,“三十三”。具体实现在processStringToInt函数。 分为几个函数,使含义更清晰,可读性提高 int convertToInt(char str[]);// 中文转为数字 char* convertToString(int n);// 数字转为中文 void error(void);//输出错误 void execute(void);// 执行 int processStringToInt(char number

CUnit - 'Mocking' libc functions

旧城冷巷雨未停 提交于 2020-01-02 05:47:10
问题 I'm using CUnit for my project unit testing. I need to test whether I call libc functions with the right parameters & whether I treat their return values the right way. for example: if I call the bind(...) function - I would like to check which af param I pass & assert if this is the wrong one, and also I would like to emulate it's return value & assert if I check it the right way. For these purposes I would expect the CUnit environment to have a built-in mechanism to let me call a 'mocked'

Unit test of flex bison scanner parse, how to drive the test case

纵饮孤独 提交于 2019-12-23 12:24:12
问题 I have a question about how to "drive" a flex bison based parser scanner in a unit test. The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin. Right now my focus is on getting a unit test running for the command parser. I would like to be able to provide a "const string" to the parser (a command) and then test that the corresponding command is invoked in the application (in a application stub). I do not

Building CUnit with cygwin on windows

好久不见. 提交于 2019-12-23 04:43:34
问题 Can anyone explain me, how to build CUnit on Windows using cygwin? Only found an example using mingw Building CUnit on Windows Call of make Fails (no such command). Anyone help me? 回答1: There was a Problem with the make and the "config"-file was missing. After this I can create the libs. 来源: https://stackoverflow.com/questions/29891151/building-cunit-with-cygwin-on-windows

How to test code that writes to stdout?

怎甘沉沦 提交于 2019-12-20 23:30:18
问题 How to write a test in CUnit for a function that prints to stdout , to verify its output? Example function to test: void print() { printf("Hello world"); } Its unit test should somehow verify that "Hello world" was printed to the console: void test_print() { // how to assert? } How should I go about it? 回答1: This ought to achieve what you're looking for. (ie. how to tell that something was written to stdout ) #include <sys/stat.h> void print() { printf("Hello world"); } void test_print() {

How to install CUnit on Windows

情到浓时终转凉″ 提交于 2019-12-13 05:54:05
问题 I've downloaded the library to my desktop but when I try and install it by running the ./configure command I get an error: bash: ./configure: No such file or directory I've looked at 2 existing questions on SO (link1 and link2) but they didn't solve my problem. Have I downloaded it correctly? I downloaded and extracted the folder to my desktop then opened the Bash terminal in the library's home directory and executed the ./configure command. Would be very grateful if someone could help, I'm

CUnit assertion Assertion `((void *)0) != f_pCurSuite' failed

徘徊边缘 提交于 2019-12-12 03:38:26
问题 My code looks like this: #include <CUnit/CUnit.h> int maxi(int i1, int i2) { return (i1 > i2) ? i1 : i2; } void test_maxi(void) { CU_ASSERT(maxi(0,2) == 2); } int main() { test_maxi(); return 0; } I compiled it using gcc test.c -o test -lcunit on Ubuntu. I get this error when trying to launch it: test: TestRun.c:159: CU_assertImplementation: Assertion `((void *)0) != f_pCurSuite' failed. Aborted (core dumped) What does it mean? I found nothing about it on the internet. 回答1: CUnit works on