2 #include "MainWindow.h" 4 #include <QtTest/QtTest> 5 #include "Test/TestMatrix.h" 14 void TestMatrix::cleanupTestCase ()
18 void TestMatrix::initTestCase ()
20 const QString NO_ERROR_REPORT_LOG_FILE;
21 const QString NO_REGRESSION_OPEN_FILE;
22 const bool NO_GNUPLOT_LOG_FILES =
false;
23 const bool NO_REGRESSION_IMPORT =
false;
24 const bool NO_RESET =
false;
25 const bool DEBUG_FLAG =
false;
26 const QStringList NO_LOAD_STARTUP_FILES;
28 initializeLogging (
"engauge_test",
33 NO_REGRESSION_OPEN_FILE,
37 NO_LOAD_STARTUP_FILES);
41 void TestMatrix::testDeterminant ()
44 double a00 = 1, a01 = 2, a10 = 3, a11 = 4;
50 QVERIFY ((m.
determinant () == a00 * a11 - a01 * a10));
53 void TestMatrix::testInverse ()
62 for (row = 0; row < 3; row++) {
63 for (col = 0; col < 3; col++) {
64 before.
set (row, col, ++counter);
67 before.
set (2, 2, 10);
71 Matrix product = before * after;
73 for (row = 0; row < 3; row++) {
74 for (col = 0; col < 3; col++) {
75 if (qAbs (product.
get (row, col) - identity.
get (row, col)) > 0.00001) {
85 void TestMatrix::testInverse2 ()
99 Matrix product = before * after;
101 for (row = 0; row < 2; row++) {
102 for (col = 0; col < 2; col++) {
103 if (qAbs (product.
get (row, col) - identity.
get (row, col)) > 0.00001) {
113 void TestMatrix::testMultiplyNonSquareMatrix ()
121 for (row = 0; row < 2; row++) {
122 for (col = 0; col < 3; col++) {
123 before.
set (row, col, ++counter);
131 if (afterGot.
rows () == afterWanted.
rows () &&
132 afterGot.
cols () == afterWanted.
cols ()) {
134 afterWanted.
set (0, 0, 1 * 1 + 2 * 2 + 3 * 3);
135 afterWanted.
set (0, 1, 1 * 4 + 2 * 5 + 3 * 6);
136 afterWanted.
set (1, 0, 4 * 1 + 5 * 2 + 6 * 3);
137 afterWanted.
set (1, 1, 4 * 4 + 5 * 5 + 6 * 6);
139 for (row = 0; row < 2; row++) {
140 for (col = 0; col < 2; col++) {
141 if (qAbs (afterWanted.
get (row, col) - afterGot.
get (row, col)) > 0.0001) {
154 void TestMatrix::testMultiplyNonSquareMatrixAndVector ()
161 QVector<double> vec (3);
163 for (row = 0; row < 2; row++) {
164 for (col = 0; col < 3; col++) {
165 before.
set (row, col, ++counter);
171 QVector<double> afterGot = before * vec;
172 QVector<double> afterWanted (2);
174 if (afterGot.size () == afterWanted.size ()) {
176 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
177 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
179 for (row = 0; row < 2; row++) {
180 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
192 void TestMatrix::testMultiplySquareMatrix ()
200 for (row = 0; row < 3; row++) {
201 for (col = 0; col < 3; col++) {
202 before.
set (row, col, ++counter);
207 Matrix afterGot = before * before;
210 if (afterGot.
rows() == afterWanted.
rows() &&
211 afterGot.
cols() == afterWanted.
cols()) {
213 afterWanted.
set (0, 0, 1 * 1 + 2 * 4 + 3 * 7);
214 afterWanted.
set (0, 1, 1 * 2 + 2 * 5 + 3 * 8);
215 afterWanted.
set (0, 2, 1 * 3 + 2 * 6 + 3 * 9);
216 afterWanted.
set (1, 0, 4 * 1 + 5 * 4 + 6 * 7);
217 afterWanted.
set (1, 1, 4 * 2 + 5 * 5 + 6 * 8);
218 afterWanted.
set (1, 2, 4 * 3 + 5 * 6 + 6 * 9);
219 afterWanted.
set (2, 0, 7 * 1 + 8 * 4 + 9 * 7);
220 afterWanted.
set (2, 1, 7 * 2 + 8 * 5 + 9 * 8);
221 afterWanted.
set (2, 2, 7 * 3 + 8 * 6 + 9 * 9);
223 for (row = 0; row < 3; row++) {
224 for (col = 0; col < 3; col++) {
225 if (qAbs (afterWanted.
get (row, col) - afterGot.
get (row, col)) > 0.0001) {
238 void TestMatrix::testMultiplySquareMatrixAndVector ()
245 QVector<double> vec (3);
247 for (row = 0; row < 3; row++) {
248 for (col = 0; col < 3; col++) {
249 before.
set (row, col, ++counter);
255 QVector<double> afterGot = before * vec;
256 QVector<double> afterWanted (3);
258 if (afterGot.size() == afterWanted.size()) {
260 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
261 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
262 afterWanted [2] = 7 * 1 + 8 * 2 + 9 * 3;
264 for (row = 0; row < 3; row++) {
265 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
277 void TestMatrix::testTranspose ()
285 for (row = 0; row < 3; row++) {
286 for (col = 0; col < 3; col++) {
287 before.
set (row, col, ++counter);
292 for (row = 0; row < 3; row++) {
293 for (col = 0; col < 3; col++) {
294 if (before.
get (row, col) != after.
get (col, row)) {
Matrix inverse() const
Return the inverse of this matrix.
Matrix transpose() const
Return the transpose of the current matrix.
double determinant() const
Return the determinant of this matrix.
int cols() const
Width of matrix.
Matrix class that supports arbitrary NxN size.
int rows() const
Height of matrix.
double get(int row, int col) const
Return (row, col) element.
void set(int row, int col, double value)
Set (row, col) element.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...