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

67 lines
1.9 KiB
C++

#include <boost/test/unit_test.hpp>
#include "StaticArrayList.h"
using namespace Kylin;
class StaticArrayListTest {
public:
StaticArrayListTest() {
for (size_t i = 0; i < 8; i++) {
list.insert(list.length(), i);
}
}
StaticArrayList<size_t, 10> list;
};
BOOST_AUTO_TEST_SUITE(StaticArrayListTestCase)
BOOST_FIXTURE_TEST_CASE(Size, StaticArrayListTest) { BOOST_CHECK_EQUAL(list.size(), 8); }
BOOST_FIXTURE_TEST_CASE(Capacity, StaticArrayListTest) { BOOST_CHECK_EQUAL(list.capacity(), 10); }
BOOST_FIXTURE_TEST_CASE(Last, StaticArrayListTest) { BOOST_CHECK_EQUAL(list.last(), 7); }
BOOST_FIXTURE_TEST_CASE(At, StaticArrayListTest) { BOOST_CHECK_EQUAL(list.at(4), 4); }
BOOST_FIXTURE_TEST_CASE(CopyConstructor, StaticArrayListTest) {
auto list1 = list;
BOOST_CHECK_EQUAL(list1.size(), 8);
BOOST_CHECK_EQUAL(list1.capacity(), 10);
BOOST_CHECK_EQUAL(list1.at(4), 4);
}
BOOST_FIXTURE_TEST_CASE(Append, StaticArrayListTest) {
list.append(456);
BOOST_CHECK_EQUAL(list.length(), 9);
BOOST_CHECK_EQUAL(list[8], 456);
}
BOOST_FIXTURE_TEST_CASE(Insert, StaticArrayListTest) {
list.insert(4, 789);
BOOST_CHECK_EQUAL(list.length(), 9);
BOOST_CHECK_EQUAL(list[4], 789);
BOOST_CHECK_EQUAL(list[5], 4);
}
BOOST_FIXTURE_TEST_CASE(RemoveAt, StaticArrayListTest) {
list.removeAt(3);
BOOST_CHECK_EQUAL(list[3], 4);
BOOST_CHECK_EQUAL(list.length(), 7);
}
BOOST_FIXTURE_TEST_CASE(Clear, StaticArrayListTest) {
list.clear();
BOOST_CHECK_EQUAL(list.length(), 0);
BOOST_CHECK_EQUAL(list.capacity(), 10);
}
BOOST_FIXTURE_TEST_CASE(IndexOf, StaticArrayListTest) { BOOST_CHECK_EQUAL(list.indexOf(5), 5); }
BOOST_FIXTURE_TEST_CASE(ForEach, StaticArrayListTest) {
size_t index = 0;
for (auto value : list) {
BOOST_CHECK_EQUAL(value, index++);
}
BOOST_CHECK_EQUAL(8, index);
}
BOOST_AUTO_TEST_SUITE_END()