Commit 5891bb53 by misterg Committed by Gennadiy Civil

googletest export

- 209457486 Import of OSS PR, https://github.com/google/googletest/pu... by misterg <misterg@google.com> PiperOrigin-RevId: 209457486
parent 9404c5ae
......@@ -38,6 +38,16 @@ int Counter::Increment() {
return counter_++;
}
// Returns the current counter value, and decrements it.
// counter can not be less than 0, return 0 in this case
int Counter::Decrement() {
if (counter_ == 0) {
return counter_;
} else {
return counter_--;
}
}
// Prints the current counter value to STDOUT.
void Counter::Print() const {
printf("%d", counter_);
......
......@@ -43,6 +43,9 @@ class Counter {
// Returns the current counter value, and increments it.
int Increment();
// Returns the current counter value, and decrements it.
int Decrement();
// Prints the current counter value to STDOUT.
void Print() const;
};
......
......@@ -37,12 +37,17 @@ namespace {
TEST(Counter, Increment) {
Counter c;
// Test that counter 0 returns 0
EXPECT_EQ(0, c.Decrement());
// EXPECT_EQ() evaluates its arguments exactly once, so they
// can have side effects.
EXPECT_EQ(0, c.Increment());
EXPECT_EQ(1, c.Increment());
EXPECT_EQ(2, c.Increment());
EXPECT_EQ(3, c.Decrement());
}
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment