Kylin/UnitTest/DataStructure/LinkedQueueTest.cpp
2023-12-27 10:29:16 +08:00

57 lines
1.5 KiB
C++

#include "LinkedQueue.h"
#include <boost/test/unit_test.hpp>
using namespace Kylin;
class LinkedQueueTest {
public:
LinkedQueue<size_t> queue{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
};
BOOST_AUTO_TEST_SUITE(LinkedQueueTestCase)
BOOST_FIXTURE_TEST_CASE(Size, LinkedQueueTest) { BOOST_CHECK_EQUAL(queue.size(), 10); }
BOOST_FIXTURE_TEST_CASE(Head, LinkedQueueTest) { BOOST_CHECK_EQUAL(queue.head(), 0); }
BOOST_FIXTURE_TEST_CASE(Enqueue, LinkedQueueTest) {
queue.enqueue(10);
BOOST_CHECK_EQUAL(queue.size(), 11);
}
BOOST_FIXTURE_TEST_CASE(Dequeue, LinkedQueueTest) {
BOOST_CHECK_EQUAL(queue.dequeue(), 0);
BOOST_CHECK_EQUAL(queue.size(), 9);
}
BOOST_FIXTURE_TEST_CASE(Clear, LinkedQueueTest) {
queue.clear();
BOOST_CHECK_EQUAL(queue.size(), 0);
}
BOOST_FIXTURE_TEST_CASE(Swap, LinkedQueueTest) {
Kylin::LinkedQueue<size_t> queue2;
for (size_t i = 0; i < 5; i++) {
queue2.enqueue(i + 10);
}
queue.swap(queue2);
BOOST_CHECK_EQUAL(queue.size(), 5);
BOOST_CHECK_EQUAL(queue2.size(), 10);
for (size_t i = 0; i < 5; i++) {
BOOST_CHECK_EQUAL(queue.dequeue(), i + 10);
}
for (size_t i = 0; i < 10; i++) {
BOOST_CHECK_EQUAL(queue2.dequeue(), i);
}
}
BOOST_FIXTURE_TEST_CASE(MoveConstructor, LinkedQueueTest) {
auto queue2(std::move(queue));
BOOST_CHECK_EQUAL(queue.empty(), true);
BOOST_CHECK_EQUAL(queue2.size(), 10);
}
BOOST_AUTO_TEST_SUITE_END()