Skip to content
Snippets Groups Projects
Commit 5e88292f authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add tests for DiscreteFunctionP0::fill

parent 3821b5b9
No related branches found
No related tags found
1 merge request!89Add missing compatibility check when affecting lists to R^d or R^dxd
......@@ -135,6 +135,82 @@ TEST_CASE("DiscreteFunctionP0", "[scheme]")
}
}
SECTION("fill")
{
auto all_values_equal = [](const auto& f, const auto& g) {
size_t number_of_cells = f.cellValues().numberOfItems();
for (CellId cell_id = 0; cell_id < number_of_cells; ++cell_id) {
if (f[cell_id] != g) {
return false;
}
}
return true;
};
SECTION("1D")
{
std::shared_ptr mesh = MeshDataBaseForTests::get().cartesianMesh1D();
constexpr size_t Dimension = 1;
DiscreteFunctionP0<Dimension, double> f{mesh};
f.fill(3);
REQUIRE(all_values_equal(f, 3));
DiscreteFunctionP0<Dimension, TinyVector<3>> v{mesh};
v.fill(TinyVector<3>{1, 2, 3});
REQUIRE(all_values_equal(v, TinyVector<3>{1, 2, 3}));
DiscreteFunctionP0<Dimension, TinyMatrix<3>> A{mesh};
A.fill(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9});
REQUIRE(all_values_equal(A, TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
SECTION("2D")
{
std::shared_ptr mesh = MeshDataBaseForTests::get().cartesianMesh2D();
constexpr size_t Dimension = 2;
DiscreteFunctionP0<Dimension, double> f{mesh};
f.fill(3);
REQUIRE(all_values_equal(f, 3));
DiscreteFunctionP0<Dimension, TinyVector<3>> v{mesh};
v.fill(TinyVector<3>{1, 2, 3});
REQUIRE(all_values_equal(v, TinyVector<3>{1, 2, 3}));
DiscreteFunctionP0<Dimension, TinyMatrix<3>> A{mesh};
A.fill(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9});
REQUIRE(all_values_equal(A, TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
SECTION("3D")
{
std::shared_ptr mesh = MeshDataBaseForTests::get().cartesianMesh3D();
constexpr size_t Dimension = 3;
DiscreteFunctionP0<Dimension, double> f{mesh};
f.fill(3);
REQUIRE(all_values_equal(f, 3));
DiscreteFunctionP0<Dimension, TinyVector<3>> v{mesh};
v.fill(TinyVector<3>{1, 2, 3});
REQUIRE(all_values_equal(v, TinyVector<3>{1, 2, 3}));
DiscreteFunctionP0<Dimension, TinyMatrix<3>> A{mesh};
A.fill(TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9});
REQUIRE(all_values_equal(A, TinyMatrix<3>{1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
}
SECTION("binary operators")
{
SECTION("1D")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment