123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #include <limits.h>
- #include <time.h>
- #include "gtest/gtest.h"
- #include "sample1.h"
- #include "sample3-inl.h"
- namespace {
- class QuickTest : public testing::Test {
- protected:
-
-
- void SetUp() override { start_time_ = time(nullptr); }
-
-
- void TearDown() override {
-
- const time_t end_time = time(nullptr);
-
-
-
- EXPECT_TRUE(end_time - start_time_ <= 5) << "The test took too long.";
- }
-
- time_t start_time_;
- };
- class IntegerFunctionTest : public QuickTest {
-
-
- };
- TEST_F(IntegerFunctionTest, Factorial) {
-
- EXPECT_EQ(1, Factorial(-5));
- EXPECT_EQ(1, Factorial(-1));
- EXPECT_GT(Factorial(-10), 0);
-
- EXPECT_EQ(1, Factorial(0));
-
- EXPECT_EQ(1, Factorial(1));
- EXPECT_EQ(2, Factorial(2));
- EXPECT_EQ(6, Factorial(3));
- EXPECT_EQ(40320, Factorial(8));
- }
- TEST_F(IntegerFunctionTest, IsPrime) {
-
- EXPECT_FALSE(IsPrime(-1));
- EXPECT_FALSE(IsPrime(-2));
- EXPECT_FALSE(IsPrime(INT_MIN));
-
- EXPECT_FALSE(IsPrime(0));
- EXPECT_FALSE(IsPrime(1));
- EXPECT_TRUE(IsPrime(2));
- EXPECT_TRUE(IsPrime(3));
-
- EXPECT_FALSE(IsPrime(4));
- EXPECT_TRUE(IsPrime(5));
- EXPECT_FALSE(IsPrime(6));
- EXPECT_TRUE(IsPrime(23));
- }
- class QueueTest : public QuickTest {
- protected:
- void SetUp() override {
-
- QuickTest::SetUp();
-
- q1_.Enqueue(1);
- q2_.Enqueue(2);
- q2_.Enqueue(3);
- }
-
-
-
-
-
-
-
- Queue<int> q0_;
- Queue<int> q1_;
- Queue<int> q2_;
- };
- TEST_F(QueueTest, DefaultConstructor) {
- EXPECT_EQ(0u, q0_.Size());
- }
- TEST_F(QueueTest, Dequeue) {
- int* n = q0_.Dequeue();
- EXPECT_TRUE(n == nullptr);
- n = q1_.Dequeue();
- EXPECT_TRUE(n != nullptr);
- EXPECT_EQ(1, *n);
- EXPECT_EQ(0u, q1_.Size());
- delete n;
- n = q2_.Dequeue();
- EXPECT_TRUE(n != nullptr);
- EXPECT_EQ(2, *n);
- EXPECT_EQ(1u, q2_.Size());
- delete n;
- }
- }
|