-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListQueue.t.cpp
More file actions
104 lines (87 loc) · 2.05 KB
/
Copy pathListQueue.t.cpp
File metadata and controls
104 lines (87 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "wndx/algo/ds/ListQueue.hpp"
#include <gtest/gtest.h>
#include <stdexcept> // std::runtime_error
#include <string>
using namespace wndx::algo;
class ListQueueTest : public ::testing::Test
{
protected:
ds::ListQueue<int> *queue;
ListQueueTest()
{
queue = new ds::ListQueue<int>();
}
ListQueueTest(const int &elem)
{
queue = new ds::ListQueue<int>(elem);
}
virtual ~ListQueueTest()
{
if (queue) delete queue;
}
virtual void SetUp()
{}
virtual void TearDown()
{
queue->clear();
}
};
TEST_F(ListQueueTest, testEmptyQueue)
{
EXPECT_TRUE(queue->empty());
EXPECT_EQ(queue->size(), 0);
}
TEST_F(ListQueueTest, testDequeueOnEmpty)
{
try {
queue->dequeue();
} catch(std::runtime_error const &err) {
EXPECT_EQ(err.what(), std::string("Empty Queue"));
} catch(...) {
FAIL() << "Expected std::runtime_error Empty Queue";
}
}
TEST_F(ListQueueTest, testPeekOnEmpty)
{
try {
queue->peek();
} catch(std::runtime_error const &err) {
EXPECT_EQ(err.what(), std::string("Empty Queue"));
} catch(...) {
FAIL() << "Expected std::runtime_error Empty Queue";
}
}
TEST_F(ListQueueTest, testEnqueue)
{
queue->enqueue(2);
EXPECT_EQ(queue->size(), 1);
}
TEST_F(ListQueueTest, testPeek)
{
queue->enqueue(2);
EXPECT_EQ(2, queue->peek());
EXPECT_EQ(queue->size(), 1);
}
TEST_F(ListQueueTest, testDequeue)
{
queue->enqueue(2);
EXPECT_EQ(2, queue->dequeue());
EXPECT_EQ(queue->size(), 0);
}
TEST_F(ListQueueTest, testExhaustively)
{
ASSERT_TRUE(queue->empty());
queue->enqueue(1);
ASSERT_FALSE(queue->empty());
queue->enqueue(2);
EXPECT_EQ(queue->size(), 2);
EXPECT_EQ(1, queue->peek());
EXPECT_EQ(queue->size(), 2);
EXPECT_EQ(1, queue->dequeue());
EXPECT_EQ(queue->size(), 1);
EXPECT_EQ(2, queue->peek());
EXPECT_EQ(queue->size(), 1);
EXPECT_EQ(2, queue->dequeue());
EXPECT_EQ(queue->size(), 0);
ASSERT_TRUE(queue->empty());
}