C程序:使用 googletest 测试框架
googletest C/C++ 测试框架非常好用,介绍及下载请看 http://code.google.com/p/googletest/
//============================================================================
// 使用 googletest 测试框架
//============================================================================
// Returns n! (the factorial of n). For negative n, n! is defined to be 1.
int Factorial(int n)
{
int result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
#include "src/gtest-all.cc"
// Tests Factorial().
// Tests factorial of negative numbers.
TEST(FactorialTest, Negative)
{
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_TRUE(Factorial(-10)> 0);
}
// Tests factorial of 0.
TEST(FactorialTest, Zero)
{
EXPECT_EQ(1, Factorial(0));
}
// Tests factorial of positive numbers.
TEST(FactorialTest, Positive)
{
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
#include "src/gtest_main.cc"
相关文档:
1) -/+: 这个称做scope, 如果在函数前面是- ,那么理解为一般的函数;如果是+, 可以理解为c++中的static函数
2) 函数的参数声明:
如果没有参数的话,在函数名后面,可以什么都不写;
如果只有一个参数,在 : 后面声明参数的类型和名称;
如果有多个参数的话,每个参数前面都要有一个 : , 然后接着是参数类型和参 ......
在C++中,关于CPP的头文件互相包含的问题很让人头疼,其实我们谁也不愿意弄的结构混乱,难以理解,但有时又是有必须的。
假定当前有两个头文件分别为 A.h 和 B.h,内容分别如下:
A.h内容为:
#ifndef  ......
C没有类
这让人很疲惫
对象的说法很时髦
不就是继承封装组合人人会
右走是C++,这个大众都熟悉它
左走就是objective-c,躲在僻静僻静的麦金塔
本是同根生的C
如何高举面向对象的大旗
求同存异标新立异且听一一细分清
对象的C
是不同的C
类的处理与众不同重点要区分
不重复是我的口头禅
任何时候我只说一次告诉 ......
#include <stdio.h>
#include <string.h> /* 程序多次调用biodkey(),应包含头文件bios.h */
#include <bios.h><br>/* 程序多次调用clrscr(),应包含头文件conio.h */
#include <conio.h>
#define MAX 100
#define PAGE 2
#define PRINT1 printf("------------------------------ ......
最近在研究操作系统,《自己动手写操作系统》上第5章讲了asm和c函数之间互调用,目的是使用c来写操作系统内核的代码,毕竟用汇编写代码还是很费时间的事。
配置Linux开发环境实在是太麻烦,要装虚拟机,还要配置老半天。于是就想能都在windows环境下实现互调用,很自然的想到了ming ......