4#include <QtTest/QtTest>
16void TestMatrix::cleanupTestCase ()
20void TestMatrix::initTestCase ()
27 const bool NO_RESET =
false;
53void TestMatrix::testDeterminant ()
56 double a00 = 1, a01 = 2, a10 = 3, a11 = 4;
62 QVERIFY ((m.determinant () == a00 * a11 - a01 * a10));
65void 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);
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) {
103void 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);
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) {
137void TestMatrix::testMultiplyNonSquareMatrix ()
143 Matrix before (2, 3);
145 for (row = 0; row < 2; row++) {
146 for (col = 0; col < 3; col++) {
147 before.set (row, col, ++counter);
152 Matrix afterGot = before * before.transpose ();
153 Matrix afterWanted (2);
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) {
178void TestMatrix::testMultiplyNonSquareMatrixAndVector ()
184 Matrix before (2, 3);
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) {
216void 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;
232 Matrix afterWanted (3);
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) {
262void 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) {
301void TestMatrix::testTranspose ()
309 for (row = 0; row < 3; row++) {
310 for (col = 0; col < 3; col++) {
311 before.set (row, col, ++counter);
315 Matrix after = before.transpose ();
316 for (row = 0; row < 3; row++) {
317 for (col = 0; col < 3; col++) {
318 if (before.get (row, col) != after.
get (col, row)) {
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
MatrixConsistent
Indicates if matrix is consistent (i.e. has at least one solution)
const bool NO_EXPORT_ONLY
const QStringList NO_COMMAND_LINE
const QString NO_EXTRACT_IMAGE_EXTENSION
const QString NO_ERROR_REPORT_LOG_FILE
const bool NO_GNUPLOT_LOG_FILES
const QString NO_REGRESSION_OPEN_FILE
const QStringList NO_LOAD_STARTUP_FILES
const bool NO_REGRESSION_IMPORT
const bool NO_EXTRACT_IMAGE_ONLY
const bool NO_DROP_REGRESSION
const int SIGNIFICANT_DIGITS
int rows() const
Height of matrix.
double get(int row, int col) const
Return (row, col) element.
int cols() const
Width of matrix.
TestMatrix(QObject *parent=0)
Single constructor.