Blender V4.3
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"
7
8#include "testing/testing.h"
9
11
12TEST(unique_sorted_indices, FindRangeEnd)
13{
16 EXPECT_EQ(find_size_of_next_range<int>({4, 5, 6, 8, 9}), 3);
17}
18
19TEST(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
28TEST(unique_sorted_indices, NonEmptyAsRange)
29{
33}
34
35TEST(unique_sorted_indices, FindSizeOfNextRange)
36{
40 EXPECT_EQ(find_size_of_next_range<int>({5, 6, 7, 10, 11, 100}), 3);
41}
42
43TEST(unique_sorted_indices, FindStartOfNextRange)
44{
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
52TEST(unique_sorted_indices, SplitToRangesAndSpans)
53{
54 Array<int> data = {1, 2, 3, 4, 7, 9, 10, 13, 14, 15, 20, 21, 22, 23, 24};
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
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int64_t find_size_of_next_range(const Span< T > indices)
int64_t find_size_until_next_range(const Span< T > indices, const int64_t min_range_size)
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)
bool non_empty_is_range(const Span< T > indices)
IndexRange non_empty_as_range(const Span< T > indices)
__int64 int64_t
Definition stdint.h:89