diff options
author | PiJoules <6019989+PiJoules@users.noreply.github.com> | 2024-06-06 11:25:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-06 11:25:16 -0700 |
commit | 649edb8eb25e82e3ac6fce4788f51759636229ec (patch) | |
tree | 9e81398200b309fdbba256430d7bdd795fcdf314 /libc/test | |
parent | 88cdd9905597ace5b1ac7d080df5326d3399b3f8 (diff) | |
download | llvm-649edb8eb25e82e3ac6fce4788f51759636229ec.zip llvm-649edb8eb25e82e3ac6fce4788f51759636229ec.tar.gz llvm-649edb8eb25e82e3ac6fce4788f51759636229ec.tar.bz2 |
[libc][FixedVector] Add more helper methods (#94278)
This adds:
- A ctor accepting a start and end iterator
- A ctor accepting a count and const T&
- size()
- subscript operators
- begin() and end() iterators
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/__support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libc/test/src/__support/fixedvector_test.cpp | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt index 5afc417..d05377e 100644 --- a/libc/test/src/__support/CMakeLists.txt +++ b/libc/test/src/__support/CMakeLists.txt @@ -132,6 +132,7 @@ add_libc_test( SRCS fixedvector_test.cpp DEPENDS + libc.src.__support.CPP.array libc.src.__support.fixedvector ) diff --git a/libc/test/src/__support/fixedvector_test.cpp b/libc/test/src/__support/fixedvector_test.cpp index e9ffdd0..212e1ae 100644 --- a/libc/test/src/__support/fixedvector_test.cpp +++ b/libc/test/src/__support/fixedvector_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/CPP/array.h" #include "src/__support/fixedvector.h" #include "test/UnitTest/Test.h" @@ -69,3 +70,29 @@ TEST(LlvmLibcFixedVectorTest, Iteration) { for (int &x : v) ASSERT_GE(x, 0); } + +TEST(LlvmLibcFixedVectorTest, ConstructionFromIterators) { + LIBC_NAMESPACE::cpp::array<int, 4> arr{1, 2, 3, 4}; + LIBC_NAMESPACE::FixedVector<int, 5> vec(arr.begin(), arr.end()); + ASSERT_EQ(vec.size(), arr.size()); + for (size_t i = 0; i < arr.size(); ++i) + ASSERT_EQ(vec[i], arr[i]); +} + +TEST(LlvmLibcFixedVectorTest, ConstructionFromCountAndValue) { + constexpr int kVal = 10; + LIBC_NAMESPACE::FixedVector<int, 5> vec(4, kVal); + ASSERT_EQ(vec.size(), size_t(4)); + for (size_t i = 0; i < vec.size(); ++i) + ASSERT_EQ(vec[i], kVal); +} + +TEST(LlvmLibcFixedVectorTest, ForwardIteration) { + LIBC_NAMESPACE::cpp::array<int, 4> arr{1, 2, 3, 4}; + LIBC_NAMESPACE::FixedVector<int, 5> vec(arr.begin(), arr.end()); + ASSERT_EQ(vec.size(), arr.size()); + for (auto it = vec.begin(); it != vec.end(); ++it) { + auto idx = it - vec.begin(); + ASSERT_EQ(*it, arr[idx]); + } +} |