Blender
V4.3
source
blender
blenlib
tests
BLI_unique_sorted_indices_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_array.hh
"
6
#include "
BLI_unique_sorted_indices.hh
"
7
8
#include "testing/testing.h"
9
10
namespace
blender::unique_sorted_indices::tests
{
11
12
TEST
(unique_sorted_indices, FindRangeEnd)
13
{
14
EXPECT_EQ
(
find_size_of_next_range<int>
({4}), 1);
15
EXPECT_EQ
(
find_size_of_next_range<int>
({4, 5, 6, 7}), 4);
16
EXPECT_EQ
(
find_size_of_next_range<int>
({4, 5, 6, 8, 9}), 3);
17
}
18
19
TEST
(unique_sorted_indices, NonEmptyIsRange)
20
{
21
EXPECT_TRUE(
non_empty_is_range<int>
({0, 1, 2}));
22
EXPECT_TRUE(
non_empty_is_range<int>
({5}));
23
EXPECT_TRUE(
non_empty_is_range<int>
({7, 8, 9, 10}));
24
EXPECT_FALSE(
non_empty_is_range<int>
({3, 5}));
25
EXPECT_FALSE(
non_empty_is_range<int>
({3, 4, 5, 6, 8, 9}));
26
}
27
28
TEST
(unique_sorted_indices, NonEmptyAsRange)
29
{
30
EXPECT_EQ
(
non_empty_as_range<int>
({0, 1, 2}),
IndexRange
(0, 3));
31
EXPECT_EQ
(
non_empty_as_range<int>
({5}),
IndexRange
(5, 1));
32
EXPECT_EQ
(
non_empty_as_range<int>
({10, 11}),
IndexRange
(10, 2));
33
}
34
35
TEST
(unique_sorted_indices, FindSizeOfNextRange)
36
{
37
EXPECT_EQ
(
find_size_of_next_range<int>
({0, 3, 4}), 1);
38
EXPECT_EQ
(
find_size_of_next_range<int>
({4, 5, 6, 7}), 4);
39
EXPECT_EQ
(
find_size_of_next_range<int>
({4}), 1);
40
EXPECT_EQ
(
find_size_of_next_range<int>
({5, 6, 7, 10, 11, 100}), 3);
41
}
42
43
TEST
(unique_sorted_indices, FindStartOfNextRange)
44
{
45
EXPECT_EQ
(
find_size_until_next_range<int>
({4}, 3), 1);
46
EXPECT_EQ
(
find_size_until_next_range<int>
({4, 5}, 3), 2);
47
EXPECT_EQ
(
find_size_until_next_range<int>
({4, 5, 6}, 3), 0);
48
EXPECT_EQ
(
find_size_until_next_range<int>
({4, 5, 6, 7}, 3), 0);
49
EXPECT_EQ
(
find_size_until_next_range<int>
({0, 1, 3, 5, 10, 11, 12, 20}, 3), 4);
50
}
51
52
TEST
(unique_sorted_indices, SplitToRangesAndSpans)
53
{
54
Array<int>
data = {1, 2, 3, 4, 7, 9, 10, 13, 14, 15, 20, 21, 22, 23, 24};
55
Vector<std::variant<IndexRange, Span<int>
>> parts;
56
const
int64_t
parts_num =
split_to_ranges_and_spans<int>
(data, 3, parts);
57
58
EXPECT_EQ
(parts_num, 4);
59
EXPECT_EQ
(parts.size(), 4);
60
EXPECT_EQ
(std::get<IndexRange>(parts[0]),
IndexRange
(1, 4));
61
EXPECT_EQ
(std::get<
Span<int>
>(parts[1]),
Span<int>
({7, 9, 10}));
62
EXPECT_EQ
(std::get<IndexRange>(parts[2]),
IndexRange
(13, 3));
63
EXPECT_EQ
(std::get<IndexRange>(parts[3]),
IndexRange
(20, 5));
64
}
65
66
}
// namespace blender::unique_sorted_indices::tests
BLI_array.hh
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_unique_sorted_indices.hh
blender::Array
Definition
BLI_array.hh:50
blender::IndexRange
Definition
BLI_index_range.hh:50
blender::Span
Definition
BLI_span.hh:75
blender::Vector
Definition
BLI_vector.hh:65
blender::unique_sorted_indices::tests
Definition
BLI_unique_sorted_indices_test.cc:10
blender::unique_sorted_indices::tests::TEST
TEST(unique_sorted_indices, FindRangeEnd)
Definition
BLI_unique_sorted_indices_test.cc:12
blender::unique_sorted_indices::find_size_of_next_range
int64_t find_size_of_next_range(const Span< T > indices)
Definition
BLI_unique_sorted_indices.hh:71
blender::unique_sorted_indices::find_size_until_next_range
int64_t find_size_until_next_range(const Span< T > indices, const int64_t min_range_size)
Definition
BLI_unique_sorted_indices.hh:90
blender::unique_sorted_indices::split_to_ranges_and_spans
int64_t split_to_ranges_and_spans(const Span< T > indices, const int64_t range_threshold, Vector< std::variant< IndexRange, Span< T > >, InlineBufferSize > &r_segments)
Definition
BLI_unique_sorted_indices.hh:118
blender::unique_sorted_indices::non_empty_is_range
bool non_empty_is_range(const Span< T > indices)
Definition
BLI_unique_sorted_indices.hh:37
blender::unique_sorted_indices::non_empty_as_range
IndexRange non_empty_as_range(const Span< T > indices)
Definition
BLI_unique_sorted_indices.hh:46
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