[SandboxVec][BottomUpVec] Fix packing when PHIs are present (#124206)
[llvm-project.git] / libc / test / src / __support / CPP / algorithm_test.cpp
blob00d07bfbfbaaf9b658f549a65386b07299be8807
1 //===-- Unittests for Algorithm -------------------------------------------===//
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/CPP/algorithm.h"
10 #include "src/__support/CPP/array.h"
11 #include "src/__support/macros/config.h"
12 #include "test/UnitTest/Test.h"
14 // TODO(https://github.com/llvm/llvm-project/issues/94066): Add unittests for
15 // the remaining algorithm functions.
16 namespace LIBC_NAMESPACE_DECL {
17 namespace cpp {
19 TEST(LlvmLibcAlgorithmTest, FindIfNot) {
20 array<int, 4> nums{1, 2, 3, 4};
21 EXPECT_EQ(find_if_not(nums.begin(), nums.end(), [](int i) { return i == 0; }),
22 nums.begin());
23 EXPECT_EQ(find_if_not(nums.begin(), nums.end(), [](int i) { return i == 1; }),
24 nums.begin() + 1);
25 EXPECT_EQ(find_if_not(nums.begin(), nums.end(), [](int i) { return i < 4; }),
26 nums.begin() + 3);
27 EXPECT_EQ(find_if_not(nums.begin(), nums.end(), [](int i) { return i < 5; }),
28 nums.end());
30 EXPECT_EQ(
31 find_if_not(nums.begin() + 1, nums.end(), [](int i) { return i == 0; }),
32 nums.begin() + 1);
33 EXPECT_EQ(
34 find_if_not(nums.begin(), nums.begin(), [](int i) { return i == 0; }),
35 nums.begin());
38 TEST(LlvmLibcAlgorithmTest, AllOf) {
39 array<int, 4> nums{1, 2, 3, 4};
40 EXPECT_TRUE(all_of(nums.begin(), nums.end(), [](int i) { return i < 5; }));
41 EXPECT_FALSE(all_of(nums.begin(), nums.end(), [](int i) { return i < 4; }));
42 EXPECT_TRUE(
43 all_of(nums.begin(), nums.begin() + 3, [](int i) { return i < 4; }));
44 EXPECT_TRUE(
45 all_of(nums.begin() + 1, nums.end(), [](int i) { return i > 1; }));
46 EXPECT_TRUE(all_of(nums.begin(), nums.begin(), [](int i) { return i < 0; }));
49 } // namespace cpp
50 } // namespace LIBC_NAMESPACE_DECL