[clang] Introduce paged vector (PR #66430)
Giulio Eulisse via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 19 15:06:13 PDT 2023
================
@@ -0,0 +1,265 @@
+//===- 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.materialisedBegin().getIndex(), 0ULL);
+ EXPECT_EQ(V.materialisedEnd().getIndex(), 0ULL);
+ EXPECT_EQ(std::distance(V.materialisedBegin(), V.materialisedEnd()), 0LL);
+}
+
+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.materialisedBegin().getIndex(), 2ULL);
+ EXPECT_EQ(V.materialisedEnd().getIndex(), 2ULL);
+ EXPECT_EQ(std::distance(V.materialisedBegin(), V.materialisedEnd()), 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;
+ }
+ EXPECT_EQ(V.empty(), false);
+ EXPECT_EQ(V.size(), 10ULL);
+ EXPECT_EQ(V.capacity(), 10ULL);
+ EXPECT_EQ(V.materialisedBegin().getIndex(), 0ULL);
+ EXPECT_EQ(V.materialisedEnd().getIndex(), 10ULL);
+ EXPECT_EQ(std::distance(V.materialisedBegin(), V.materialisedEnd()), 10LL);
+ for (int I = 0; I < 10; ++I) {
+ EXPECT_EQ(V[I], I);
+ }
+}
+
+TEST(PagedVectorTest, HalfPageFillingTest) {
+ PagedVector<int, 10> V;
+ V.resize(5);
+ EXPECT_EQ(V.empty(), false);
+ EXPECT_EQ(V.size(), 5ULL);
+ EXPECT_EQ(V.capacity(), 10ULL);
+ for (int I = 0; I < 5; ++I) {
+ V[I] = I;
+ }
+ EXPECT_EQ(std::distance(V.materialisedBegin(), V.materialisedEnd()), 5LL);
+ for (int I = 0; I < 5; ++I) {
+ EXPECT_EQ(V[I], I);
+ }
----------------
ktf wrote:
It would actually assert because the index is out of bound. I will add an appropriate EXPECT_DEATH(...)
https://github.com/llvm/llvm-project/pull/66430
More information about the cfe-commits
mailing list