##// END OF EJS Templates
Unit tests for fillDataHoles() method
Alexandre Leroux -
r1021:9d4ace4d73d0
parent child
Show More
@@ -0,0 +1,87
1 #include <Data/DataSeriesUtils.h>
2
3 #include <QObject>
4 #include <QtTest>
5
6 class TestDataSeriesUtils : public QObject {
7 Q_OBJECT
8
9 private slots:
10 /// Tests @sa DataSeriesUtils::fillDataHoles() method
11 void testFillDataHoles_data();
12 void testFillDataHoles();
13 };
14
15 void TestDataSeriesUtils::testFillDataHoles_data()
16 {
17 QTest::addColumn<std::vector<double> >("xAxisData");
18 QTest::addColumn<std::vector<double> >("valuesData");
19 QTest::addColumn<double>("resolution");
20 QTest::addColumn<double>("fillValue");
21 QTest::addColumn<std::vector<double> >(
22 "expectedXAxisData"); // expected x-axis data after filling holes
23 QTest::addColumn<std::vector<double> >(
24 "expectedValuesData"); // expected values data after filling holes
25
26 auto nan = std::numeric_limits<double>::quiet_NaN();
27
28 QTest::newRow("fillDataHoles (basic case)")
29 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2.
30 << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.}
31 << std::vector<double>{0., 1., nan, 2., 3., nan, nan, nan, 4.};
32
33 QTest::newRow("fillDataHoles (change nb components)")
34 << std::vector<double>{0., 1., 5., 7., 14.}
35 << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan
36 << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.}
37 << std::vector<double>{0., 1., 2., 3., nan, nan, 4., 5., 6.,
38 7., nan, nan, nan, nan, nan, nan, 8., 9.};
39
40 QTest::newRow("fillDataHoles (change resolution)")
41 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.}
42 << 1.5 << nan << std::vector<double>{0., 1., 2.5, 4., 5., 6.5, 7., 8.5, 10., 11.5, 13., 14.}
43 << std::vector<double>{0., 1., nan, nan, 2., nan, 3., nan, nan, nan, nan, 4.};
44
45 QTest::newRow("fillDataHoles (with no data (no changes made))")
46 << std::vector<double>{} << std::vector<double>{} << 2. << nan << std::vector<double>{}
47 << std::vector<double>{};
48
49 QTest::newRow("fillDataHoles (with no resolution (no changes made))")
50 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 0.
51 << nan << std::vector<double>{0., 1., 5., 7., 14.}
52 << std::vector<double>{0., 1., 2., 3., 4.};
53
54 QTest::newRow("fillDataHoles (change fill value)")
55 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2.
56 << -1. << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.}
57 << std::vector<double>{0., 1., -1., 2., 3., -1., -1., -1., 4.};
58 }
59
60 void TestDataSeriesUtils::testFillDataHoles()
61 {
62 QFETCH(std::vector<double>, xAxisData);
63 QFETCH(std::vector<double>, valuesData);
64 QFETCH(double, resolution);
65 QFETCH(double, fillValue);
66
67 QFETCH(std::vector<double>, expectedXAxisData);
68 QFETCH(std::vector<double>, expectedValuesData);
69
70 // Executes method (xAxisData and valuesData are modified)
71 DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue);
72
73 // Checks results
74 auto equal = [](const auto &data, const auto &expectedData) {
75 // Compares with NaN values
76 return std::equal(data.begin(), data.end(), expectedData.begin(), expectedData.end(),
77 [](const auto &val, const auto &expectedVal) {
78 return (std::isnan(val) && std::isnan(expectedVal))
79 || val == expectedVal;
80 });
81 };
82 QVERIFY(equal(xAxisData, expectedXAxisData));
83 QVERIFY(equal(valuesData, expectedValuesData));
84 }
85
86 QTEST_MAIN(TestDataSeriesUtils)
87 #include "TestDataSeriesUtils.moc"
@@ -1,64 +1,65
1 1
2 2 core_moc_headers = [
3 3 'include/Data/IDataProvider.h',
4 4 'include/DataSource/DataSourceController.h',
5 5 'include/DataSource/DataSourceItemAction.h',
6 6 'include/Network/NetworkController.h',
7 7 'include/Time/TimeController.h',
8 8 'include/Variable/Variable.h',
9 9 'include/Variable/VariableCacheController.h',
10 10 'include/Variable/VariableController.h',
11 11 'include/Variable/VariableAcquisitionWorker.h',
12 12 'include/Variable/VariableSynchronizationGroup.h',
13 13 'include/Variable/VariableModel.h',
14 14 'include/Visualization/VisualizationController.h'
15 15 ]
16 16
17 17
18 18 core_moc_files = qt5.preprocess(moc_headers : core_moc_headers)
19 19
20 20 core_sources = [
21 21 'src/Common/DateUtils.cpp',
22 22 'src/Common/StringUtils.cpp',
23 23 'src/Common/MimeTypesDef.cpp',
24 24 'src/Data/ScalarSeries.cpp',
25 25 'src/Data/SpectrogramSeries.cpp',
26 26 'src/Data/DataSeriesIterator.cpp',
27 27 'src/Data/ArrayDataIterator.cpp',
28 28 'src/Data/VectorSeries.cpp',
29 29 'src/Data/OptionalAxis.cpp',
30 'src/Data/DataSeriesUtils.cpp',
30 31 'src/DataSource/DataSourceController.cpp',
31 32 'src/DataSource/DataSourceItem.cpp',
32 33 'src/DataSource/DataSourceItemAction.cpp',
33 34 'src/Network/NetworkController.cpp',
34 35 'src/Plugin/PluginManager.cpp',
35 36 'src/Settings/SqpSettingsDefs.cpp',
36 37 'src/Time/TimeController.cpp',
37 38 'src/Variable/Variable.cpp',
38 39 'src/Variable/VariableCacheController.cpp',
39 40 'src/Variable/VariableController.cpp',
40 41 'src/Variable/VariableAcquisitionWorker.cpp',
41 42 'src/Variable/VariableSynchronizationGroup.cpp',
42 43 'src/Variable/VariableModel.cpp',
43 44 'src/Visualization/VisualizationController.cpp'
44 45 ]
45 46
46 47 core_inc = include_directories(['include', '../plugin/include'])
47 48
48 49 sciqlop_core_lib = library('sciqlopcore',
49 50 core_sources,
50 51 core_moc_files,
51 52 cpp_args : '-DCORE_LIB',
52 53 include_directories : core_inc,
53 54 dependencies : [qt5core, qt5network],
54 55 install : true
55 56 )
56 57
57 58
58 59 sciqlop_core = declare_dependency(link_with : sciqlop_core_lib,
59 60 include_directories : core_inc,
60 61 dependencies : [qt5core, qt5network])
61 62
62 63
63 64 subdir('tests')
64 65
@@ -1,31 +1,32
1 1
2 2
3 3 tests = [
4 4 [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'],
5 5 [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'],
6 6 [['Data/TestSpectrogramSeries.cpp'],'test_spectrogram','SpectrogramSeries test'],
7 7 [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'],
8 8 [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'],
9 9 [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'],
10 10 [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'],
11 [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'],
11 12 [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'],
12 13 [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'],
13 14 [['Variable/TestVariable.cpp'],'test_variable','Variable test'],
14 15 [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test']
15 16 ]
16 17
17 18 amdatest_sources = [
18 19 'Data/DataSeriesBuilders.h',
19 20 'Data/DataSeriesBuilders.cpp',
20 21 'Data/DataSeriesTestsUtils.h',
21 22 'Data/DataSeriesTestsUtils.cpp'
22 23 ]
23 24
24 25 foreach unit_test : tests
25 26 test_moc_files = qt5.preprocess(moc_sources : unit_test[0])
26 27 test_exe = executable(unit_test[1],unit_test[0] , test_moc_files,
27 28 dependencies : [sciqlop_core, qt5test],
28 29 sources : [amdatest_sources])
29 30 test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])])
30 31 endforeach
31 32
General Comments 0
You need to be logged in to leave comments. Login now