81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
#include "StaticLinkedList.h"
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
using namespace Kylin;
|
|
|
|
class StaticLinkedListTest {
|
|
public:
|
|
StaticLinkedListTest() {
|
|
for (size_t i = 0; i < 8; i++) {
|
|
list.append(i);
|
|
}
|
|
}
|
|
StaticLinkedList<size_t, 10> list;
|
|
};
|
|
BOOST_AUTO_TEST_SUITE(StaticLinkedListTestCase)
|
|
BOOST_FIXTURE_TEST_CASE(At, StaticLinkedListTest) { BOOST_CHECK_EQUAL(list.at(5), 5); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Size, StaticLinkedListTest) { BOOST_CHECK_EQUAL(list.size(), 8); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Last, StaticLinkedListTest) { BOOST_CHECK_EQUAL(list.last(), 7); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(EmptyListCallLastCauseException, StaticLinkedListTest) {
|
|
StaticLinkedList<size_t, 10> emptyList;
|
|
BOOST_CHECK_THROW(emptyList.last(), InvalidOperationException);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(RemoveAt, StaticLinkedListTest) {
|
|
list.removeAt(3);
|
|
BOOST_CHECK_EQUAL(list.at(3), 4);
|
|
BOOST_CHECK_EQUAL(list.length(), 7);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Clear, StaticLinkedListTest) {
|
|
list.clear();
|
|
BOOST_CHECK_EQUAL(list.length(), 0);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(IndexOf, StaticLinkedListTest) { BOOST_CHECK_EQUAL(list.indexOf(5), 5); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Append, StaticLinkedListTest) {
|
|
list.append(198);
|
|
BOOST_CHECK_EQUAL(list.length(), 9);
|
|
BOOST_CHECK_EQUAL(list.at(8), 198);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(InsertToIndexLessThenSize, StaticLinkedListTest) {
|
|
list.insert(4, 456);
|
|
BOOST_CHECK_EQUAL(list.length(), 9);
|
|
BOOST_CHECK_EQUAL(list.at(4), 456);
|
|
BOOST_CHECK_EQUAL(list.at(5), 4);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(InsertToIndexEuqalSize, StaticLinkedListTest) {
|
|
list.insert(list.size(), 456);
|
|
BOOST_CHECK_EQUAL(list.length(), 9);
|
|
BOOST_CHECK_EQUAL(list.at(list.size() - 1), 456);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Swap, StaticLinkedListTest) {
|
|
StaticLinkedList<size_t, 10> list2;
|
|
for (size_t i = 0; i < 5; i++) {
|
|
list2.insert(list2.length(), i + 10);
|
|
}
|
|
BOOST_CHECK_THROW(list2.swap(list), InvalidOperationException);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(CopyConstructor, StaticLinkedListTest) {
|
|
auto list2(list);
|
|
BOOST_CHECK_EQUAL(list2.size(), 8);
|
|
BOOST_CHECK_EQUAL(list2[5], 5);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Iterator, StaticLinkedListTest) {
|
|
size_t value = 0;
|
|
for (const auto &v : list) {
|
|
BOOST_CHECK_EQUAL(v, value++);
|
|
}
|
|
BOOST_CHECK_EQUAL(value, 8);
|
|
}
|
|
BOOST_AUTO_TEST_SUITE_END()
|