Line |
Branch |
Exec |
Source |
1 |
|
|
// ./tests/catch2-tests [section] -s |
2 |
|
|
|
3 |
|
|
|
4 |
|
|
/////////////////////// Qt includes |
5 |
|
|
#include <QDebug> |
6 |
|
|
#include <QString> |
7 |
|
|
#include <QDir> |
8 |
|
|
|
9 |
|
|
/////////////////////// IsoSpec |
10 |
|
|
#include <IsoSpec++/isoSpec++.h> |
11 |
|
|
#include <IsoSpec++/element_tables.h> |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
/////////////////////// Catch2 includes |
15 |
|
|
#include <catch2/catch_test_macros.hpp> |
16 |
|
|
#include <catch2/matchers/catch_matchers_floating_point.hpp> |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
/////////////////////// Local includes |
20 |
|
|
#include "tests-config.h" |
21 |
|
|
#include <libXpertMass/Isotope.hpp> |
22 |
|
|
#include <libXpertMass/IsotopicDataUserConfigHandler.hpp> |
23 |
|
|
|
24 |
|
|
namespace MsXpS |
25 |
|
|
{ |
26 |
|
|
|
27 |
|
|
namespace libXpertMass |
28 |
|
|
{ |
29 |
|
|
|
30 |
|
|
QString user_config_isotopic_data_file_name("light-c-n.dat"); |
31 |
|
|
QString isotopic_data_file_name = |
32 |
|
|
QString("%1/%2/%3") |
33 |
|
|
.arg(TESTS_INPUT_DIR, "isotopes", user_config_isotopic_data_file_name); |
34 |
|
|
|
35 |
|
|
IsotopicDataUserConfigHandler |
36 |
|
|
iso_data_user_config_handler(isotopic_data_file_name); |
37 |
|
|
|
38 |
|
|
|
39 |
|
8 |
SCENARIO("IsotopicDataUserConfigHandler loads data from file") |
40 |
|
|
{ |
41 |
|
|
|
42 |
8/14
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 8 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 4 times.
|
8 |
WHEN("Constructed, the data are empty") |
43 |
|
|
{ |
44 |
|
|
|
45 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The isotopic data are empty but they are allocated") |
46 |
|
|
{ |
47 |
6/16
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData() != nullptr); |
48 |
|
4 |
} |
49 |
|
8 |
} |
50 |
|
|
|
51 |
8/14
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 8 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 4 times.
|
8 |
AND_WHEN("Loading isotopic data from a user config file") |
52 |
|
|
{ |
53 |
|
|
std::size_t loaded_isotope_count = |
54 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
iso_data_user_config_handler.loadData(isotopic_data_file_name); |
55 |
|
|
|
56 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The number of isotopes loaded is checked") |
57 |
|
|
{ |
58 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
4 |
REQUIRE(loaded_isotope_count > 0); |
59 |
7/18
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
✓ Branch 25 taken 4 times.
✗ Branch 26 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData()->size() == |
60 |
|
|
loaded_isotope_count); |
61 |
|
|
// FIXME: remove debug code belows |
62 |
|
4 |
double prova = 0.025602148; |
63 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 19 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
4 |
REQUIRE_THAT(prova, Catch::Matchers::WithinAbs(0.025602148, 0.0000001)); |
64 |
|
4 |
} |
65 |
|
8 |
} |
66 |
|
8 |
} |
67 |
|
|
|
68 |
|
12 |
SCENARIO( |
69 |
|
|
"IsotopicDataUserConfigHandler loads data from file previously " |
70 |
|
|
"written by writeDate test for IsotopicDataLibraryHandler") |
71 |
|
|
{ |
72 |
|
|
isotopic_data_file_name = |
73 |
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 |
QString("%1/%2/%3").arg(TESTS_OUTPUT_DIR, "isotopes", "isospec-tables.dat"); |
74 |
|
|
|
75 |
8/14
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 12 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 12 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 8 times.
|
12 |
WHEN("Constructed, the data are empty") |
76 |
|
|
{ |
77 |
|
|
|
78 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The isotopic data are empty but they are allocated") |
79 |
|
|
{ |
80 |
6/16
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData() != nullptr); |
81 |
|
4 |
} |
82 |
|
12 |
} |
83 |
|
|
|
84 |
8/14
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 12 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 12 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 8 times.
|
12 |
AND_WHEN("Loading isotopic data from a user config file") |
85 |
|
|
{ |
86 |
|
|
std::size_t loaded_isotope_count = |
87 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
iso_data_user_config_handler.loadData(isotopic_data_file_name); |
88 |
|
|
|
89 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The number of isotopes loaded is checked") |
90 |
|
|
{ |
91 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
4 |
REQUIRE(loaded_isotope_count > 0); |
92 |
7/18
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
✓ Branch 25 taken 4 times.
✗ Branch 26 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData()->size() == |
93 |
|
|
loaded_isotope_count); |
94 |
|
4 |
} |
95 |
|
12 |
} |
96 |
|
|
|
97 |
8/14
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 12 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 12 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 8 times.
|
12 |
AND_WHEN("A new IsotopicDataUserConfigHandler instance is copy constructed") |
98 |
|
|
{ |
99 |
|
|
long use_count_before_copy = |
100 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
iso_data_user_config_handler.getIsotopicData().use_count(); |
101 |
|
|
|
102 |
|
|
IsotopicDataUserConfigHandler iso_data_user_config_handler_1( |
103 |
|
4 |
iso_data_user_config_handler); |
104 |
|
|
|
105 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The instances are checked and should be identical") |
106 |
|
|
{ |
107 |
9/22
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 4 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 4 times.
✗ Branch 28 not taken.
✓ Branch 33 taken 4 times.
✗ Branch 34 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData()->size() == |
108 |
|
|
iso_data_user_config_handler_1.getIsotopicData()->size()); |
109 |
|
|
|
110 |
|
|
long use_count_after_copy = |
111 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
iso_data_user_config_handler.getIsotopicData().use_count(); |
112 |
|
|
|
113 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
4 |
REQUIRE(use_count_after_copy == use_count_before_copy + 1); |
114 |
|
4 |
} |
115 |
|
16 |
} |
116 |
|
12 |
} |
117 |
|
|
|
118 |
|
8 |
SCENARIO("IsotopicDataUserConfigHandler writes data to file") |
119 |
|
|
{ |
120 |
|
|
|
121 |
7/14
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 8 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 8 times.
✗ Branch 24 not taken.
|
8 |
WHEN("Data have been loaded, the data are checked") |
122 |
|
|
{ |
123 |
|
|
std::size_t loaded_isotope_count = |
124 |
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 |
iso_data_user_config_handler.loadData(isotopic_data_file_name); |
125 |
|
|
|
126 |
8/14
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 8 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 4 times.
|
8 |
THEN("The number of isotopes loaded is checked") |
127 |
|
|
{ |
128 |
7/18
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
✓ Branch 25 taken 4 times.
✗ Branch 26 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
|
4 |
REQUIRE(iso_data_user_config_handler.getIsotopicData()->size() == |
129 |
|
|
loaded_isotope_count); |
130 |
|
8 |
} |
131 |
|
|
|
132 |
8/14
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 8 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 4 times.
|
8 |
AND_WHEN("Isotopic data are written to file") |
133 |
|
|
{ |
134 |
|
|
QString isotopes_output_dir = |
135 |
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 |
QString("%1/%2").arg(TESTS_OUTPUT_DIR, "isotopes"); |
136 |
|
|
|
137 |
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 |
QDir dir; |
138 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
bool result = dir.mkpath(isotopes_output_dir); |
139 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
4 |
REQUIRE(result == true); |
140 |
|
|
|
141 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 |
QString output_file_name = QString("%1/%2").arg( |
142 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
isotopes_output_dir, user_config_isotopic_data_file_name); |
143 |
|
|
|
144 |
|
|
// qDebug() << "The write file name: " << output_file_name.toStdString() |
145 |
|
|
// << std::endl; |
146 |
|
|
|
147 |
|
|
std::size_t written_isotope_count = |
148 |
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 |
iso_data_user_config_handler.writeData(output_file_name); |
149 |
|
|
|
150 |
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
|
4 |
THEN("The count of written isotopes is checked") |
151 |
|
|
{ |
152 |
5/14
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
4 |
REQUIRE(written_isotope_count == loaded_isotope_count); |
153 |
|
4 |
} |
154 |
|
12 |
} |
155 |
|
8 |
} |
156 |
|
8 |
} |
157 |
|
|
|
158 |
|
|
|
159 |
|
|
} // namespace libXpertMass |
160 |
|
|
} // namespace MsXpS |
161 |
|
|
|