File indexing completed on 2023-03-17 11:11:28
0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003
0004 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatrix.h"
0005
0006 namespace {
0007 template <int I, int J, typename T>
0008 bool compare(const L1MuGMTMatrix<T>& iMatrix, std::array<T, I * J> const& iValues) {
0009 for (int i = 0; i < I; ++i) {
0010 for (int j = 0; j < J; ++j) {
0011 if (iMatrix(i, j) != iValues[j + i * J]) {
0012 return false;
0013 }
0014 }
0015 }
0016 return true;
0017 }
0018 }
0019
0020 TEST_CASE("Test L1MuGMTMatrix", "L1MuGMTMatrix") {
0021 SECTION("empty") {
0022 L1MuGMTMatrix<int> m(2, 3, 0);
0023 REQUIRE(compare<2, 3>(m, {{0, 0, 0, 0, 0, 0}}) == true);
0024 }
0025
0026 SECTION("set all to 1") {
0027 L1MuGMTMatrix<int> m(2, 3, 1);
0028 REQUIRE(compare<2, 3>(m, {{1, 1, 1, 1, 1, 1}}) == true);
0029 }
0030
0031 SECTION("set different values") {
0032 L1MuGMTMatrix<int> m(2, 3, 0);
0033 m.set(0, 0, 0);
0034 m.set(0, 1, 1);
0035 m.set(0, 2, 2);
0036
0037 m.set(1, 0, 3);
0038 m.set(1, 1, 4);
0039 m.set(1, 2, 5);
0040
0041 REQUIRE(compare<2, 3>(m, {{0, 1, 2, 3, 4, 5}}) == true);
0042
0043 REQUIRE(m.isMax(0, 0) == false);
0044 REQUIRE(m.isMax(0, 1) == false);
0045 REQUIRE(m.isMax(0, 2) == false);
0046 REQUIRE(m.isMax(1, 0) == false);
0047 REQUIRE(m.isMax(1, 1) == false);
0048 REQUIRE(m.isMax(1, 2) == true);
0049
0050 REQUIRE(m.isMin(0, 0) == true);
0051 REQUIRE(m.isMin(0, 1) == false);
0052 REQUIRE(m.isMin(0, 2) == false);
0053
0054 REQUIRE(m.isMin(1, 0) == false);
0055 REQUIRE(m.isMin(1, 1) == false);
0056 REQUIRE(m.isMin(1, 2) == false);
0057 }
0058
0059 SECTION("Copy and operator=") {
0060 L1MuGMTMatrix<int> m(2, 3, 0);
0061 m.set(0, 0, 0);
0062 m.set(0, 1, 1);
0063 m.set(0, 2, 2);
0064
0065 m.set(1, 0, 3);
0066 m.set(1, 1, 4);
0067 m.set(1, 2, 5);
0068
0069 L1MuGMTMatrix<int> cp(m);
0070
0071 REQUIRE(compare<2, 3>(cp, {{0, 1, 2, 3, 4, 5}}) == true);
0072
0073 L1MuGMTMatrix<int> opEq(2, 3, 0);
0074 opEq = m;
0075
0076 REQUIRE(compare<2, 3>(opEq, {{0, 1, 2, 3, 4, 5}}) == true);
0077 }
0078
0079 SECTION("Arithmetics") {
0080 L1MuGMTMatrix<int> m(2, 3, 0);
0081 m.set(0, 0, 0);
0082 m.set(0, 1, 1);
0083 m.set(0, 2, 2);
0084
0085 m.set(1, 0, 3);
0086 m.set(1, 1, 4);
0087 m.set(1, 2, 5);
0088
0089 SECTION("Scalar addition") { REQUIRE(compare<2, 3>(m += 1, {{1, 2, 3, 4, 5, 6}}) == true); }
0090
0091 SECTION("Scalar multiplication") { REQUIRE(compare<2, 3>(m *= 2, {{0, 2, 4, 6, 8, 10}}) == true); }
0092
0093 SECTION("Matrix addition") {
0094 L1MuGMTMatrix<int> cp(m);
0095 REQUIRE(compare<2, 3>(m += cp, {{0, 2, 4, 6, 8, 10}}) == true);
0096 }
0097 }
0098
0099 SECTION("Look for non 0") {
0100 L1MuGMTMatrix<int> m(2, 3, 0);
0101
0102 m.set(0, 0, 0);
0103 m.set(0, 1, 0);
0104 m.set(0, 2, 2);
0105
0106 m.set(1, 0, 0);
0107 m.set(1, 1, 0);
0108 m.set(1, 2, 0);
0109
0110 REQUIRE(m.colAny(0) == -1);
0111 REQUIRE(m.colAny(1) == -1);
0112 REQUIRE(m.colAny(2) == 0);
0113
0114 REQUIRE(m.rowAny(0) == 2);
0115 REQUIRE(m.rowAny(1) == -1);
0116 }
0117 }