diff options
author | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-04-03 17:49:11 +0200 |
---|---|---|
committer | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-05-20 09:49:01 +0200 |
commit | dacbcc7d7779e5faec243b51b1581d401954ddea (patch) | |
tree | 39552f8b3bb9bb000f804c777a7f3867788f29ce /test/matrix.cpp | |
parent | 6287ceff5aba1e8207aafdae9f967c70d9aad19f (diff) |
test: Add minimal test for Matrix
Add a few tests for the Matrix class. This is not full fledged but at
least a starter.
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'test/matrix.cpp')
-rw-r--r-- | test/matrix.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/matrix.cpp b/test/matrix.cpp new file mode 100644 index 00000000..4afae2da --- /dev/null +++ b/test/matrix.cpp @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024, Ideas on Board Oy + * + * Matrix tests + */ + +#include "libcamera/internal/matrix.h" + +#include <cmath> +#include <iostream> + +#include "test.h" + +using namespace libcamera; + +#define ASSERT_EQ(a, b) \ + if ((a) != (b)) { \ + std::cout << #a " != " #b << " (line " << __LINE__ << ")" \ + << std::endl; \ + return TestFail; \ + } + +class MatrixTest : public Test +{ +protected: + int run() + { + Matrix<double, 3, 3> m1; + + ASSERT_EQ(m1[0][0], 0.0); + ASSERT_EQ(m1[0][1], 0.0); + + constexpr Matrix<float, 2, 2> m2 = Matrix<float, 2, 2>().identity(); + ASSERT_EQ(m2[0][0], 1.0); + ASSERT_EQ(m2[0][1], 0.0); + ASSERT_EQ(m2[1][0], 0.0); + ASSERT_EQ(m2[1][1], 1.0); + + Matrix<float, 2, 2> m3{ { 2.0, 0.0, 0.0, 2.0 } }; + Matrix<float, 2, 2> m4 = m3.inverse(); + + Matrix<float, 2, 2> m5 = m3 * m4; + ASSERT_EQ(m5[0][0], 1.0); + ASSERT_EQ(m5[0][1], 0.0); + ASSERT_EQ(m5[1][0], 0.0); + ASSERT_EQ(m5[1][1], 1.0); + + return TestPass; + } +}; + +TEST_REGISTER(MatrixTest) |