Blender
V4.3
source
blender
blenlib
tests
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
5
#include "
BLI_binary_search.hh
"
6
#include "
BLI_vector.hh
"
7
8
#include "testing/testing.h"
9
10
namespace
blender::binary_search::tests
{
11
12
TEST
(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
19
TEST
(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
32
TEST
(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
BLI_binary_search.hh
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_vector.hh
blender::Vector
Definition
BLI_vector.hh:65
blender::binary_search::tests
Definition
BLI_binary_search_test.cc:10
blender::binary_search::tests::TEST
TEST(binary_search, Empty)
Definition
BLI_binary_search_test.cc:12
blender::binary_search::find_predicate_begin
int64_t find_predicate_begin(Iterator begin, Iterator end, Predicate &&predicate)
Definition
BLI_binary_search.hh:23
int64_t
__int64 int64_t
Definition
stdint.h:89
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0