[clang] Introduce paged vector (PR #66430)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 29 02:30:19 PDT 2023
================
@@ -0,0 +1,342 @@
+//===- llvm/unittest/ADT/PagedVectorTest.cpp ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// PagedVector unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/PagedVector.h"
+#include "gtest/gtest.h"
+#include <iterator>
+
+namespace llvm {
+TEST(PagedVectorTest, EmptyTest) {
+ PagedVector<int, 10> V;
+ EXPECT_EQ(V.empty(), true);
+ EXPECT_EQ(V.size(), 0ULL);
+ EXPECT_EQ(V.capacity(), 0ULL);
+ EXPECT_EQ(V.materialized_begin().getIndex(), 0ULL);
+ EXPECT_EQ(V.materialized_end().getIndex(), 0ULL);
+ EXPECT_EQ(std::distance(V.materialized_begin(), V.materialized_end()), 0LL);
+
+ EXPECT_DEATH(V[0], "Index < Size");
+ EXPECT_DEATH(PagedVector<int>(nullptr), "Allocator cannot be null");
+}
+
+TEST(PagedVectorTest, ExpandTest) {
+ PagedVector<int, 10> V;
+ V.resize(2);
+ EXPECT_EQ(V.empty(), false);
+ EXPECT_EQ(V.size(), 2ULL);
+ EXPECT_EQ(V.capacity(), 10ULL);
+ EXPECT_EQ(V.materialized_begin().getIndex(), 2ULL);
+ EXPECT_EQ(V.materialized_end().getIndex(), 2ULL);
+ EXPECT_EQ(std::distance(V.materialized_begin(), V.materialized_end()), 0LL);
+}
+
+TEST(PagedVectorTest, FullPageFillingTest) {
+ PagedVector<int, 10> V;
+ V.resize(10);
+ EXPECT_EQ(V.empty(), false);
+ EXPECT_EQ(V.size(), 10ULL);
+ EXPECT_EQ(V.capacity(), 10ULL);
+ for (int I = 0; I < 10; ++I) {
+ V[I] = I;
+ }
----------------
vgvassilev wrote:
And for the rest of the loops in the test.
https://github.com/llvm/llvm-project/pull/66430
More information about the cfe-commits
mailing list