sample3_unittest.cc (googletest-release-1.11.0) | : | sample3_unittest.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 70 | skipping to change at line 70 | |||
// | // | |||
// </TechnicalDetails> | // </TechnicalDetails> | |||
#include "sample3-inl.h" | #include "sample3-inl.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
namespace { | namespace { | |||
// To use a test fixture, derive a class from testing::Test. | // To use a test fixture, derive a class from testing::Test. | |||
class QueueTestSmpl3 : public testing::Test { | class QueueTestSmpl3 : public testing::Test { | |||
protected: // You should make the members protected s.t. they can be | protected: // You should make the members protected s.t. they can be | |||
// accessed from sub-classes. | // accessed from sub-classes. | |||
// virtual void SetUp() will be called before each test is run. You | // virtual void SetUp() will be called before each test is run. You | |||
// should define it if you need to initialize the variables. | // should define it if you need to initialize the variables. | |||
// Otherwise, this can be skipped. | // Otherwise, this can be skipped. | |||
void SetUp() override { | void SetUp() override { | |||
q1_.Enqueue(1); | q1_.Enqueue(1); | |||
q2_.Enqueue(2); | q2_.Enqueue(2); | |||
q2_.Enqueue(3); | q2_.Enqueue(3); | |||
} | } | |||
// virtual void TearDown() will be called after each test is run. | // virtual void TearDown() will be called after each test is run. | |||
// You should define it if there is cleanup work to do. Otherwise, | // You should define it if there is cleanup work to do. Otherwise, | |||
// you don't have to provide it. | // you don't have to provide it. | |||
// | // | |||
// virtual void TearDown() { | // virtual void TearDown() { | |||
// } | // } | |||
// A helper function that some test uses. | // A helper function that some test uses. | |||
static int Double(int n) { | static int Double(int n) { return 2 * n; } | |||
return 2*n; | ||||
} | ||||
// A helper function for testing Queue::Map(). | // A helper function for testing Queue::Map(). | |||
void MapTester(const Queue<int> * q) { | void MapTester(const Queue<int>* q) { | |||
// Creates a new queue, where each element is twice as big as the | // Creates a new queue, where each element is twice as big as the | |||
// corresponding one in q. | // corresponding one in q. | |||
const Queue<int> * const new_q = q->Map(Double); | const Queue<int>* const new_q = q->Map(Double); | |||
// Verifies that the new queue has the same size as q. | // Verifies that the new queue has the same size as q. | |||
ASSERT_EQ(q->Size(), new_q->Size()); | ASSERT_EQ(q->Size(), new_q->Size()); | |||
// Verifies the relationship between the elements of the two queues. | // Verifies the relationship between the elements of the two queues. | |||
for (const QueueNode<int>*n1 = q->Head(), *n2 = new_q->Head(); | for (const QueueNode<int>*n1 = q->Head(), *n2 = new_q->Head(); | |||
n1 != nullptr; n1 = n1->next(), n2 = n2->next()) { | n1 != nullptr; n1 = n1->next(), n2 = n2->next()) { | |||
EXPECT_EQ(2 * n1->element(), n2->element()); | EXPECT_EQ(2 * n1->element(), n2->element()); | |||
} | } | |||
skipping to change at line 127 | skipping to change at line 124 | |||
// instead of TEST. | // instead of TEST. | |||
// Tests the default c'tor. | // Tests the default c'tor. | |||
TEST_F(QueueTestSmpl3, DefaultConstructor) { | TEST_F(QueueTestSmpl3, DefaultConstructor) { | |||
// You can access data in the test fixture here. | // You can access data in the test fixture here. | |||
EXPECT_EQ(0u, q0_.Size()); | EXPECT_EQ(0u, q0_.Size()); | |||
} | } | |||
// Tests Dequeue(). | // Tests Dequeue(). | |||
TEST_F(QueueTestSmpl3, Dequeue) { | TEST_F(QueueTestSmpl3, Dequeue) { | |||
int * n = q0_.Dequeue(); | int* n = q0_.Dequeue(); | |||
EXPECT_TRUE(n == nullptr); | EXPECT_TRUE(n == nullptr); | |||
n = q1_.Dequeue(); | n = q1_.Dequeue(); | |||
ASSERT_TRUE(n != nullptr); | ASSERT_TRUE(n != nullptr); | |||
EXPECT_EQ(1, *n); | EXPECT_EQ(1, *n); | |||
EXPECT_EQ(0u, q1_.Size()); | EXPECT_EQ(0u, q1_.Size()); | |||
delete n; | delete n; | |||
n = q2_.Dequeue(); | n = q2_.Dequeue(); | |||
ASSERT_TRUE(n != nullptr); | ASSERT_TRUE(n != nullptr); | |||
End of changes. 5 change blocks. | ||||
7 lines changed or deleted | 4 lines changed or added |