1 //===-- Unittests for Algorithm -------------------------------------------===//
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
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
{
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; }),
23 EXPECT_EQ(find_if_not(nums
.begin(), nums
.end(), [](int i
) { return i
== 1; }),
25 EXPECT_EQ(find_if_not(nums
.begin(), nums
.end(), [](int i
) { return i
< 4; }),
27 EXPECT_EQ(find_if_not(nums
.begin(), nums
.end(), [](int i
) { return i
< 5; }),
31 find_if_not(nums
.begin() + 1, nums
.end(), [](int i
) { return i
== 0; }),
34 find_if_not(nums
.begin(), nums
.begin(), [](int i
) { return i
== 0; }),
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; }));
43 all_of(nums
.begin(), nums
.begin() + 3, [](int i
) { return i
< 4; }));
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; }));
50 } // namespace LIBC_NAMESPACE_DECL