aboutsummaryrefslogtreecommitdiff
path: root/src/sched/test_taskqueue.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/sched/test_taskqueue.cc')
-rw-r--r--src/sched/test_taskqueue.cc122
1 files changed, 0 insertions, 122 deletions
diff --git a/src/sched/test_taskqueue.cc b/src/sched/test_taskqueue.cc
deleted file mode 100644
index 217c44d..0000000
--- a/src/sched/test_taskqueue.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-#include <gtest/gtest.h>
-
-#include "../sched.hpp"
-
-struct DebugQueue : public Queue<Task> {
-public:
- void
- expect_ordered() const
- {
- int id = 1;
- for (auto *it = head; it != nullptr; it = it->next) {
- // std::cout << it->node->name << std::endl;
- EXPECT_EQ(it->node->id, id++);
- }
- }
-};
-
-TEST(taskqueue, insert)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- queue.expect_ordered();
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
-}
-
-TEST(taskqueue, removeHead)
-{
- DebugQueue queue;
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, removeTail)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- auto *p5 = new Task{"P5", 5, 1, 10};
- queue.insert(p5);
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p5);
-
- queue.remove(p5);
- delete p5;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, removeLast)
-{
- DebugQueue queue;
-
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- EXPECT_EQ(queue.head->node, p0);
- EXPECT_EQ(queue.tail->node, p0);
-
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head, nullptr);
- EXPECT_EQ(queue.tail, nullptr);
-}
-
-TEST(taskqueue, removeNullptr)
-{
- DebugQueue queue;
- queue.insert(new Task{"P1", 1, 1, 10});
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- queue.insert(new Task{"P4", 4, 1, 10});
- queue.remove(nullptr);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, remove)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
-
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}