48#include <gtest/gtest.h>
60using namespace testing;
88 for (
size_t i = 0; i <
SMALL_N; ++i)
89 for (
size_t j = 0; j <
SMALL_M; ++j)
102 for (
size_t i = 0; i < 4; ++i)
221 for (
size_t i = 0; i <
SMALL_N; ++i)
222 for (
size_t j = 0; j <
SMALL_M; ++j)
226 mat.write(0, 0, 999);
289 other.write(0, 0, 100);
327 dest = std::move(mat);
347 mat1.write(0, 0, 10);
348 mat2.write(0, 0, 20);
439 int&
ref = mat.write(1, 1, 10);
469 string value =
"hello";
471 mat.
write(0, 0, std::move(value));
518 for (
size_t i = 0; i <
SMALL_N; ++i)
519 for (
size_t j = 0; j <
SMALL_M; ++j)
526 mat.
write(1, 1, 100);
550 for (
size_t i = 0; i <
SMALL_N; ++i)
551 for (
size_t j = 0; j <
SMALL_M; ++j)
559 for (
size_t i = 0; i < 4; ++i)
582 mat.set_dimension(5, 5);
592 mat.set_default_initial_value(99);
593 mat.set_dimension(2, 2);
604 mat.set_default_initial_value(42);
677 auto it = mat.get_it();
680 while (it.has_curr())
692 auto it = mat.get_it();
694 for (
size_t i = 0; i <
SMALL_N; ++i)
695 for (
size_t j = 0; j <
SMALL_M; ++j)
700 EXPECT_EQ(it.get_curr(), mat.read(i, j));
709 auto it = mat.get_it();
712 while (it.has_curr())
720 auto it = mat.get_it();
722 while (it.has_curr())
730 auto it = mat.get_it();
749 mat.traverse([&](
int val)
767 bool result = mat.traverse([&](
int)
783 mat.traverse([&](
int val)
801 mat.traverse_allocated([&](
int val)
822 mat.for_each([&
sum](
int val) {
sum += val; });
831 bool result = mat.all([](
int val) {
return val >= 0; });
838 bool result = mat.all([](
int val) {
return val < 5; });
844 bool result = mat.exists([](
int val) {
return val == 5; });
850 bool result = mat.exists([](
int val) {
return val == 999; });
856 int sum = mat.foldl(0, [](
int acc,
int val) {
return acc + val; });
870 static_assert(std::is_same_v<Matrix::Item_Type, int>);
871 static_assert(std::is_same_v<Matrix::Key_Type, int>);
872 static_assert(std::is_same_v<Matrix::Set_Type, Matrix>);
886 for (
size_t i = 0; i < 5; ++i)
887 for (
size_t j = 0; j < 5; ++j)
901 for (
size_t i = 0; i < 10; ++i)
902 for (
size_t j = 0; j < 10; ++j)
903 mat(i, j) =
static_cast<int>(i * 10 + j);
931 for (
size_t j = 0; j < 10; ++j)
932 mat.
write(0, j,
static_cast<int>(j));
944 for (
size_t i = 0; i < 10; ++i)
945 mat.
write(i, 0,
static_cast<int>(i));
956 mat.
write(999, 999, 2);
957 mat.
write(500, 500, 3);
974 for (
size_t i = 0; i <
LARGE_N; ++i)
975 mat.
write(i, i,
static_cast<int>(i));
978 for (
size_t i = 0; i <
LARGE_N; ++i)
990 for (
size_t i = 0; i <
LARGE_N; ++i)
991 original.write(i, i,
static_cast<int>(i));
997 for (
size_t i = 0; i <
LARGE_N; ++i)
1009 mat.
write(0, 0, 1.5);
1010 mat.
write(1, 1, 2.7);
1011 mat.
write(2, 2, 3.9);
1022 mat.
write(0, 0,
"hello");
1023 mat.
write(1, 1,
"world");
1060 ::testing::InitGoogleTest(&
argc,
argv);
Functional programming utilities for Aleph-w containers.
void empty() noexcept
empty the list
DynList & swap(DynList &l) noexcept
Swap this with l.
Dynamic matrix with sparse storage.
const T & read(const size_t i, const size_t j) const
Read the entry at position (i, j).
constexpr bool is_empty() const noexcept
Check if the matrix is empty (uninitialized).
constexpr size_t cols() const noexcept
Get the number of columns.
T & write(const size_t i, const size_t j, const T &data)
Write a value to position (i, j).
void allocate()
Pre-allocate memory for the entire matrix.
const T & get_default_value() const noexcept
Get the default value for unwritten entries.
constexpr size_t rows() const noexcept
Get the number of rows.
void set_default_initial_value(const T &value)
Set the default value for unwritten entries.
constexpr size_t size() const noexcept
Get the total number of entries.
constexpr bool is_square() const noexcept
Check if the matrix is square.
DynMatrix< T > transpose() const
Create a transposed copy of the matrix.
void fill(const T &value)
Fill all entries with a value.
constexpr bool is_empty() const noexcept
Return true if list is empty.
Sparse matrix with generic row and column domains.
TEST_F(FilledMatrix, copy_constructor_creates_independent_copy)
constexpr size_t MEDIUM_N
constexpr size_t MEDIUM_M
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Type that counts constructions/destructions.
Counted & operator=(Counted &&other) noexcept
Counted & operator=(const Counted &other)
Counted(Counted &&other) noexcept
bool operator==(const Counted &other) const
bool operator!=(const Counted &other) const
Counted(const Counted &other)
Fixture with a pre-filled matrix.
Fixture with a small integer matrix.
Fixture with a square matrix.
Dynamic matrix with lazy allocation.