42 using std::stringstream;
63 TEST(CardinalityTest, IsDefaultConstructable) {
68 TEST(CardinalityTest, IsCopyable) {
82 TEST(CardinalityTest, IsOverSaturatedByCallCountWorks) {
83 const Cardinality c =
AtMost(5);
91 TEST(CardinalityTest, CanDescribeActualCallCount) {
93 Cardinality::DescribeActualCallCountTo(0, &ss0);
97 Cardinality::DescribeActualCallCountTo(1, &ss1);
101 Cardinality::DescribeActualCallCountTo(2, &ss2);
105 Cardinality::DescribeActualCallCountTo(3, &ss3);
127 TEST(AnyNumberTest, HasCorrectBounds) {
129 EXPECT_EQ(0, c.ConservativeLowerBound());
130 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
135 TEST(AtLeastTest, OnNegativeNumber) {
138 },
"The invocation lower bound must be >= 0");
141 TEST(AtLeastTest, OnZero) {
142 const Cardinality c =
AtLeast(0);
155 TEST(AtLeastTest, OnPositiveNumber) {
156 const Cardinality c =
AtLeast(2);
182 TEST(AtLeastTest, HasCorrectBounds) {
183 const Cardinality c =
AtLeast(2);
184 EXPECT_EQ(2, c.ConservativeLowerBound());
185 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
190 TEST(AtMostTest, OnNegativeNumber) {
193 },
"The invocation upper bound must be >= 0");
196 TEST(AtMostTest, OnZero) {
197 const Cardinality c =
AtMost(0);
210 TEST(AtMostTest, OnPositiveNumber) {
211 const Cardinality c =
AtMost(2);
237 TEST(AtMostTest, HasCorrectBounds) {
238 const Cardinality c =
AtMost(2);
239 EXPECT_EQ(0, c.ConservativeLowerBound());
240 EXPECT_EQ(2, c.ConservativeUpperBound());
245 TEST(BetweenTest, OnNegativeStart) {
248 },
"The invocation lower bound must be >= 0, but is actually -1");
251 TEST(BetweenTest, OnNegativeEnd) {
254 },
"The invocation upper bound must be >= 0, but is actually -2");
257 TEST(BetweenTest, OnStartBiggerThanEnd) {
260 },
"The invocation upper bound (1) must be >= "
261 "the invocation lower bound (2)");
264 TEST(BetweenTest, OnZeroStartAndZeroEnd) {
265 const Cardinality c =
Between(0, 0);
279 TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
280 const Cardinality c =
Between(0, 2);
297 TEST(BetweenTest, OnSameStartAndEnd) {
298 const Cardinality c =
Between(3, 3);
315 TEST(BetweenTest, OnDifferentStartAndEnd) {
316 const Cardinality c =
Between(3, 5);
336 TEST(BetweenTest, HasCorrectBounds) {
337 const Cardinality c =
Between(3, 5);
338 EXPECT_EQ(3, c.ConservativeLowerBound());
339 EXPECT_EQ(5, c.ConservativeUpperBound());
344 TEST(ExactlyTest, OnNegativeNumber) {
347 },
"The invocation lower bound must be >= 0");
350 TEST(ExactlyTest, OnZero) {
351 const Cardinality c =
Exactly(0);
364 TEST(ExactlyTest, OnPositiveNumber) {
365 const Cardinality c =
Exactly(2);
388 TEST(ExactlyTest, HasCorrectBounds) {
389 const Cardinality c =
Exactly(3);
390 EXPECT_EQ(3, c.ConservativeLowerBound());
391 EXPECT_EQ(3, c.ConservativeUpperBound());
397 class EvenCardinality :
public CardinalityInterface {
400 virtual bool IsSatisfiedByCallCount(
int call_count)
const {
401 return (call_count % 2 == 0);
405 virtual bool IsSaturatedByCallCount(
int )
const {
410 virtual void DescribeTo(::std::ostream* ss)
const {
411 *ss <<
"called even number of times";
415 TEST(MakeCardinalityTest, ConstructsCardinalityFromInterface) {
425 EXPECT_EQ(
"called even number of times", ss.str());