Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / __support / fixedvector_test.cpp
bloba70ebfabed227009f9d4da30b133d6290a32f6d8
1 //===-- Unittests for FixedVector -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/fixedvector.h"
10 #include "test/UnitTest/Test.h"
12 TEST(LlvmLibcFixedVectorTest, PushAndPop) {
13 LIBC_NAMESPACE::FixedVector<int, 20> fixed_vector;
14 ASSERT_TRUE(fixed_vector.empty());
15 for (int i = 0; i < 20; i++)
16 ASSERT_TRUE(fixed_vector.push_back(i));
17 ASSERT_FALSE(fixed_vector.empty());
18 ASSERT_FALSE(fixed_vector.push_back(123));
19 for (int i = 20; i > 0; --i) {
20 ASSERT_EQ(fixed_vector.back(), i - 1);
21 ASSERT_TRUE(fixed_vector.pop_back());
23 ASSERT_FALSE(fixed_vector.pop_back());
24 ASSERT_TRUE(fixed_vector.empty());
27 TEST(LlvmLibcFixedVectorTest, Reset) {
28 LIBC_NAMESPACE::FixedVector<int, 20> fixed_vector;
29 ASSERT_TRUE(fixed_vector.empty());
30 for (int i = 0; i < 20; i++)
31 ASSERT_TRUE(fixed_vector.push_back(i));
32 ASSERT_FALSE(fixed_vector.empty());
33 fixed_vector.reset();
34 ASSERT_TRUE(fixed_vector.empty());
37 TEST(LlvmLibcFixedVectorTest, Destroy) {
38 LIBC_NAMESPACE::FixedVector<int, 20> fixed_vector;
39 ASSERT_TRUE(fixed_vector.empty());
40 for (int i = 0; i < 20; i++)
41 ASSERT_TRUE(fixed_vector.push_back(i));
42 ASSERT_FALSE(fixed_vector.empty());
43 LIBC_NAMESPACE::FixedVector<int, 20>::destroy(&fixed_vector);
44 ASSERT_TRUE(fixed_vector.empty());