##// END OF EJS Templates
Tests get data by index method
Alexandre Leroux -
r474:6d79c86d7f69
parent child
Show More
@@ -5,7 +5,36
5 class TestOneDimArrayData : public QObject {
5 class TestOneDimArrayData : public QObject {
6 Q_OBJECT
6 Q_OBJECT
7 private slots:
7 private slots:
8 /// Tests @sa ArrayData::data(int componentIndex)
9 void testDataByComponentIndex_data();
10 void testDataByComponentIndex();
11
8 };
12 };
9
13
14 void TestOneDimArrayData::testDataByComponentIndex_data()
15 {
16 // Test structure
17 QTest::addColumn<QVector<double> >("inputData"); // array data's input
18 QTest::addColumn<int>("componentIndex"); // component index to test
19 QTest::addColumn<QVector<double> >("expectedData"); // expected data
20
21 // Test cases
22 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
23 << QVector<double>{1., 2., 3., 4., 5.};
24 QTest::newRow("invalidIndex1")
25 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
26 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
27 }
28
29 void TestOneDimArrayData::testDataByComponentIndex()
30 {
31 QFETCH(QVector<double>, inputData);
32 QFETCH(int, componentIndex);
33 QFETCH(QVector<double>, expectedData);
34
35 ArrayData<1> arrayData{inputData};
36 QVERIFY(arrayData.data(componentIndex) == expectedData);
37 }
38
10 QTEST_MAIN(TestOneDimArrayData)
39 QTEST_MAIN(TestOneDimArrayData)
11 #include "TestOneDimArrayData.moc"
40 #include "TestOneDimArrayData.moc"
@@ -7,7 +7,39 using DataContainer = QVector<QVector<double> >;
7 class TestTwoDimArrayData : public QObject {
7 class TestTwoDimArrayData : public QObject {
8 Q_OBJECT
8 Q_OBJECT
9 private slots:
9 private slots:
10 /// Tests @sa ArrayData::data(int componentIndex)
11 void testDataByComponentIndex_data();
12 void testDataByComponentIndex();
13
10 };
14 };
11
15
16 void TestTwoDimArrayData::testDataByComponentIndex_data()
17 {
18 // Test structure
19 QTest::addColumn<DataContainer>("inputData"); // array data's input
20 QTest::addColumn<int>("componentIndex"); // component index to test
21 QTest::addColumn<QVector<double> >("expectedData"); // expected data
22
23 // Test cases
24 auto inputData
25 = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
26
27 QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.};
28 QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.};
29 QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.};
30 QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{};
31 QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{};
32 }
33
34 void TestTwoDimArrayData::testDataByComponentIndex()
35 {
36 QFETCH(DataContainer, inputData);
37 QFETCH(int, componentIndex);
38 QFETCH(QVector<double>, expectedData);
39
40 ArrayData<2> arrayData{inputData};
41 QVERIFY(arrayData.data(componentIndex) == expectedData);
42 }
43
12 QTEST_MAIN(TestTwoDimArrayData)
44 QTEST_MAIN(TestTwoDimArrayData)
13 #include "TestTwoDimArrayData.moc"
45 #include "TestTwoDimArrayData.moc"
General Comments 0
You need to be logged in to leave comments. Login now