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

29 lines
842 B
C++

#include "DynamicArray.h"
#include <boost/test/unit_test.hpp>
using namespace Kylin;
class DynamicArrayTest {
public:
DynamicArray<size_t> array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // size:10
};
BOOST_AUTO_TEST_SUITE(DynamicArrayTestCase)
BOOST_FIXTURE_TEST_CASE(Size, DynamicArrayTest) { BOOST_CHECK_EQUAL(array.size(), 10); }
BOOST_FIXTURE_TEST_CASE(InitializerListConstructor, DynamicArrayTest) {
for (size_t i = 0; i < array.size(); i++) {
BOOST_CHECK_EQUAL(array[i], i);
}
}
BOOST_FIXTURE_TEST_CASE(IndexOf, DynamicArrayTest) { BOOST_CHECK_EQUAL(array.indexOf(5), 5); }
BOOST_FIXTURE_TEST_CASE(ForEach, DynamicArrayTest) {
size_t index = 0;
for (auto value : array) {
BOOST_CHECK_EQUAL(value, index++);
}
BOOST_CHECK_EQUAL(index, 10);
}
BOOST_AUTO_TEST_SUITE_END()