proxygen
sample1_unittest.cc File Reference
#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (FactorialTest, Negative)
 
 TEST (FactorialTest, Zero)
 
 TEST (FactorialTest, Positive)
 
 TEST (IsPrimeTest, Negative)
 
 TEST (IsPrimeTest, Trivial)
 
 TEST (IsPrimeTest, Positive)
 

Function Documentation

TEST ( FactorialTest  ,
Negative   
)

Definition at line 79 of file sample1_unittest.cc.

References EXPECT_EQ, EXPECT_GT, and Factorial().

79  {
80  // This test is named "Negative", and belongs to the "FactorialTest"
81  // test case.
82  EXPECT_EQ(1, Factorial(-5));
83  EXPECT_EQ(1, Factorial(-1));
84  EXPECT_GT(Factorial(-10), 0);
85 
86  // <TechnicalDetails>
87  //
88  // EXPECT_EQ(expected, actual) is the same as
89  //
90  // EXPECT_TRUE((expected) == (actual))
91  //
92  // except that it will print both the expected value and the actual
93  // value when the assertion fails. This is very helpful for
94  // debugging. Therefore in this case EXPECT_EQ is preferred.
95  //
96  // On the other hand, EXPECT_TRUE accepts any Boolean expression,
97  // and is thus more general.
98  //
99  // </TechnicalDetails>
100 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int Factorial(int n)
Definition: sample1.cc:37
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( FactorialTest  ,
Zero   
)

Definition at line 103 of file sample1_unittest.cc.

References EXPECT_EQ, and Factorial().

103  {
104  EXPECT_EQ(1, Factorial(0));
105 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int Factorial(int n)
Definition: sample1.cc:37
TEST ( FactorialTest  ,
Positive   
)

Definition at line 108 of file sample1_unittest.cc.

References EXPECT_EQ, and Factorial().

108  {
109  EXPECT_EQ(1, Factorial(1));
110  EXPECT_EQ(2, Factorial(2));
111  EXPECT_EQ(6, Factorial(3));
112  EXPECT_EQ(40320, Factorial(8));
113 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int Factorial(int n)
Definition: sample1.cc:37
TEST ( IsPrimeTest  ,
Negative   
)

Definition at line 119 of file sample1_unittest.cc.

References EXPECT_FALSE, and IsPrime().

119  {
120  // This test belongs to the IsPrimeTest test case.
121 
122  EXPECT_FALSE(IsPrime(-1));
123  EXPECT_FALSE(IsPrime(-2));
124  EXPECT_FALSE(IsPrime(INT_MIN));
125 }
bool IsPrime(int n)
Definition: sample1.cc:47
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( IsPrimeTest  ,
Trivial   
)

Definition at line 128 of file sample1_unittest.cc.

References EXPECT_FALSE, EXPECT_TRUE, and IsPrime().

128  {
129  EXPECT_FALSE(IsPrime(0));
130  EXPECT_FALSE(IsPrime(1));
131  EXPECT_TRUE(IsPrime(2));
132  EXPECT_TRUE(IsPrime(3));
133 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
bool IsPrime(int n)
Definition: sample1.cc:47
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( IsPrimeTest  ,
Positive   
)

Definition at line 136 of file sample1_unittest.cc.

References EXPECT_FALSE, EXPECT_TRUE, and IsPrime().

136  {
137  EXPECT_FALSE(IsPrime(4));
138  EXPECT_TRUE(IsPrime(5));
139  EXPECT_FALSE(IsPrime(6));
140  EXPECT_TRUE(IsPrime(23));
141 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
bool IsPrime(int n)
Definition: sample1.cc:47
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862