Skip to content

Commit

Permalink
[test] strongly typed test for expression template correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Jan 19, 2025
1 parent 9675667 commit e57ee9f
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions test/kalman_f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace {
assert(filter.f() == 1);

{
const auto f{2.};
const double f{2.};
filter.f(f);
assert(filter.f() == 2);
}

{
const auto f{3.};
const double f{3.};
filter.f(f);
assert(filter.f() == 3);
}
Expand Down
8 changes: 4 additions & 4 deletions test/kalman_f_5x4x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
//! @test Verifies the state transition matrix F management overloads for
//! the Eigen filter type.
[[maybe_unused]] auto test{[] {
const auto i5x5{identity<matrix<5, 5>>};
const auto z5x5{zero<matrix<5, 5>>};
const matrix<5, 5> i5x5{identity<matrix<5, 5>>};
const matrix<5, 5> z5x5{zero<matrix<5, 5>>};
kalman filter{state{vector<5>{0., 0., 0., 0., 0.}}, output<vector<4>>,
input<vector<3>>, update_types<double, float, int>,
prediction_types<int, float, double>};

assert(filter.f() == i5x5);

{
const auto f{z5x5};
const matrix<5, 5> f{z5x5};
filter.f(f);
assert(filter.f() == z5x5);
}

{
const auto f{i5x5};
const matrix<5, 5> f{i5x5};
filter.f(f);
assert(filter.f() == i5x5);
}
Expand Down
8 changes: 4 additions & 4 deletions test/kalman_h_5x4x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
//! @test Verifies the observation transition matrix H management overloads for
//! the Eigen filter type.
[[maybe_unused]] auto test{[] {
const auto i4x5{identity<matrix<4, 5>>};
const auto z4x5{zero<matrix<4, 5>>};
const matrix<4, 5> i4x5{identity<matrix<4, 5>>};
const matrix<4, 5> z4x5{zero<matrix<4, 5>>};
kalman filter{state{vector<5>{0., 0., 0., 0., 0.}}, output<vector<4>>,
input<vector<3>>, update_types<double, float, int>,
prediction_types<int, float, double>};

assert(filter.h() == i4x5);

{
const auto h{z4x5};
const matrix<4, 5> h{z4x5};
filter.h(h);
assert(filter.h() == z4x5);
}

{
const auto h{i4x5};
const matrix<4, 5> h{i4x5};
filter.h(h);
assert(filter.h() == i4x5);
}
Expand Down
4 changes: 2 additions & 2 deletions test/linalg_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the assignment operator.
[[maybe_unused]] auto test{[] {
auto m{identity<matrix<double, 5, 5>>};
auto c = m;
const matrix<double, 5, 5> m{identity<matrix<double, 5, 5>>};
const matrix<double, 5, 5> c = m;

assert((c == identity<matrix<double, 5, 5>>));

Expand Down
4 changes: 2 additions & 2 deletions test/linalg_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the copy constructor.
[[maybe_unused]] auto test{[] {
auto m{identity<matrix<double, 5, 5>>};
auto c{m};
const matrix<double, 5, 5> m{identity<matrix<double, 5, 5>>};
const matrix<double, 5, 5> c{m};

assert((c == identity<matrix<double, 5, 5>>));

Expand Down
2 changes: 1 addition & 1 deletion test/linalg_identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the identity matrices values are unit diagonals.
[[maybe_unused]] auto test{[] {
auto i{identity<matrix<double, 3, 3>>};
const matrix<double, 3, 3> i{identity<matrix<double, 3, 3>>};

assert(i(0, 0) == 1.0);
assert(i(0, 1) == 0.0);
Expand Down
6 changes: 3 additions & 3 deletions test/linalg_multiplication_sxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the assignment operator.
[[maybe_unused]] auto test{[] {
matrix<double, 2, 2> a{{1.0, 2.0}, {3.0, 4.0}};
matrix<double, 2, 1> b{3.0, 4.0};
auto r{a * b};
const matrix<double, 2, 2> a{{1.0, 2.0}, {3.0, 4.0}};
const matrix<double, 2, 1> b{3.0, 4.0};
const matrix<double, 2, 1> r{a * b};

assert(r(0, 0) == 11.0);
assert(r(1, 0) == 25.0);
Expand Down
6 changes: 3 additions & 3 deletions test/linalg_operator_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the equality operator.
[[maybe_unused]] auto test{[] {
auto m{zero<matrix<double, 5, 5>>};
auto i{identity<matrix<double, 5, 5>>};
auto z{zero<matrix<double, 5, 5>>};
const matrix<double, 5, 5> m{zero<matrix<double, 5, 5>>};
const matrix<double, 5, 5> i{identity<matrix<double, 5, 5>>};
const matrix<double, 5, 5> z{zero<matrix<double, 5, 5>>};

assert(m == z);
assert(m != i);
Expand Down
2 changes: 1 addition & 1 deletion test/linalg_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the zero matrices values are null.
[[maybe_unused]] auto test{[] {
auto z{zero<matrix<double, 3, 3>>};
const matrix<double, 3, 3> z{zero<matrix<double, 3, 3>>};

assert(z(0, 0) == 0.0);
assert(z(0, 1) == 0.0);
Expand Down

0 comments on commit e57ee9f

Please sign in to comment.