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 DEBUG_FLAG =
false;
29 const QStringList NO_LOAD_STARTUP_FILES;
31 initializeLogging (
"engauge_test",
36 NO_REGRESSION_OPEN_FILE,
41 NO_LOAD_STARTUP_FILES);
45 void TestMatrix::testDeterminant ()
48 double a00 = 1, a01 = 2, a10 = 3, a11 = 4;
54 QVERIFY ((m.determinant () == a00 * a11 - a01 * a10));
57 void TestMatrix::testInverse ()
66 for (row = 0; row < 3; row++) {
67 for (col = 0; col < 3; col++) {
68 before.set (row, col, ++counter);
71 before.set (2, 2, 10);
73 MatrixConsistent matrixConsistent;
77 if (matrixConsistent != MATRIX_CONSISTENT) {
80 Matrix product = before * after;
82 for (row = 0; row < 3; row++) {
83 for (col = 0; col < 3; col++) {
84 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
95 void TestMatrix::testInverse2 ()
102 before.set (0, 0, 2);
103 before.set (0, 1, 1);
104 before.set (1, 0, 1);
105 before.set (1, 1, 1);
107 MatrixConsistent matrixConsistent;
111 if (matrixConsistent != MATRIX_CONSISTENT) {
114 Matrix product = before * after;
116 for (row = 0; row < 2; row++) {
117 for (col = 0; col < 2; col++) {
118 if (qAbs (product.
get (row, col) - identity.get (row, col)) > 0.00001) {
129 void TestMatrix::testMultiplyNonSquareMatrix ()
137 for (row = 0; row < 2; row++) {
138 for (col = 0; col < 3; col++) {
139 before.set (row, col, ++counter);
147 if (afterGot.
rows () == afterWanted.rows () &&
148 afterGot.
cols () == afterWanted.cols ()) {
150 afterWanted.set (0, 0, 1 * 1 + 2 * 2 + 3 * 3);
151 afterWanted.set (0, 1, 1 * 4 + 2 * 5 + 3 * 6);
152 afterWanted.set (1, 0, 4 * 1 + 5 * 2 + 6 * 3);
153 afterWanted.set (1, 1, 4 * 4 + 5 * 5 + 6 * 6);
155 for (row = 0; row < 2; row++) {
156 for (col = 0; col < 2; col++) {
157 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
170 void TestMatrix::testMultiplyNonSquareMatrixAndVector ()
177 QVector<double> vec (3);
179 for (row = 0; row < 2; row++) {
180 for (col = 0; col < 3; col++) {
181 before.set (row, col, ++counter);
187 QVector<double> afterGot = before * vec;
188 QVector<double> afterWanted (2);
190 if (afterGot.size () == afterWanted.size ()) {
192 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
193 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
195 for (row = 0; row < 2; row++) {
196 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
208 void TestMatrix::testMultiplySquareMatrix ()
216 for (row = 0; row < 3; row++) {
217 for (col = 0; col < 3; col++) {
218 before.set (row, col, ++counter);
223 Matrix afterGot = before * before;
226 if (afterGot.
rows() == afterWanted.rows() &&
227 afterGot.
cols() == afterWanted.cols()) {
229 afterWanted.set (0, 0, 1 * 1 + 2 * 4 + 3 * 7);
230 afterWanted.set (0, 1, 1 * 2 + 2 * 5 + 3 * 8);
231 afterWanted.set (0, 2, 1 * 3 + 2 * 6 + 3 * 9);
232 afterWanted.set (1, 0, 4 * 1 + 5 * 4 + 6 * 7);
233 afterWanted.set (1, 1, 4 * 2 + 5 * 5 + 6 * 8);
234 afterWanted.set (1, 2, 4 * 3 + 5 * 6 + 6 * 9);
235 afterWanted.set (2, 0, 7 * 1 + 8 * 4 + 9 * 7);
236 afterWanted.set (2, 1, 7 * 2 + 8 * 5 + 9 * 8);
237 afterWanted.set (2, 2, 7 * 3 + 8 * 6 + 9 * 9);
239 for (row = 0; row < 3; row++) {
240 for (col = 0; col < 3; col++) {
241 if (qAbs (afterWanted.get (row, col) - afterGot.
get (row, col)) > 0.0001) {
254 void TestMatrix::testMultiplySquareMatrixAndVector ()
261 QVector<double> vec (3);
263 for (row = 0; row < 3; row++) {
264 for (col = 0; col < 3; col++) {
265 before.set (row, col, ++counter);
271 QVector<double> afterGot = before * vec;
272 QVector<double> afterWanted (3);
274 if (afterGot.size() == afterWanted.size()) {
276 afterWanted [0] = 1 * 1 + 2 * 2 + 3 * 3;
277 afterWanted [1] = 4 * 1 + 5 * 2 + 6 * 3;
278 afterWanted [2] = 7 * 1 + 8 * 2 + 9 * 3;
280 for (row = 0; row < 3; row++) {
281 if (qAbs (afterWanted [row] - afterGot [row]) > 0.0001) {
293 void TestMatrix::testTranspose ()
301 for (row = 0; row < 3; row++) {
302 for (col = 0; col < 3; col++) {
303 before.set (row, col, ++counter);
308 for (row = 0; row < 3; row++) {
309 for (col = 0; col < 3; col++) {
310 if (before.get (row, col) != after.
get (col, row)) {
TestMatrix(QObject *parent=0)
Single constructor.
Matrix transpose() const
Return the transpose of the current matrix.
Matrix inverse(int significantDigits, MatrixConsistent &matrixConsistent) const
Return the inverse 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.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...