From 41387160723843b7984c2e49afd19c4bbf720041 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 16 Dec 2008 22:02:12 -0500 Subject: Testing for Matrix class --- sigcore/test/TestMatrix.cpp | 301 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 sigcore/test/TestMatrix.cpp (limited to 'sigcore/test/TestMatrix.cpp') diff --git a/sigcore/test/TestMatrix.cpp b/sigcore/test/TestMatrix.cpp new file mode 100644 index 00000000..53cf57ea --- /dev/null +++ b/sigcore/test/TestMatrix.cpp @@ -0,0 +1,301 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "TestMatrix.h" + +// Qt includes +#include + +void TestMatrix::addRow() +{ + Sigcore::Matrix mat; + + QCOMPARE(mat.width(), 0); + QCOMPARE(mat.height(), 0); + + mat.addRow(); + + QCOMPARE(mat.width(), 1); + QCOMPARE(mat.height(), 1); + + mat.addRow(4); + + QCOMPARE(mat.height(), 2); + QCOMPARE(mat.width(), 1); + QCOMPARE(mat(1, 0), 4); +} + +void TestMatrix::addColumn() +{ + Sigcore::Matrix mat; + + QCOMPARE(mat.width(), 0); + QCOMPARE(mat.height(), 0); + + mat.addColumn(); + + QCOMPARE(mat.width(), 1); + QCOMPARE(mat.height(), 1); + + mat.addColumn(4); + + QCOMPARE(mat.height(), 1); + QCOMPARE(mat.width(), 2); + QCOMPARE(mat(0, 1), 4); +} + +void TestMatrix::insertRow() +{ + Sigcore::Matrix mat; + + mat.addRow(); + mat.addRow(4); + + mat.insertRow(1, 3); + + QCOMPARE(mat.height(), 3); + QCOMPARE(mat.width(), 1); + QCOMPARE(mat(1, 0), 3); +} + +void TestMatrix::insertColumn() +{ + Sigcore::Matrix mat; + + mat.addColumn(); + mat.addColumn(4); + + mat.insertColumn(1, 3); + + QCOMPARE(mat.height(), 1); + QCOMPARE(mat.width(), 3); + QCOMPARE(mat(0, 1), 3); +} + +void TestMatrix::deleteRow() +{ + Sigcore::Matrix mat; + + mat.addRow(); + mat.addRow(4); + mat.addRow(3); + + mat.deleteRow(1); + + QCOMPARE(mat.height(), 2); + QCOMPARE(mat.width(), 1); + QCOMPARE(mat(1, 0), 3); + + mat.deleteRow(0); + mat.deleteRow(0); + + QCOMPARE(mat.height(), 0); + QCOMPARE(mat.width(), 0); +} + +void TestMatrix::deleteColumn() +{ + Sigcore::Matrix mat; + + mat.addColumn(); + mat.addColumn(4); + mat.addColumn(3); + + mat.deleteColumn(1); + + QCOMPARE(mat.height(), 1); + QCOMPARE(mat.width(), 2); + QCOMPARE(mat(0, 1), 3); + + mat.deleteColumn(0); + mat.deleteColumn(0); + + QCOMPARE(mat.height(), 0); + QCOMPARE(mat.width(), 0); +} + +void TestMatrix::clear() +{ + Sigcore::Matrix mat(3, 3); + + mat.clear(); + + QCOMPARE(mat.height(), 0); + QCOMPARE(mat.width(), 0); +} + +void TestMatrix::resize() +{ + Sigcore::Matrix mat(3, 3); + + mat.resize(4, 4, 9); + + QCOMPARE(mat.height(), 4); + QCOMPARE(mat.width(), 4); + QCOMPARE(mat(3, 3), 9); + + mat.resize(2, 2, 9); + + QCOMPARE(mat.height(), 2); + QCOMPARE(mat.width(), 2); +} + +void TestMatrix::row() +{ + Sigcore::Matrix mat(3, 3); + + mat(0, 0) = 0; + mat(0, 1) = 1; + mat(0, 2) = 2; + + mat(1, 0) = 3; + mat(1, 1) = 4; + mat(1, 2) = 5; + + mat(2, 0) = 6; + mat(2, 1) = 7; + mat(2, 2) = 8; + + QVector row = mat.row(1); + + QCOMPARE(row[0], 3); + QCOMPARE(row[1], 4); + QCOMPARE(row[2], 5); +} + +void TestMatrix::column() +{ + Sigcore::Matrix mat(3, 3); + + mat(0, 0) = 0; + mat(0, 1) = 1; + mat(0, 2) = 2; + + mat(1, 0) = 3; + mat(1, 1) = 4; + mat(1, 2) = 5; + + mat(2, 0) = 6; + mat(2, 1) = 7; + mat(2, 2) = 8; + + QVector column = mat.column(1); + + QCOMPARE(column[0], 1); + QCOMPARE(column[1], 4); + QCOMPARE(column[2], 7); +} + +void TestMatrix::access() +{ + Sigcore::Matrix mat(3, 3); + + mat(0, 0) = 0; + mat(0, 1) = 1; + mat(0, 2) = 2; + + mat(1, 0) = 3; + mat(1, 1) = 4; + mat(1, 2) = 5; + + mat(2, 0) = 6; + mat(2, 1) = 7; + mat(2, 2) = 8; + + QCOMPARE(mat(0, 0), 0); + QCOMPARE(mat(0, 1), 1); + QCOMPARE(mat(0, 2), 2); + + QCOMPARE(mat(1, 0), 3); + QCOMPARE(mat(1, 1), 4); + QCOMPARE(mat(1, 2), 5); + + QCOMPARE(mat(2, 0), 6); + QCOMPARE(mat(2, 1), 7); + QCOMPARE(mat(2, 2), 8); +} + +void TestMatrix::assignment() +{ + Sigcore::Matrix mat1(3, 3); + Sigcore::Matrix mat2; + + mat1(0, 0) = 0; + mat1(0, 1) = 1; + mat1(0, 2) = 2; + + mat1(1, 0) = 3; + mat1(1, 1) = 4; + mat1(1, 2) = 5; + + mat1(2, 0) = 6; + mat1(2, 1) = 7; + mat1(2, 2) = 8; + + mat2 = mat1; + + QCOMPARE(mat2(0, 0), 0); + QCOMPARE(mat2(0, 1), 1); + QCOMPARE(mat2(0, 2), 2); + + QCOMPARE(mat2(1, 0), 3); + QCOMPARE(mat2(1, 1), 4); + QCOMPARE(mat2(1, 2), 5); + + QCOMPARE(mat2(2, 0), 6); + QCOMPARE(mat2(2, 1), 7); + QCOMPARE(mat2(2, 2), 8); +} + +void TestMatrix::equal() +{ + Sigcore::Matrix mat1(3, 3); + Sigcore::Matrix mat2; + + mat1(0, 0) = 0; + mat1(0, 1) = 1; + mat1(0, 2) = 2; + + mat1(1, 0) = 3; + mat1(1, 1) = 4; + mat1(1, 2) = 5; + + mat1(2, 0) = 6; + mat1(2, 1) = 7; + mat1(2, 2) = 8; + + QVERIFY(mat1 != mat2); + + mat2 = mat1; + + QCOMPARE(mat2(0, 0), 0); + QCOMPARE(mat2(0, 1), 1); + QCOMPARE(mat2(0, 2), 2); + + QCOMPARE(mat2(1, 0), 3); + QCOMPARE(mat2(1, 1), 4); + QCOMPARE(mat2(1, 2), 5); + + QCOMPARE(mat2(2, 0), 6); + QCOMPARE(mat2(2, 1), 7); + QCOMPARE(mat2(2, 2), 8); + + QVERIFY(mat1 == mat2); +} + +QTEST_APPLESS_MAIN(TestMatrix) -- cgit