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 bool NO_DROP_REGRESSION =
false;
23 const QString NO_ERROR_REPORT_LOG_FILE;
24 const QString NO_REGRESSION_OPEN_FILE;
25 const bool NO_GNUPLOT_LOG_FILES =
false;
26 const bool NO_REGRESSION_IMPORT =
false;
27 const bool NO_RESET =
false;
28 const bool NO_EXPORT_ONLY =
false;
29 const bool NO_EXTRACT_IMAGE_ONLY =
false;
30 const QString NO_EXTRACT_IMAGE_EXTENSION;
31 const bool DEBUG_FLAG =
false;
32 const QStringList NO_LOAD_STARTUP_FILES;
33 const QStringList NO_COMMAND_LINE;
35 initializeLogging (
"engauge_test",
40 NO_REGRESSION_OPEN_FILE,
46 NO_EXTRACT_IMAGE_ONLY,
47 NO_EXTRACT_IMAGE_EXTENSION,
48 NO_LOAD_STARTUP_FILES,
53 void TestMatrix::testDeterminant ()
56 double a00 = 1, a01 = 2, a10 = 3, a11 = 4;
62 QVERIFY ((m.determinant () == a00 * a11 - a01 * a10));
65 void TestMatrix::testInverse ()
74 for (row = 0; row < 3; row++) {
75 for (col = 0; col < 3; col++) {
76 before.set (row, col, ++counter);
79 before.set (2, 2, 10);
81 MatrixConsistent matrixConsistent;
85 if (matrixConsistent != MATRIX_CONSISTENT) {
88 Matrix product = before * after;
90 for (row = 0; row < 3; row++) {
91 for (col = 0; col < 3; col++) {
92 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
103 void TestMatrix::testInverse2 ()
110 before.set (0, 0, 2);
111 before.set (0, 1, 1);
112 before.set (1, 0, 1);
113 before.set (1, 1, 1);
115 MatrixConsistent matrixConsistent;
119 if (matrixConsistent != MATRIX_CONSISTENT) {
122 Matrix product = before * after;
124 for (row = 0; row < 2; row++) {
125 for (col = 0; col < 2; col++) {
126 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
137 void TestMatrix::testMultiplyNonSquareMatrix ()
145 for (row = 0; row < 2; row++) {
146 for (col = 0; col < 3; col++) {
147 before.set (row, col, ++counter);
155 if (afterGot.
rows () == afterWanted.rows () &&
156 afterGot.
cols () == afterWanted.cols ()) {
158 afterWanted.set (0, 0, 1 * 1 + 2 * 2 + 3 * 3);
159 afterWanted.set (0, 1, 1 * 4 + 2 * 5 + 3 * 6);
160 afterWanted.set (1, 0, 4 * 1 + 5 * 2 + 6 * 3);
161 afterWanted.set (1, 1, 4 * 4 + 5 * 5 + 6 * 6);
163 for (row = 0; row < 2; row++) {
164 for (col = 0; col < 2; col++) {
165 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
178 void TestMatrix::testMultiplyNonSquareMatrixAndVector ()
185 QVector<double> vec (3);
187 for (row = 0; row < 2; row++) {
188 for (col = 0; col < 3; col++) {
189 before.set (row, col, ++counter);
195 QVector<double> afterGot = before * vec;
196 QVector<double> afterWanted (2);
198 if (afterGot.size () == afterWanted.size ()) {
200 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
201 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
203 for (row = 0; row < 2; row++) {
204 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
216 void TestMatrix::testMultiplySquareMatrix ()
224 for (row = 0; row < 3; row++) {
225 for (col = 0; col < 3; col++) {
226 before.set (row, col, ++counter);
231 Matrix afterGot = before * before;
234 if (afterGot.
rows() == afterWanted.rows() &&
235 afterGot.
cols() == afterWanted.cols()) {
237 afterWanted.set (0, 0, 1 * 1 + 2 * 4 + 3 * 7);
238 afterWanted.set (0, 1, 1 * 2 + 2 * 5 + 3 * 8);
239 afterWanted.set (0, 2, 1 * 3 + 2 * 6 + 3 * 9);
240 afterWanted.set (1, 0, 4 * 1 + 5 * 4 + 6 * 7);
241 afterWanted.set (1, 1, 4 * 2 + 5 * 5 + 6 * 8);
242 afterWanted.set (1, 2, 4 * 3 + 5 * 6 + 6 * 9);
243 afterWanted.set (2, 0, 7 * 1 + 8 * 4 + 9 * 7);
244 afterWanted.set (2, 1, 7 * 2 + 8 * 5 + 9 * 8);
245 afterWanted.set (2, 2, 7 * 3 + 8 * 6 + 9 * 9);
247 for (row = 0; row < 3; row++) {
248 for (col = 0; col < 3; col++) {
249 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
262 void TestMatrix::testMultiplySquareMatrixAndVector ()
269 QVector<double> vec (3);
271 for (row = 0; row < 3; row++) {
272 for (col = 0; col < 3; col++) {
273 before.set (row, col, ++counter);
279 QVector<double> afterGot = before * vec;
280 QVector<double> afterWanted (3);
282 if (afterGot.size() == afterWanted.size()) {
284 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
285 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
286 afterWanted [2] = 7 * 1 + 8 * 2 + 9 * 3;
288 for (row = 0; row < 3; row++) {
289 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
301 void TestMatrix::testTranspose ()
309 for (row = 0; row < 3; row++) {
310 for (col = 0; col < 3; col++) {
311 before.set (row, col, ++counter);
316 for (row = 0; row < 3; row++) {
317 for (col = 0; col < 3; col++) {
318 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.