Blender V4.3
BLI_binary_search_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
6#include "BLI_vector.hh"
7
8#include "testing/testing.h"
9
11
12TEST(binary_search, Empty)
13{
14 const Vector<int> vec;
15 const int64_t index = find_predicate_begin(vec, [](const int /*value*/) { return true; });
16 EXPECT_EQ(index, 0);
17}
18
19TEST(binary_search, One)
20{
21 const Vector<int> vec = {5};
22 {
23 const int64_t index = find_predicate_begin(vec, [](const int /*value*/) { return false; });
24 EXPECT_EQ(index, 1);
25 }
26 {
27 const int64_t index = find_predicate_begin(vec, [](const int /*value*/) { return true; });
28 EXPECT_EQ(index, 0);
29 }
30}
31
32TEST(binary_search, Multiple)
33{
34 const Vector<int> vec{4, 5, 7, 9, 10, 20, 30};
35 {
36 const int64_t index = find_predicate_begin(vec, [](const int value) { return value > 0; });
37 EXPECT_EQ(index, 0);
38 }
39 {
40 const int64_t index = find_predicate_begin(vec, [](const int value) { return value > 4; });
41 EXPECT_EQ(index, 1);
42 }
43 {
44 const int64_t index = find_predicate_begin(vec, [](const int value) { return value > 10; });
45 EXPECT_EQ(index, 5);
46 }
47 {
48 const int64_t index = find_predicate_begin(vec, [](const int value) { return value >= 25; });
49 EXPECT_EQ(index, 6);
50 }
51 {
52 const int64_t index = find_predicate_begin(vec, [](const int value) { return value >= 30; });
53 EXPECT_EQ(index, 6);
54 }
55 {
56 const int64_t index = find_predicate_begin(vec, [](const int value) { return value > 30; });
57 EXPECT_EQ(index, 7);
58 }
59}
60
61} // namespace blender::binary_search::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int64_t find_predicate_begin(Iterator begin, Iterator end, Predicate &&predicate)
__int64 int64_t
Definition stdint.h:89