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"
Ïà¹ØÎĵµ£º
ÔÚC++ÖУ¬¹ØÓÚCPPµÄÍ·Îļþ»¥Ïà°üº¬µÄÎÊÌâºÜÈÃÈËÍ·ÌÛ£¬ÆäʵÎÒÃÇËÒ²²»Ô¸ÒâŪµÄ½á¹¹»ìÂÒ£¬ÄÑÒÔÀí½â£¬µ«ÓÐʱÓÖÊÇÓбØÐëµÄ¡£
¼Ù¶¨µ±Ç°ÓÐÁ½¸öÍ·Îļþ·Ö±ðΪ A.h ºÍ B.h£¬ÄÚÈÝ·Ö±ðÈçÏ£º
A.hÄÚÈÝΪ£º
#ifndef  ......
ÌâÍâÆª£ºµ¥Ôª²âÊÔÄÑÓÚ³¤ÆÚ¼á³ÖµÄÔÒòÓë½â¾ö̽ÌÖ
ÉÏһƪ¡¶µ¥Ôª²âÊÔÐ§Òæ¡·£¬ÓÐÍøÓÑÆÀÂÛ˵£º“µ¥Ôª²âÊԵĺô¦»ù±¾ÈËÈËÖªµÀ£¬¾ÍÊÇÄѼá³Ö£¡”¡£ÕâÒ»ÆÀÂÛÑÏÖØÌáÐÑÁËÎÒ£¬²»´í£¬“ÄѼá³Ö”Ò²ÊÇÒ»¸öÆÕ±éÏÖ×´¡£Èç¹û²»Äܼá³Ö£¬ÄÇÒ»Çж¼Êǰ״Òò´Ë£¬ÕâÀï²åÈëÒ»¸öÌâÍâÆª£¬Ì½ÌÖµ¥Ôª²âÊÔÄÑÓÚ³¤Æ ......
#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("------------------------------ ......
Êä³öì³²¨ÄÇÆõÊýÁÐǰN¸öºÏÊý£¬ËĸöÒ»ÐУ¬NÓÉʹÓÃÕßÊäÈ룬½éÓÚ10µ½30Ö®¼ä¡£
#include<stdio.h>
#include<math.h>
int fab(int);
int judge(int);
int main()
{
int a[30]={0};
int i,n,t=0;
do
{
printf("Input the number\n");
scanf("%d",&n);
}
while(n>3 ......
ÓúêʵÏÖÒ»¸öswap¹¦ÄÜ
#include <stdio.h>
#include <stdlib.h>
#define SWAP( TYPE,ARG1,ARG2 ) \
void TYPE##Swap( TYPE *p, TYPE *q ) \
{ \
TYPE tmp = *p; \
*p = *q; \
*q = tmp; \
} \
TYPE##Swap(&ARG1,&ARG2 ......