MCPcopy Create free account
hub / github.com/SGL-UT/gnsstk / operatorTest

Method operatorTest

core/tests/Math/Matrix_Operators_T.cpp:45–140  ·  view source on GitHub ↗

Test the add/subtract and set operators */

Source from the content-addressed store, hash-verified

43
44/* Test the add/subtract and set operators */
45int Matrix_T::operatorTest(void)
46{
47 gnsstk::TestUtil testFramework("Matrix", "Operators", __FILE__, __LINE__);
48 std::string failMesg;
49 int badCount = 0;
50
51 gnsstk::Vector<int> v1 = gnsstk::Vector<int>(16);
52 for (int i = 0; i < 16; i++)
53 v1[i] = i + 1;
54 gnsstk::Vector<int> v2 = gnsstk::Vector<int>(16);
55 for (int i = 0; i < 16; i++)
56 v2[i] = 16 - i;
57 gnsstk::Vector<int> v3 = gnsstk::Vector<int>(4);
58 for (int i = 0; i < 4; i++)
59 v3[i] = i + 1;
60 gnsstk::Vector<int> v4 = gnsstk::Vector<int>(8);
61 for (int i = 0; i < 4; i++)
62 {
63 v4[i] = i + 1 + 4;
64 v4[i + 4] = i + 1 + 4;
65 }
66
67 gnsstk::Matrix<int> a(2, 2, 1);
68 gnsstk::Matrix<int> b(8, 2, 3);
69 gnsstk::Matrix<int> c(4, 2, 5);
70 gnsstk::Matrix<int> d(4, 4, 7);
71 gnsstk::Matrix<int> e(8, 2, v1);
72 gnsstk::Matrix<int> f(4, 4, v2);
73 gnsstk::Matrix<int> g(2, 2, v3);
74 gnsstk::Matrix<int> h(4, 2, v4);
75
76 //--------------Matrix_operatorTest_1 - Does 2x2 additon function as expected?
77 a += g; // 2x2 addition
78 for (int i = 0; i < a.rows(); i++)
79 for (int j = 0; j < a.cols(); j++)
80 if (v3(i * g.cols() + j) + 1 != a(i, j))
81 {
82 badCount++;
83 }
84 failDescriptionStream << "Check to see if addition between two 2x2 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
85 failDescriptionString = failDescriptionStream.str();
86 failDescriptionStream.str("");
87 testFramework.assert(badCount == 0, failDescriptionString, __LINE__);
88 badCount = 0; // Reset error counter;
89 a -= g; // 2x2 reset a
90
91 //--------------Matrix_operatorTest_2 - Does 8x2 subtraction work as expected?
92 b -= e; // 8x2 subtraction
93 for (int i = 0; i < b.rows(); i++)
94 for (int j = 0; j < b.cols(); j++)
95 //cout << b(i,j) << " " << 3-(1+i+j*8) << endl;
96 if (3 - v1(i * e.cols() + j) != b(i, j))
97 {
98 badCount++;
99 }
100 failDescriptionStream << "Check to see if subtraction between two 8x2 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
101 failDescriptionString = failDescriptionStream.str();
102 failDescriptionStream.str("");

Callers 2

mainFunction · 0.45
Vector_T.cppFile · 0.45

Calls 2

rowsMethod · 0.45
colsMethod · 0.45

Tested by

no test coverage detected