|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
| 9 | +#include "src/__support/CPP/array.h" |
9 | 10 | #include "src/__support/fixedvector.h"
|
10 | 11 | #include "test/UnitTest/Test.h"
|
11 | 12 |
|
@@ -59,3 +60,37 @@ TEST(LlvmLibcFixedVectorTest, Iteration) {
|
59 | 60 | for (auto it = v.rbegin(), e = v.rend(); it != e; ++it)
|
60 | 61 | ASSERT_GT(*it, -1);
|
61 | 62 | }
|
| 63 | + |
| 64 | +TEST(LlvmLibcFixedVectorTest, ConstructionFromIterators) { |
| 65 | + LIBC_NAMESPACE::cpp::array<int, 4> arr{1, 2, 3, 4}; |
| 66 | + LIBC_NAMESPACE::FixedVector<int, 5> vec(arr.begin(), arr.end()); |
| 67 | + ASSERT_EQ(vec.size(), arr.size()); |
| 68 | + for (size_t i = 0; i < arr.size(); ++i) |
| 69 | + ASSERT_EQ(vec[i], arr[i]); |
| 70 | +} |
| 71 | + |
| 72 | +TEST(LlvmLibcFixedVectorTest, ConstructionFromCountAndValue) { |
| 73 | + constexpr int kVal = 10; |
| 74 | + // TODO: If the first argument here were just `4`, then we'd have no way to |
| 75 | + // disambiguate between the FixedVector ctor that uses iterators vs the one |
| 76 | + // taking a count and `cosnt T &`. Using `4` would result in a compile error. |
| 77 | + // Formally, we can ensure the count + reference ctor is used if we gate the |
| 78 | + // iterator ctor on checking if the type has the `input_iterator_tag` via |
| 79 | + // iterator_traits, but we'd have to plumb that through which can be done |
| 80 | + // separately. Note the snafu we hit here only happens because we happen to |
| 81 | + // test with containters using integral types. |
| 82 | + LIBC_NAMESPACE::FixedVector<int, 5> vec(size_t(4), kVal); |
| 83 | + ASSERT_EQ(vec.size(), size_t(4)); |
| 84 | + for (size_t i = 0; i < vec.size(); ++i) |
| 85 | + ASSERT_EQ(vec[i], kVal); |
| 86 | +} |
| 87 | + |
| 88 | +TEST(LlvmLibcFixedVectorTest, ForwardIteration) { |
| 89 | + LIBC_NAMESPACE::cpp::array<int, 4> arr{1, 2, 3, 4}; |
| 90 | + LIBC_NAMESPACE::FixedVector<int, 5> vec(arr.begin(), arr.end()); |
| 91 | + ASSERT_EQ(vec.size(), arr.size()); |
| 92 | + for (auto it = vec.begin(); it != vec.end(); ++it) { |
| 93 | + auto idx = it - vec.begin(); |
| 94 | + ASSERT_EQ(*it, arr[idx]); |
| 95 | + } |
| 96 | +} |
0 commit comments