##// END OF EJS Templates
Fixes the refresh of data that was not working all the time
Fixes the refresh of data that was not working all the time

File last commit:

r695:17f44c407bff
r1270:c436df4b66de
Show More
TestOneDimArrayData.cpp
181 lines | 5.3 KiB | text/x-c | CppLexer
/ core / tests / Data / TestOneDimArrayData.cpp
Alexandre Leroux
Inits unit tests for 1-dim and 2-dim array data
r514 #include "Data/ArrayData.h"
#include <QObject>
#include <QtTest>
Alexandre Leroux
Updates unit tests
r647 namespace {
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 using DataContainer = std::vector<double>;
void verifyArrayData(const ArrayData<1> &arrayData, const DataContainer &expectedData)
Alexandre Leroux
Updates unit tests
r647 {
QVERIFY(std::equal(
arrayData.cbegin(), arrayData.cend(), expectedData.cbegin(), expectedData.cend(),
[](const auto &it, const auto &expectedData) { return it.at(0) == expectedData; }));
}
} // namespace
Alexandre Leroux
Inits unit tests for 1-dim and 2-dim array data
r514 class TestOneDimArrayData : public QObject {
Q_OBJECT
private slots:
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 /// Tests @sa ArrayData::data()
void testData_data();
void testData();
Alexandre Leroux
Tests add() method
r516 /// Tests @sa ArrayData::add()
void testAdd_data();
void testAdd();
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 /// Tests @sa ArrayData::at(int index)
void testAt_data();
void testAt();
Alexandre Leroux
Tests clear() and size() methods
r517 /// Tests @sa ArrayData::clear()
void testClear_data();
void testClear();
/// Tests @sa ArrayData::size()
void testSize_data();
void testSize();
Alexandre Leroux
Tests sort() method
r518 /// Tests @sa ArrayData::sort()
void testSort_data();
void testSort();
Alexandre Leroux
Inits unit tests for 1-dim and 2-dim array data
r514 };
Alexandre Leroux
Tests sort() method
r518 void TestOneDimArrayData::testData_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array's data input
QTest::addColumn<DataContainer>("expectedData"); // expected data
Alexandre Leroux
Tests sort() method
r518
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.}
<< DataContainer{1., 2., 3., 4., 5.};
Alexandre Leroux
Tests sort() method
r518 }
void TestOneDimArrayData::testData()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
QFETCH(DataContainer, expectedData);
Alexandre Leroux
Tests sort() method
r518
ArrayData<1> arrayData{inputData};
Alexandre Leroux
Updates unit tests
r647 verifyArrayData(arrayData, expectedData);
Alexandre Leroux
Tests get data by index method
r515 }
Alexandre Leroux
Tests add() method
r516 void TestOneDimArrayData::testAdd_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array's data input
QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with
QTest::addColumn<bool>("prepend"); // prepend or append merge
QTest::addColumn<DataContainer>("expectedData"); // expected data after merge
Alexandre Leroux
Tests add() method
r516
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("appendMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.}
<< false << DataContainer{1., 2., 3., 4., 5., 6., 7., 8.};
QTest::newRow("prependMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.}
<< true << DataContainer{6., 7., 8., 1., 2., 3., 4., 5.};
Alexandre Leroux
Tests add() method
r516 }
void TestOneDimArrayData::testAdd()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
QFETCH(DataContainer, otherData);
Alexandre Leroux
Tests add() method
r516 QFETCH(bool, prepend);
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedData);
Alexandre Leroux
Tests add() method
r516
ArrayData<1> arrayData{inputData};
ArrayData<1> other{otherData};
arrayData.add(other, prepend);
Alexandre Leroux
Updates unit tests
r647 verifyArrayData(arrayData, expectedData);
Alexandre Leroux
Tests add() method
r516 }
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 void TestOneDimArrayData::testAt_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array data's input
QTest::addColumn<int>("index"); // index to retrieve data
QTest::addColumn<double>("expectedData"); // expected data at index
Alexandre Leroux
Tests specific methods of 1-dim array data
r519
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 0 << 1.;
QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << 3 << 4.;
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 }
void TestOneDimArrayData::testAt()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 QFETCH(int, index);
QFETCH(double, expectedData);
ArrayData<1> arrayData{inputData};
QVERIFY(arrayData.at(index) == expectedData);
}
void TestOneDimArrayData::testClear_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array data's input
Alexandre Leroux
Tests specific methods of 1-dim array data
r519
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.};
Alexandre Leroux
Tests specific methods of 1-dim array data
r519 }
Alexandre Leroux
Tests clear() and size() methods
r517 void TestOneDimArrayData::testClear()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
Alexandre Leroux
Tests clear() and size() methods
r517
ArrayData<1> arrayData{inputData};
arrayData.clear();
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 verifyArrayData(arrayData, DataContainer{});
Alexandre Leroux
Tests clear() and size() methods
r517 }
void TestOneDimArrayData::testSize_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array data's input
QTest::addColumn<int>("expectedSize"); // expected array data size
Alexandre Leroux
Tests clear() and size() methods
r517
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 5;
Alexandre Leroux
Tests clear() and size() methods
r517 }
void TestOneDimArrayData::testSize()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
Alexandre Leroux
Tests clear() and size() methods
r517 QFETCH(int, expectedSize);
ArrayData<1> arrayData{inputData};
QVERIFY(arrayData.size() == expectedSize);
}
Alexandre Leroux
Tests sort() method
r518 void TestOneDimArrayData::testSort_data()
{
// Test structure
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("inputData"); // array data's input
Alexandre Leroux
Tests sort() method
r518 QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedData"); // expected data after sorting
Alexandre Leroux
Tests sort() method
r518
// Test cases
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << std::vector<int>{0, 2, 3, 1, 4}
<< DataContainer{1., 3., 4., 2., 5.};
QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << std::vector<int>{4, 1, 2, 3, 0}
<< DataContainer{5., 2., 3., 4., 1.};
Alexandre Leroux
Tests sort() method
r518 }
void TestOneDimArrayData::testSort()
{
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, inputData);
Alexandre Leroux
Tests sort() method
r518 QFETCH(std::vector<int>, sortPermutation);
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedData);
Alexandre Leroux
Tests sort() method
r518
ArrayData<1> arrayData{inputData};
auto sortedArrayData = arrayData.sort(sortPermutation);
Alexandre Leroux
Fix compilation on Linux
r524 QVERIFY(sortedArrayData != nullptr);
Alexandre Leroux
Updates unit tests
r647 verifyArrayData(*sortedArrayData, expectedData);
Alexandre Leroux
Tests sort() method
r518 }
Alexandre Leroux
Inits unit tests for 1-dim and 2-dim array data
r514 QTEST_MAIN(TestOneDimArrayData)
#include "TestOneDimArrayData.moc"