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

39 lines
981 B
C++

#include "StaticArray.h"
#include <boost/test/unit_test.hpp>
using namespace Kylin;
class StaticArrayTest {
public:
Kylin::StaticArray<size_t, 10> array;
};
BOOST_AUTO_TEST_SUITE(StaticArrayTestCase)
BOOST_FIXTURE_TEST_CASE(Size, StaticArrayTest) { BOOST_CHECK_EQUAL(array.size(), 10); }
BOOST_FIXTURE_TEST_CASE(Length, StaticArrayTest) { BOOST_CHECK_EQUAL(array.length(), 10); }
BOOST_FIXTURE_TEST_CASE(At, StaticArrayTest) {
array[3] = 5;
BOOST_CHECK_EQUAL(array.at(3), 5);
}
BOOST_FIXTURE_TEST_CASE(IndexOf, StaticArrayTest) {
array[3] = 5;
BOOST_CHECK_EQUAL(array.indexOf(5), 3);
}
BOOST_FIXTURE_TEST_CASE(ForEach, StaticArrayTest) {
size_t index = 0;
for (auto &value : array) {
value = index++;
}
BOOST_CHECK_EQUAL(index, 10);
index = 0;
for (auto value : array) {
BOOST_CHECK_EQUAL(value, index++);
}
BOOST_CHECK_EQUAL(index, 10);
}
BOOST_AUTO_TEST_SUITE_END()