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