2 #include "MainWindow.h"
4 #include <QtTest/QtTest>
5 #include "Test/TestMatrix.h"
9 const
int SIGNIFICANT_DIGITS = 7;
16 void TestMatrix::cleanupTestCase ()
20 void TestMatrix::initTestCase ()
22 const QString NO_ERROR_REPORT_LOG_FILE;
23 const QString NO_REGRESSION_OPEN_FILE;
24 const bool NO_GNUPLOT_LOG_FILES =
false;
25 const bool NO_REGRESSION_IMPORT =
false;
26 const bool NO_RESET =
false;
27 const bool NO_EXPORT_ONLY =
false;
28 const bool NO_EXTRACT_IMAGE_ONLY =
false;
29 const QString NO_EXTRACT_IMAGE_EXTENSION;
30 const bool DEBUG_FLAG =
false;
31 const QStringList NO_LOAD_STARTUP_FILES;
32 const QStringList NO_COMMAND_LINE;
34 initializeLogging (
"engauge_test",
39 NO_REGRESSION_OPEN_FILE,
44 NO_EXTRACT_IMAGE_ONLY,
45 NO_EXTRACT_IMAGE_EXTENSION,
46 NO_LOAD_STARTUP_FILES,
51 void TestMatrix::testDeterminant ()
54 double a00 = 1, a01 = 2, a10 = 3, a11 = 4;
60 QVERIFY ((m.determinant () == a00 * a11 - a01 * a10));
63 void TestMatrix::testInverse ()
72 for (row = 0; row < 3; row++) {
73 for (col = 0; col < 3; col++) {
74 before.set (row, col, ++counter);
77 before.set (2, 2, 10);
79 MatrixConsistent matrixConsistent;
83 if (matrixConsistent != MATRIX_CONSISTENT) {
86 Matrix product = before * after;
88 for (row = 0; row < 3; row++) {
89 for (col = 0; col < 3; col++) {
90 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
101 void TestMatrix::testInverse2 ()
108 before.set (0, 0, 2);
109 before.set (0, 1, 1);
110 before.set (1, 0, 1);
111 before.set (1, 1, 1);
113 MatrixConsistent matrixConsistent;
117 if (matrixConsistent != MATRIX_CONSISTENT) {
120 Matrix product = before * after;
122 for (row = 0; row < 2; row++) {
123 for (col = 0; col < 2; col++) {
124 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
135 void TestMatrix::testMultiplyNonSquareMatrix ()
143 for (row = 0; row < 2; row++) {
144 for (col = 0; col < 3; col++) {
145 before.set (row, col, ++counter);
153 if (afterGot.
rows () == afterWanted.rows () &&
154 afterGot.
cols () == afterWanted.cols ()) {
156 afterWanted.set (0, 0, 1 * 1 + 2 * 2 + 3 * 3);
157 afterWanted.set (0, 1, 1 * 4 + 2 * 5 + 3 * 6);
158 afterWanted.set (1, 0, 4 * 1 + 5 * 2 + 6 * 3);
159 afterWanted.set (1, 1, 4 * 4 + 5 * 5 + 6 * 6);
161 for (row = 0; row < 2; row++) {
162 for (col = 0; col < 2; col++) {
163 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
176 void TestMatrix::testMultiplyNonSquareMatrixAndVector ()
183 QVector<double> vec (3);
185 for (row = 0; row < 2; row++) {
186 for (col = 0; col < 3; col++) {
187 before.set (row, col, ++counter);
193 QVector<double> afterGot = before * vec;
194 QVector<double> afterWanted (2);
196 if (afterGot.size () == afterWanted.size ()) {
198 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
199 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
201 for (row = 0; row < 2; row++) {
202 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
214 void TestMatrix::testMultiplySquareMatrix ()
222 for (row = 0; row < 3; row++) {
223 for (col = 0; col < 3; col++) {
224 before.set (row, col, ++counter);
229 Matrix afterGot = before * before;
232 if (afterGot.
rows() == afterWanted.rows() &&
233 afterGot.
cols() == afterWanted.cols()) {
235 afterWanted.set (0, 0, 1 * 1 + 2 * 4 + 3 * 7);
236 afterWanted.set (0, 1, 1 * 2 + 2 * 5 + 3 * 8);
237 afterWanted.set (0, 2, 1 * 3 + 2 * 6 + 3 * 9);
238 afterWanted.set (1, 0, 4 * 1 + 5 * 4 + 6 * 7);
239 afterWanted.set (1, 1, 4 * 2 + 5 * 5 + 6 * 8);
240 afterWanted.set (1, 2, 4 * 3 + 5 * 6 + 6 * 9);
241 afterWanted.set (2, 0, 7 * 1 + 8 * 4 + 9 * 7);
242 afterWanted.set (2, 1, 7 * 2 + 8 * 5 + 9 * 8);
243 afterWanted.set (2, 2, 7 * 3 + 8 * 6 + 9 * 9);
245 for (row = 0; row < 3; row++) {
246 for (col = 0; col < 3; col++) {
247 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
260 void TestMatrix::testMultiplySquareMatrixAndVector ()
267 QVector<double> vec (3);
269 for (row = 0; row < 3; row++) {
270 for (col = 0; col < 3; col++) {
271 before.set (row, col, ++counter);
277 QVector<double> afterGot = before * vec;
278 QVector<double> afterWanted (3);
280 if (afterGot.size() == afterWanted.size()) {
282 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
283 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
284 afterWanted [2] = 7 * 1 + 8 * 2 + 9 * 3;
286 for (row = 0; row < 3; row++) {
287 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
299 void TestMatrix::testTranspose ()
307 for (row = 0; row < 3; row++) {
308 for (col = 0; col < 3; col++) {
309 before.set (row, col, ++counter);
314 for (row = 0; row < 3; row++) {
315 for (col = 0; col < 3; col++) {
316 if (before.get (row, col) != after.
get (col, row)) {
int rows() const
Height of matrix.
Matrix inverse(int significantDigits, MatrixConsistent &matrixConsistent) const
Return the inverse of this matrix.
Matrix transpose() const
Return the transpose of the current matrix.
Matrix class that supports arbitrary NxN size.
int cols() const
Width of matrix.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
double get(int row, int col) const
Return (row, col) element.