Fix some operations API mismatch

* Compound operators were not usable properly.
* std::size_t was used in the API in places where Index should have been used.
This commit is contained in:
Joel Falcou 2025-10-29 20:33:59 +01:00
parent f8cb289529
commit c7aa4a0afa
12 changed files with 152 additions and 120 deletions

View file

@ -5,10 +5,11 @@
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
#include <functional>
#include "unit/tests.hpp"
#include <array>
#include <functional>
template<typename MatrixType> struct MatrixDescriptor
{
@ -18,15 +19,15 @@ template<typename MatrixType> struct MatrixDescriptor
template<typename MatrixType, std::size_t N>
void test_matrix_sizes(
std::size_t rows,
std::size_t cols,
rotgen::Index rows,
rotgen::Index cols,
std::function<void(MatrixType&, std::size_t, std::size_t)> const& init_fn,
std::array<std::pair<int, int>, N> const& resize_dimensions)
{
MatrixType matrix(rows, cols);
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) init_fn(matrix, r, c);
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c) init_fn(matrix, r, c);
TTS_EQUAL(rotgen::size(matrix), rows * cols);
@ -37,24 +38,24 @@ void test_matrix_sizes(
rotgen::resize(matrix, r, c);
TTS_EQUAL(rotgen::rows(matrix), static_cast<size_t>(r));
TTS_EQUAL(rotgen::cols(matrix), static_cast<size_t>(c));
TTS_EQUAL(rotgen::size(matrix), static_cast<size_t>(r * c));
TTS_EQUAL(rotgen::rows(matrix), r);
TTS_EQUAL(rotgen::cols(matrix), c);
TTS_EQUAL(rotgen::size(matrix), r * c);
}
rotgen::conservativeResize(matrix, rows, cols);
TTS_EQUAL(rotgen::size(matrix), rows * cols);
int i = 1;
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) matrix(r, c) = i++;
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c) matrix(r, c) = i++;
rotgen::conservativeResize(matrix, rows + 3, cols + 2);
TTS_EQUAL(rotgen::size(matrix), (rows + 3) * (cols + 2));
i = 1;
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), i++);
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), i++);
}
TTS_CASE("Matrix size-related operations")