diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-16 22:02:12 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-16 22:02:12 -0500 |
| commit | 41387160723843b7984c2e49afd19c4bbf720041 (patch) | |
| tree | 514e7b86bab7c10a11d4b2d432ad53bde79f4394 | |
| parent | fb4d19e42856f5d8a8fb95d6cbc3b2613697cf46 (diff) | |
Testing for Matrix class
| -rw-r--r-- | sigcore/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigcore/test/TestMatrix.cpp | 301 | ||||
| -rw-r--r-- | sigcore/test/TestMatrix.h | 49 |
3 files changed, 351 insertions, 1 deletions
diff --git a/sigcore/test/CMakeLists.txt b/sigcore/test/CMakeLists.txt index 53b13d3a..5cbf093e 100644 --- a/sigcore/test/CMakeLists.txt +++ b/sigcore/test/CMakeLists.txt @@ -4,5 +4,5 @@ SET(libraries MAKE_TEST(Fraction libraries) MAKE_TEST(Hat libraries) -# MAKE_TEST(Matrix libraries) +MAKE_TEST(Matrix libraries) # MAKE_TEST(Script libraries) 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 <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "TestMatrix.h" + +// Qt includes +#include <QtTest/QTest> + +void TestMatrix::addRow() +{ + Sigcore::Matrix<int> 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<int> 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<int> 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<int> 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<int> 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<int> 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<int> mat(3, 3); + + mat.clear(); + + QCOMPARE(mat.height(), 0); + QCOMPARE(mat.width(), 0); +} + +void TestMatrix::resize() +{ + Sigcore::Matrix<int> 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<int> 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<int> row = mat.row(1); + + QCOMPARE(row[0], 3); + QCOMPARE(row[1], 4); + QCOMPARE(row[2], 5); +} + +void TestMatrix::column() +{ + Sigcore::Matrix<int> 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<int> column = mat.column(1); + + QCOMPARE(column[0], 1); + QCOMPARE(column[1], 4); + QCOMPARE(column[2], 7); +} + +void TestMatrix::access() +{ + Sigcore::Matrix<int> 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<int> mat1(3, 3); + Sigcore::Matrix<int> 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<int> mat1(3, 3); + Sigcore::Matrix<int> 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) diff --git a/sigcore/test/TestMatrix.h b/sigcore/test/TestMatrix.h new file mode 100644 index 00000000..7d30d030 --- /dev/null +++ b/sigcore/test/TestMatrix.h @@ -0,0 +1,49 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef TESTMATRIX +#define TESTMATRIX + +// Sigcore includes +#include "../Matrix.h" + +class TestMatrix : public QObject +{ + Q_OBJECT + + private slots: + void addRow(); + void addColumn(); + void insertRow(); + void insertColumn(); + void deleteRow(); + void deleteColumn(); + + void clear(); + + void resize(); + + void row(); + void column(); + + void access(); + + void assignment(); + void equal(); +}; + +#endif |
