TEST(WTF_Vector, MoveOnly_Insert) { Vector<MoveOnly> vector; for (size_t i = 0; i < 100; ++i) { MoveOnly moveOnly(i); vector.insert(0, std::move(moveOnly)); EXPECT_EQ(0U, moveOnly.value()); } EXPECT_EQ(vector.size(), 100U); for (size_t i = 0; i < 100; ++i) EXPECT_EQ(99 - i, vector[i].value()); for (size_t i = 0; i < 200; i += 2) { MoveOnly moveOnly(1000 + i); vector.insert(i, std::move(moveOnly)); EXPECT_EQ(0U, moveOnly.value()); } EXPECT_EQ(200U, vector.size()); for (size_t i = 0; i < 200; ++i) { if (i % 2) EXPECT_EQ(99 - i / 2, vector[i].value()); else EXPECT_EQ(1000 + i, vector[i].value()); } }
TEST(WTF_Vector, MoveOnly_Append) { Vector<MoveOnly> vector; for (size_t i = 0; i < 100; ++i) { MoveOnly moveOnly(i); vector.append(std::move(moveOnly)); EXPECT_EQ(0U, moveOnly.value()); } for (size_t i = 0; i < 100; ++i) EXPECT_EQ(i, vector[i].value()); for (size_t i = 0; i < 16; ++i) { Vector<MoveOnly> vector; vector.append(i); for (size_t j = 0; j < i; ++j) vector.append(j); vector.append(std::move(vector[0])); EXPECT_EQ(0U, vector[0].value()); for (size_t j = 0; j < i; ++j) EXPECT_EQ(j, vector[j + 1].value()); EXPECT_EQ(i, vector.last().value()); } }
TEST(WTF_Vector, MoveOnly_UncheckedAppend) { Vector<MoveOnly> vector; vector.reserveInitialCapacity(100); for (size_t i = 0; i < 100; ++i) { MoveOnly moveOnly(i); vector.uncheckedAppend(std::move(moveOnly)); EXPECT_EQ(0U, moveOnly.value()); } for (size_t i = 0; i < 100; ++i) EXPECT_EQ(i, vector[i].value()); }
TEST(WTF_Vector, MoveOnly_TakeLast) { Vector<MoveOnly> vector; for (size_t i = 0; i < 100; ++i) { MoveOnly moveOnly(i); vector.append(std::move(moveOnly)); EXPECT_EQ(0U, moveOnly.value()); } EXPECT_EQ(100U, vector.size()); for (size_t i = 0; i < 100; ++i) EXPECT_EQ(99 - i, vector.takeLast().value()); EXPECT_EQ(0U, vector.size()); }
TEST(WTF_HashSet, MoveOnly) { HashSet<MoveOnly> hashSet; for (size_t i = 0; i < 100; ++i) { MoveOnly moveOnly(i + 1); hashSet.add(WTF::move(moveOnly)); } for (size_t i = 0; i < 100; ++i) EXPECT_TRUE(hashSet.contains(MoveOnly(i + 1))); for (size_t i = 0; i < 100; ++i) EXPECT_TRUE(hashSet.remove(MoveOnly(i + 1))); EXPECT_TRUE(hashSet.isEmpty()); for (size_t i = 0; i < 100; ++i) hashSet.add(MoveOnly(i + 1)); for (size_t i = 0; i < 100; ++i) EXPECT_TRUE(hashSet.take(MoveOnly(i + 1)) == MoveOnly(i + 1)); EXPECT_TRUE(hashSet.isEmpty()); for (size_t i = 0; i < 100; ++i) hashSet.add(MoveOnly(i + 1)); HashSet<MoveOnly> secondSet; for (size_t i = 0; i < 100; ++i) secondSet.add(hashSet.takeAny()); EXPECT_TRUE(hashSet.isEmpty()); for (size_t i = 0; i < 100; ++i) EXPECT_TRUE(secondSet.contains(MoveOnly(i + 1))); }