Files
test2/source/blender/blenlib/tests/BLI_offset_indices_test.cc
Hans Goudey 13f179a9c0 Cleanup: Add utility function to sum offset indices group sizes
I've done this a few times and would have benefited from a utility
function for it, apparently it's done in a few more places too. The
utilities aren't multithreaded for now, it doesn't seem important
and often multithreading happens at a different level of the call
stack anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/127517
2024-09-12 20:28:35 +02:00

28 lines
834 B
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "BLI_index_mask.hh"
#include "BLI_offset_indices.hh"
#include "BLI_vector.hh"
#include "BLI_strict_flags.h" /* Keep last. */
namespace blender::offset_indices::tests {
TEST(offset_indices, SumSizes)
{
Vector<int> data = {3, 2, 1, 5, -1};
const OffsetIndices<int> offsets = accumulate_counts_to_offsets(data);
EXPECT_EQ(sum_group_sizes(offsets, {0, 1, 2, 3}), 11);
EXPECT_EQ(sum_group_sizes(offsets, {3, 2, 1, 0}), 11);
EXPECT_EQ(sum_group_sizes(offsets, {3, 0}), 8);
EXPECT_EQ(sum_group_sizes(offsets, IndexRange(4)), 11);
EXPECT_EQ(sum_group_sizes(offsets, IndexMask(4)), 11);
EXPECT_EQ(sum_group_sizes(offsets, IndexMask(1)), 3);
}
} // namespace blender::offset_indices::tests