Switched to C++17 and added many new test cases
This commit is contained in:
@ -12,11 +12,7 @@ TARGET = tst_qfixedsizematrixtest
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
CONFIG += c++14
|
||||
win32-g++ {
|
||||
QMAKE_CXXFLAGS_CXX14 = -std=c++14
|
||||
QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
|
||||
}
|
||||
CONFIG += c++1z
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
|
@ -8,18 +8,18 @@ template<typename T, unsigned int width, unsigned int height>
|
||||
class FixedSizeMatrix
|
||||
{
|
||||
public:
|
||||
FixedSizeMatrix();
|
||||
explicit FixedSizeMatrix();
|
||||
FixedSizeMatrix(const std::array<std::array<T, width>, height>& data);
|
||||
FixedSizeMatrix(const FixedSizeMatrix<T, width, height> &other);
|
||||
|
||||
auto& operator=(const FixedSizeMatrix<T, width, height>& other);
|
||||
auto& operator=(const std::array<std::array<T, width>, height>& data);
|
||||
|
||||
auto operator==(const FixedSizeMatrix<T, width, height>& other) const;
|
||||
auto operator!=(const FixedSizeMatrix<T, width, height>& other) const;
|
||||
[[nodiscard]] auto operator==(const FixedSizeMatrix<T, width, height>& other) const;
|
||||
[[nodiscard]] auto operator!=(const FixedSizeMatrix<T, width, height>& other) const;
|
||||
|
||||
auto& operator()(unsigned int x, unsigned int y);
|
||||
const auto& operator()(unsigned int x, unsigned int y) const;
|
||||
[[nodiscard]] auto& operator()(unsigned int x, unsigned int y);
|
||||
[[nodiscard]] const auto& operator()(unsigned int x, unsigned int y) const;
|
||||
|
||||
void rotateLeft();
|
||||
void rotateRight();
|
||||
@ -27,11 +27,11 @@ public:
|
||||
void mirrorHorizontally();
|
||||
void mirrorVertically();
|
||||
|
||||
auto asRotatedLeft() const;
|
||||
auto asRotatedRight() const;
|
||||
auto asRotated180() const;
|
||||
auto asMirroredHorizontally() const;
|
||||
auto asMirroredVertically() const;
|
||||
[[nodiscard]] auto asRotatedLeft() const;
|
||||
[[nodiscard]] auto asRotatedRight() const;
|
||||
[[nodiscard]] auto asRotated180() const;
|
||||
[[nodiscard]] auto asMirroredHorizontally() const;
|
||||
[[nodiscard]] auto asMirroredVertically() const;
|
||||
|
||||
private:
|
||||
std::array<std::array<T, width>, height> m_data;
|
||||
|
@ -14,11 +14,20 @@ public:
|
||||
|
||||
private Q_SLOTS:
|
||||
void constructorTest();
|
||||
void assignmentTest();
|
||||
void comparisonTest();
|
||||
void copyConstructorTest();
|
||||
void assignmentOperatorTest();
|
||||
void equalsOperatorTest();
|
||||
void notEqualsOperatorTest();
|
||||
void rotateLeftTest();
|
||||
void rotateRightTest();
|
||||
void rotate180Test();
|
||||
void mirrorHorizontallyTest();
|
||||
void mirrorVerticallyTest();
|
||||
void asRotatedLeftTest();
|
||||
void asRotatedRightTest();
|
||||
void asRotated180Test();
|
||||
void asMirroredHorizontally();
|
||||
void asMirroredVertically();
|
||||
|
||||
private:
|
||||
static const std::array<std::array<TestEnum, 2>, 4> demoData2x4;
|
||||
@ -99,21 +108,40 @@ void QFixedSizeMatrixTest::verifyData(const FixedSizeMatrix<QFixedSizeMatrixTest
|
||||
|
||||
void QFixedSizeMatrixTest::constructorTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::assignmentTest()
|
||||
void QFixedSizeMatrixTest::copyConstructorTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 2, 4> otherMatrix { matrix };
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::assignmentOperatorTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 2, 4> other;
|
||||
other = matrix;
|
||||
verifyData(other, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::comparisonTest()
|
||||
void QFixedSizeMatrixTest::equalsOperatorTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix0(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix0 { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix1;
|
||||
|
||||
QVERIFY2(!(matrix0 == matrix1), "");
|
||||
|
||||
matrix1 = FixedSizeMatrix<TestEnum, 2, 4> { demoData2x4 };
|
||||
|
||||
QVERIFY2(matrix0 == matrix1, "");
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::notEqualsOperatorTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix0 { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix1;
|
||||
|
||||
QVERIFY2(matrix0 != matrix1, "");
|
||||
@ -125,25 +153,80 @@ void QFixedSizeMatrixTest::comparisonTest()
|
||||
|
||||
void QFixedSizeMatrixTest::rotateLeftTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 4, 2> rotatedContainer;
|
||||
FixedSizeMatrix<TestEnum, 4, 4> matrix { demoData4x4 };
|
||||
|
||||
rotatedContainer = matrix.asRotatedLeft();
|
||||
verifyData(rotatedContainer, demoData2x4RotatedLeft);
|
||||
matrix.rotateLeft();
|
||||
verifyData(matrix, demoData4x4RotatedLeft);
|
||||
|
||||
matrix = rotatedContainer.asRotatedLeft();
|
||||
verifyData(matrix, demoData2x4Rotated180);
|
||||
matrix.rotateLeft();
|
||||
verifyData(matrix, demoData4x4Rotated180);
|
||||
|
||||
rotatedContainer = matrix.asRotatedLeft();
|
||||
verifyData(rotatedContainer, demoData2x4RotatedRight);
|
||||
matrix.rotateLeft();
|
||||
verifyData(matrix, demoData4x4RotatedRight);
|
||||
|
||||
matrix = rotatedContainer.asRotatedLeft();
|
||||
verifyData(matrix, demoData2x4);
|
||||
matrix.rotateLeft();
|
||||
verifyData(matrix, demoData4x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::rotateRightTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 4, 4> matrix { demoData4x4 };
|
||||
|
||||
matrix.rotateRight();
|
||||
verifyData(matrix, demoData4x4RotatedRight);
|
||||
|
||||
matrix.rotateRight();
|
||||
verifyData(matrix, demoData4x4Rotated180);
|
||||
|
||||
matrix.rotateRight();
|
||||
verifyData(matrix, demoData4x4RotatedLeft);
|
||||
|
||||
matrix.rotateRight();
|
||||
verifyData(matrix, demoData4x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::rotate180Test()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
|
||||
matrix.rotate180();
|
||||
verifyData(matrix, demoData2x4Rotated180);
|
||||
|
||||
matrix.rotate180();
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::mirrorHorizontallyTest()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::mirrorVerticallyTest()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::asRotatedLeftTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 4, 2> rotatedContainer;
|
||||
|
||||
rotatedContainer = matrix.asRotatedLeft();
|
||||
verifyData(rotatedContainer, demoData2x4RotatedLeft);
|
||||
|
||||
matrix = rotatedContainer.asRotatedLeft();
|
||||
verifyData(matrix, demoData2x4Rotated180);
|
||||
|
||||
rotatedContainer = matrix.asRotatedLeft();
|
||||
verifyData(rotatedContainer, demoData2x4RotatedRight);
|
||||
|
||||
matrix = rotatedContainer.asRotatedLeft();
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::asRotatedRightTest()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
FixedSizeMatrix<TestEnum, 4, 2> rotatedContainer;
|
||||
|
||||
rotatedContainer = matrix.asRotatedRight();
|
||||
@ -159,9 +242,9 @@ void QFixedSizeMatrixTest::rotateRightTest()
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::rotate180Test()
|
||||
void QFixedSizeMatrixTest::asRotated180Test()
|
||||
{
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix(demoData2x4);
|
||||
FixedSizeMatrix<TestEnum, 2, 4> matrix { demoData2x4 };
|
||||
|
||||
matrix = matrix.asRotated180();
|
||||
verifyData(matrix, demoData2x4Rotated180);
|
||||
@ -170,6 +253,16 @@ void QFixedSizeMatrixTest::rotate180Test()
|
||||
verifyData(matrix, demoData2x4);
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::asMirroredHorizontally()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void QFixedSizeMatrixTest::asMirroredVertically()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(QFixedSizeMatrixTest)
|
||||
|
||||
#include "tst_qfixedsizematrixtest.moc"
|
||||
|
Reference in New Issue
Block a user