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 | |||

10 | /////////////////////// IsoSpec | ||

11 | #include <IsoSpec++/isoSpec++.h> | ||

12 | #include <IsoSpec++/element_tables.h> | ||

13 | |||

14 | |||

15 | /////////////////////// Catch2 includes | ||

16 | #include <catch2/catch_test_macros.hpp> | ||

17 | #include <catch2/matchers/catch_matchers_floating_point.hpp> | ||

18 | |||

19 | |||

20 | /////////////////////// Local includes | ||

21 | #include "tests-config.h" | ||

22 | #include <libXpertMass/Isotope.hpp> | ||

23 | #include <libXpertMass/IsotopicDataLibraryHandler.hpp> | ||

24 | #include <libXpertMass/Formula.hpp> | ||

25 | |||

26 | namespace MsXpS | ||

27 | { | ||

28 | |||

29 | namespace libXpertMass | ||

30 | { | ||

31 | |||

32 | QString glucose_formula_string("C6H12O6"); | ||

33 | QString saccharose_formula_string("C12H22O11"); | ||

34 | QString action_formula_string_MA_dipeptidyl("+C5H11N1O2S1-H2O+C3H7N1O2-H2O"); | ||

35 | QString action_formula_string_with_title( | ||

36 | "\"MA dipeptide\"+C5H11N1O2S1-H2O+C3H7N1O2-H2O"); | ||

37 | |||

38 | 12 | SCENARIO("Construction of Formula_s with a simple no-action string") | |

39 | { | ||

40 | |||

41 | 12 | WHEN("Constructed, using the constructor and the copy constructor") | |

42 | { | ||

43 | 4 | Formula formula_c6h12O6(glucose_formula_string); | |

44 | 4 | Formula formula_c6h12O6_copy(formula_c6h12O6); | |

45 | |||

46 | 4 | THEN("The the formula string is set to the member datum") | |

47 | { | ||

48 | 4 | REQUIRE(formula_c6h12O6.toString().toStdString() == | |

49 | glucose_formula_string.toStdString()); | ||

50 | 4 | REQUIRE(formula_c6h12O6_copy.toString().toStdString() == | |

51 | glucose_formula_string.toStdString()); | ||

52 | 4 | } | |

53 | 16 | } | |

54 | |||

55 | 12 | AND_WHEN("Setting another formula string manually") | |

56 | { | ||

57 | 4 | Formula formula_c6h12O6(glucose_formula_string); | |

58 | 4 | formula_c6h12O6.setFormula(saccharose_formula_string); | |

59 | |||

60 | 4 | THEN("The new formula string is set accordingly to the member datum") | |

61 | { | ||

62 | 4 | REQUIRE(formula_c6h12O6.toString().toStdString() == | |

63 | saccharose_formula_string.toStdString()); | ||

64 | 4 | } | |

65 | 16 | } | |

66 | |||

67 | 12 | AND_WHEN("Appending another formula string") | |

68 | { | ||

69 | 4 | Formula formula_c6h12O6(glucose_formula_string); | |

70 | 4 | formula_c6h12O6.appendFormula(saccharose_formula_string); | |

71 | 4 | QString after_appending_fomula(glucose_formula_string); | |

72 | 4 | after_appending_fomula += saccharose_formula_string; | |

73 | |||

74 | 4 | THEN("The member formula string is updated accordingly") | |

75 | { | ||

76 | 4 | REQUIRE(formula_c6h12O6.toString().toStdString() == | |

77 | after_appending_fomula.toStdString()); | ||

78 | 4 | } | |

79 | 16 | } | |

80 | 12 | } | |

81 | |||

82 | 4 | SCENARIO("Construction of Formula_s with another Formula instance") | |

83 | { | ||

84 | 4 | Formula formula_c6h12O6(glucose_formula_string); | |

85 | |||

86 | 4 | WHEN("Constructed with another Formula instance") | |

87 | { | ||

88 | 4 | Formula formula_c6h12O6_copy(formula_c6h12O6); | |

89 | |||

90 | 4 | THEN("The Formula string is set to the member datum") | |

91 | { | ||

92 | 4 | REQUIRE(formula_c6h12O6.toString().toStdString() == | |

93 | glucose_formula_string.toStdString()); | ||

94 | 4 | REQUIRE(formula_c6h12O6_copy.toString().toStdString() == | |

95 | glucose_formula_string.toStdString()); | ||

96 | 4 | } | |

97 | 8 | } | |

98 | 4 | } | |

99 | |||

100 | 20 | SCENARIO("Syntax checking of an action Formula with or without the title") | |

101 | { | ||

102 | 20 | Formula formula_MA_dipeptidyl(action_formula_string_MA_dipeptidyl); | |

103 | 20 | Formula titled_formula_MA_dipeptidyl(action_formula_string_with_title); | |

104 | |||

105 | 20 | WHEN("Constructed, the formula string is set to the member datum as is") | |

106 | { | ||

107 | 4 | REQUIRE(formula_MA_dipeptidyl.toString().toStdString() == | |

108 | action_formula_string_MA_dipeptidyl.toStdString()); | ||

109 | 4 | REQUIRE(titled_formula_MA_dipeptidyl.toString().toStdString() == | |

110 | action_formula_string_with_title.toStdString()); | ||

111 | 20 | } | |

112 | |||

113 | 20 | AND_WHEN("Checked without forcing an index even for single atoms") | |

114 | { | ||

115 | 4 | formula_MA_dipeptidyl.setForceCountIndex(false); | |

116 | 4 | titled_formula_MA_dipeptidyl.setForceCountIndex(false); | |

117 | |||

118 | 4 | THEN("Checking succeeds") | |

119 | { | ||

120 | 4 | REQUIRE(formula_MA_dipeptidyl.checkSyntax() == true); | |

121 | 4 | REQUIRE(titled_formula_MA_dipeptidyl.checkSyntax() == true); | |

122 | 4 | } | |

123 | 20 | } | |

124 | |||

125 | 20 | AND_WHEN("Checked with forcing an index even for single atoms") | |

126 | { | ||

127 | 4 | formula_MA_dipeptidyl.setForceCountIndex(true); | |

128 | 4 | titled_formula_MA_dipeptidyl.setForceCountIndex(true); | |

129 | |||

130 | 4 | THEN("Checking fails") | |

131 | { | ||

132 | |||

133 | 4 | REQUIRE(formula_MA_dipeptidyl.checkSyntax() == false); | |

134 | 4 | REQUIRE(titled_formula_MA_dipeptidyl.checkSyntax() == false); | |

135 | 4 | } | |

136 | 20 | } | |

137 | 20 | AND_WHEN("Checking an invalid Formula starting with a cipher") | |

138 | { | ||

139 | 4 | Formula formula("3Cz3H12O6N14L2"); | |

140 | 4 | formula.setForceCountIndex(false); | |

141 | |||

142 | 4 | THEN("Checking fails") | |

143 | { | ||

144 | 4 | REQUIRE(formula.checkSyntax() == false); | |

145 | 4 | } | |

146 | 24 | } | |

147 | |||

148 | 20 | AND_WHEN( | |

149 | "Checking an invalid Formula ending not with an alphabetic character or a " | ||

150 | "number") | ||

151 | { | ||

152 | 4 | Formula formula("Cz3H12O6N14L2Â§"); | |

153 | 4 | formula.setForceCountIndex(false); | |

154 | |||

155 | 4 | THEN("Checking fails") | |

156 | { | ||

157 | 4 | REQUIRE(formula.checkSyntax() == false); | |

158 | 4 | } | |

159 | 24 | } | |

160 | 20 | } | |

161 | |||

162 | 8 | SCENARIO("Validation of an action Formula, with or without a title") | |

163 | { | ||

164 | 8 | IsotopicDataLibraryHandler iso_data_lib_handler; | |

165 | |||

166 | 8 | std::size_t non_isotope_skipped_items = 0; | |

167 | std::size_t loaded_isotope_count = | ||

168 | 8 | iso_data_lib_handler.loadData(non_isotope_skipped_items); | |

169 | |||

170 | 8 | IsotopicDataCstSPtr isotopic_data_csp = nullptr; | |

171 | |||

172 | 8 | REQUIRE(loaded_isotope_count + non_isotope_skipped_items == | |

173 | IsoSpec::isospec_number_of_isotopic_entries); | ||

174 | |||

175 | 8 | isotopic_data_csp = iso_data_lib_handler.getIsotopicData(); | |

176 | 8 | REQUIRE(isotopic_data_csp->size() == loaded_isotope_count); | |

177 | |||

178 | 8 | Formula formula_MA_dipeptidyl(action_formula_string_MA_dipeptidyl); | |

179 | 8 | Formula titled_formula_MA_dipeptidyl(action_formula_string_with_title); | |

180 | |||

181 | 8 | WHEN("Constructed, the formula string is set to the member datum as is") | |

182 | { | ||

183 | 8 | REQUIRE(formula_MA_dipeptidyl.toString().toStdString() == | |

184 | action_formula_string_MA_dipeptidyl.toStdString()); | ||

185 | 8 | REQUIRE(titled_formula_MA_dipeptidyl.toString().toStdString() == | |

186 | action_formula_string_with_title.toStdString()); | ||

187 | |||

188 | 8 | AND_WHEN("Validated, the Formula creates + and - subformulas") | |

189 | { | ||

190 | 8 | bool reset_symbol_count_map = true; | |

191 | 8 | bool store_symbol_count_map = true; | |

192 | |||

193 | 8 | formula_MA_dipeptidyl.validate( | |

194 | isotopic_data_csp, store_symbol_count_map, reset_symbol_count_map); | ||

195 | 8 | titled_formula_MA_dipeptidyl.validate( | |

196 | isotopic_data_csp, store_symbol_count_map, reset_symbol_count_map); | ||

197 | |||

198 | 8 | THEN("The + and - sub formulas are checked") | |

199 | { | ||

200 | // "+C5H11N1O2S1-H20+C3H7N1O2-H2O" | ||

201 | 4 | REQUIRE(formula_MA_dipeptidyl.plusFormula().toStdString() == | |

202 | "C5H11N1O2S1C3H7N1O2"); | ||

203 | 4 | REQUIRE(formula_MA_dipeptidyl.minusFormula().toStdString() == | |

204 | "H2O1H2O1"); | ||

205 | |||

206 | 4 | REQUIRE(titled_formula_MA_dipeptidyl.plusFormula().toStdString() == | |

207 | "C5H11N1O2S1C3H7N1O2"); | ||

208 | 4 | REQUIRE(titled_formula_MA_dipeptidyl.minusFormula().toStdString() == | |

209 | "H2O1H2O1"); | ||

210 | 8 | } | |

211 | |||

212 | 8 | AND_THEN( | |

213 | "The symbol counts can be used to craft a new integrated " | ||

214 | "elemental composition string formula") | ||

215 | { | ||

216 | // Expecting result of "C5H11N1O2S1C3H7N1O2" - "H2O1H2O1" | ||

217 | // which is C8H18N2O4S1 - H4O2 | ||

218 | // which is C8H14N2O2S1 | ||

219 | 4 | std::vector<std::pair<QString, double>> symbol_count_pairs; | |

220 | QString elemental_composition = | ||

221 | 4 | formula_MA_dipeptidyl.elementalComposition(&symbol_count_pairs); | |

222 | 4 | REQUIRE(elemental_composition.toStdString() == "C8H14N2O2S1"); | |

223 | |||

224 | elemental_composition = | ||

225 | 4 | titled_formula_MA_dipeptidyl.elementalComposition(&symbol_count_pairs); | |

226 | 4 | REQUIRE(elemental_composition.toStdString() == "C8H14N2O2S1"); | |

227 | |||

228 | const std::map<QString, double> &formula_symbol_count_map = | ||

229 | 4 | formula_MA_dipeptidyl.symbolCountMap(); | |

230 | |||

231 | 4 | auto map_iterator = formula_symbol_count_map.find("C"); | |

232 | 4 | REQUIRE(map_iterator->second == 8); | |

233 | 4 | map_iterator = formula_symbol_count_map.find("H"); | |

234 | 4 | REQUIRE(map_iterator->second == 14); | |

235 | 4 | map_iterator = formula_symbol_count_map.find("N"); | |

236 | 4 | REQUIRE(map_iterator->second == 2); | |

237 | 4 | map_iterator = formula_symbol_count_map.find("O"); | |

238 | 4 | REQUIRE(map_iterator->second == 2); | |

239 | 4 | map_iterator = formula_symbol_count_map.find("S"); | |

240 | 4 | REQUIRE(map_iterator->second == 1); | |

241 | 12 | } | |

242 | 8 | } | |

243 | 8 | } | |

244 | 8 | } | |

245 | |||

246 | |||

247 | 24 | SCENARIO("Various ways to account a Formula for its masses (mono, avg)") | |

248 | { | ||

249 | 24 | IsotopicDataLibraryHandler iso_data_lib_handler; | |

250 | |||

251 | 24 | std::size_t non_isotope_skipped_items = 0; | |

252 | std::size_t loaded_isotope_count = | ||

253 | 24 | iso_data_lib_handler.loadData(non_isotope_skipped_items); | |

254 | |||

255 | 24 | IsotopicDataCstSPtr isotopic_data_csp = nullptr; | |

256 | |||

257 | 24 | REQUIRE(loaded_isotope_count + non_isotope_skipped_items == | |

258 | IsoSpec::isospec_number_of_isotopic_entries); | ||

259 | |||

260 | 24 | isotopic_data_csp = iso_data_lib_handler.getIsotopicData(); | |

261 | 24 | REQUIRE(isotopic_data_csp->size() == loaded_isotope_count); | |

262 | |||

263 | 24 | Formula formula_MA_dipeptidyl(action_formula_string_MA_dipeptidyl); | |

264 | |||

265 | 24 | WHEN("A Formula is created from string") | |

266 | { | ||

267 | |||

268 | 4 | THEN("Only its string formula is updated") | |

269 | { | ||

270 | 4 | REQUIRE(formula_MA_dipeptidyl.toString().toStdString() == | |

271 | action_formula_string_MA_dipeptidyl.toStdString()); | ||

272 | 4 | } | |

273 | 24 | } | |

274 | |||

275 | 24 | AND_WHEN( | |

276 | "That formula is validated with adequate options, its other member data " | ||

277 | "are updated") | ||

278 | { | ||

279 | 4 | bool reset_symbol_count_map = true; | |

280 | 4 | bool store_symbol_count_map = true; | |

281 | |||

282 | 4 | formula_MA_dipeptidyl.validate( | |

283 | isotopic_data_csp, store_symbol_count_map, reset_symbol_count_map); | ||

284 | |||

285 | 4 | THEN("The + and - sub formulas are checked") | |

286 | { | ||

287 | // "+C5H11N1O2S1-H20+C3H7N1O2-H2O" | ||

288 | 4 | REQUIRE(formula_MA_dipeptidyl.plusFormula().toStdString() == | |

289 | "C5H11N1O2S1C3H7N1O2"); | ||

290 | 4 | REQUIRE(formula_MA_dipeptidyl.minusFormula().toStdString() == "H2O1H2O1"); | |

291 | 4 | } | |

292 | 24 | } | |

293 | |||

294 | 24 | AND_WHEN("Masses are accounted for the action-formula") | |

295 | { | ||

296 | |||

297 | 16 | THEN("Mono and avg masses are updated in ony possible way") | |

298 | { | ||

299 | 4 | double mono = 0; | |

300 | 4 | double avg = 0; | |

301 | 4 | bool result = false; | |

302 | |||

303 | result = | ||

304 | 4 | formula_MA_dipeptidyl.accountMasses(isotopic_data_csp, &mono, &avg, 1); | |

305 | 4 | REQUIRE(result == true); | |

306 | 4 | REQUIRE_THAT(mono, | |

307 | Catch::Matchers::WithinAbs(202.07759887468, 0.0000000001)); | ||

308 | 4 | REQUIRE_THAT( | |

309 | avg, Catch::Matchers::WithinAbs(202.274890194285717, 0.0000000001)); | ||

310 | 16 | } | |

311 | |||

312 | 16 | AND_THEN("In another possible way") | |

313 | { | ||

314 | 4 | double mono = 0; | |

315 | 4 | double avg = 0; | |

316 | 4 | bool result = false; | |

317 | |||

318 | result = | ||

319 | 4 | formula_MA_dipeptidyl.accountMasses(isotopic_data_csp, &mono, &avg, 10); | |

320 | 4 | REQUIRE(result == true); | |

321 | 4 | REQUIRE_THAT( | |

322 | mono, Catch::Matchers::WithinAbs(202.07759887468 * 10, 0.0000000001)); | ||

323 | 4 | REQUIRE_THAT( | |

324 | avg, | ||

325 | Catch::Matchers::WithinAbs(202.274890194285717 * 10, 0.0000000001)); | ||

326 | 16 | } | |

327 | |||

328 | 16 | AND_THEN("In another possible way") | |

329 | { | ||

330 | 4 | Ponderable ponderable(0, 0); | |

331 | 4 | bool result = false; | |

332 | |||

333 | result = | ||

334 | 4 | formula_MA_dipeptidyl.accountMasses(isotopic_data_csp, &ponderable, 1); | |

335 | 4 | REQUIRE(result == true); | |

336 | 4 | REQUIRE_THAT(ponderable.mono(), | |

337 | Catch::Matchers::WithinAbs(202.07759887468, 0.0000000001)); | ||

338 | 4 | REQUIRE_THAT( | |

339 | ponderable.avg(), | ||

340 | Catch::Matchers::WithinAbs(202.274890194285717, 0.0000000001)); | ||

341 | 20 | } | |

342 | |||

343 | 16 | AND_THEN("In another possible way") | |

344 | { | ||

345 | 4 | Ponderable ponderable(0, 0); | |

346 | 4 | bool result = false; | |

347 | |||

348 | result = | ||

349 | 4 | formula_MA_dipeptidyl.accountMasses(isotopic_data_csp, &ponderable, 10); | |

350 | 4 | REQUIRE(result == true); | |

351 | 4 | REQUIRE_THAT( | |

352 | ponderable.mono(), | ||

353 | Catch::Matchers::WithinAbs(202.07759887468 * 10, 0.0000000001)); | ||

354 | 4 | REQUIRE_THAT( | |

355 | ponderable.avg(), | ||

356 | Catch::Matchers::WithinAbs(202.274890194285717 * 10, 0.0000000001)); | ||

357 | 20 | } | |

358 | 24 | } | |

359 | 24 | } | |

360 | |||

361 | |||

362 | } // namespace libXpertMass | ||

363 | } // namespace MsXpS | ||

364 |