1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
|
// ./tests/catch2-tests [section] -s
/////////////////////// Qt includes
#include <QDebug>
#include <QString>
#include <QStringList>
#include <QDir>
/////////////////////// IsoSpec
#include <IsoSpec++/isoSpec++.h>
#include <IsoSpec++/element_tables.h>
/////////////////////// Catch2 includes
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
/////////////////////// Local includes
#include "tests-config.h"
#include "TestUtils.hpp"
#include <libXpertMass/Modif.hpp>
namespace MsXpS
{
namespace libXpertMassCore
{
TestUtils test_utils_1_letter_modif("protein-1-letter", 1);
ErrorList error_list;
bool ok;
int mdf_element_index = 0;
int name_element_index = 1;
int name_text_index = 2;
int formula_element_index = 3;
int formula_text_index = 4;
int targets_element_index = 5;
int targets_text_index = 6;
int maxcount_element_index = 7;
int maxcount_text_index = 8;
QStringList dom_strings{"mdf",
"name",
"Acetylation",
"formula",
"-H2O+CH3COOH",
"targets",
"K",
"maxcount",
"1"};
SCENARIO("Construction of a Modif starting from empty", "[Modif]")
{
WHEN("A Modif is created empty")
{
Modif modif;
THEN("It is invalid and does not validate successfully")
{
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
qDebug() << "HERE";
THEN(
"It is not possible to assess if it is known to the polymer chemistry "
"definition")
{
REQUIRE(modif.isKnownByNameInPolChemDef() ==
Enums::PolChemDefEntityStatus::POL_CHEM_DEF_NOT_AVAILABLE);
}
AND_WHEN("Setting the PolChemDef")
{
modif.setPolChemDefCstSPtr(test_utils_1_letter_modif.msp_polChemDef);
THEN(
"It must be set but the Modif is still invalid and does not validate "
"successfully")
{
REQUIRE(modif.getPolChemDefCstSPtr() ==
test_utils_1_letter_modif.msp_polChemDef);
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
AND_WHEN("Setting an empty name")
{
modif.setName("");
THEN(
"It must be set but the Modif is still invalid and does not validate "
"successfully")
{
REQUIRE(modif.getName().toStdString() == "");
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
}
AND_WHEN("Setting the name")
{
REQUIRE(modif.getPolChemDefCstSPtr() ==
test_utils_1_letter_modif.msp_polChemDef);
modif.setName("Acetylation");
THEN(
"It must be set but the Modif is still invalid and does not validate "
"successfully")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
AND_WHEN("Setting a bad formula with title")
{
modif.setFormula("\"The title\"-h2O+cH3COOH");
THEN(
"It must be set and the Modif is still invalid and does not "
"validate "
"successfully")
{
REQUIRE(modif.getFormula().toStdString() ==
"\"The title\"-h2O+cH3COOH");
REQUIRE(modif.formula(/*with_title*/ false).toStdString() ==
"-h2O+cH3COOH");
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
}
AND_WHEN("Setting a valid formula with title")
{
REQUIRE(modif.getPolChemDefCstSPtr() ==
test_utils_1_letter_modif.msp_polChemDef);
modif.setFormula("\"The title\"-H2O+CH3COOH");
THEN(
"It must be set and now the Modif is not valid (targets not "
"defined) and does not validate successfully")
{
qDebug() << "The modif:" << modif.toString();
REQUIRE(modif.getFormula().toStdString() ==
"\"The title\"-H2O+CH3COOH");
REQUIRE(modif.formula(/*with_title*/ false).toStdString() ==
"-H2O+CH3COOH");
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
AND_WHEN("Setting an erroneous targets string")
{
QString failing_targets_string("ST*Y!");
modif.setTargets(failing_targets_string);
THEN("The Modif is not valid and does not validate successfully")
{
qDebug() << "The modif:" << modif.toString();
modif.validateTargets(/*simplify*/ true, ok);
REQUIRE_FALSE(ok);
modif.validateTargets(
failing_targets_string, /*simplify*/ true, ok);
REQUIRE_FALSE(ok);
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
}
AND_WHEN("Setting a correct targets string")
{
QString targets_string("K;R;M;C");
modif.setTargets(targets_string);
THEN(
"The Modif is not valid (max count not defined) and does not "
"validate successfully")
{
qDebug() << "The modif:" << modif.toString();
modif.validateTargets(/*simplify*/ true, ok);
REQUIRE(ok);
modif.validateTargets(targets_string, /*simplify*/ true, ok);
REQUIRE(ok);
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
AND_WHEN("Setting an erroneous max count value")
{
modif.setMaxCount(0);
THEN(
"The Modif is not valid anymore and does not validate "
"successfully")
{
qDebug() << "The modif:" << modif.toString();
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
AND_WHEN("Setting a correct max count value")
{
modif.setMaxCount(2);
THEN(
"The Modif is valid and does validate "
"successfully")
{
qDebug() << "The modif:" << modif.toString();
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
}
}
}
}
}
}
}
}
}
SCENARIO(
"Construction of a Modif starting from valid PolChemDef, name and formula",
"[Modif]")
{
WHEN("A Modif is created with PolChemDef, name and formula")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
THEN(
"The Modif is not valid and does not validate successfully (targets and "
"max count not defined)")
{
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
REQUIRE_FALSE(modif.isValid());
AND_THEN("Calculating the masses should work nonetheless")
{
modif.calculateMasses(nullptr);
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
}
AND_WHEN("Setting proper targets and max count")
{
modif.setTargets("M;C");
modif.setMaxCount(3);
THEN("It is valid and does validate successfully")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
}
}
}
}
SCENARIO("Setting bad values with setters invalidates a valid Modif", "[Modif]")
{
GIVEN(
"A Modif created with PolChemDef, name and formula, and targets and max "
"count set")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("K;R");
modif.setMaxCount(2);
qDebug() << "At this point, the modif:" << modif.toString();
THEN(
"The Modif is valid and validates successfully with masses properly "
"calculated")
{
qDebug() << "BEFORE The modif: " << modif.toString();
REQUIRE(modif.isValid());
qDebug() << "AFTER The modif: " << modif.toString();
error_list.clear();
REQUIRE(modif.validate(&error_list));
modif.calculateMasses(nullptr);
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
WHEN("Setting an empty name")
{
modif.setName("");
THEN("It is no more valid and does not validate successfully")
{
REQUIRE_FALSE(modif.isValid());
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
}
modif.setName("Acetylation");
}
}
}
SCENARIO("A Modif can be searched for in the PolChemDef", "[Modif]")
{
WHEN("A Modif is created with PolChemDef, existing name and formula")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
THEN(
"The Modif is not valid and does not validate successfully (targets and "
"max count not defined) althought the masses are properly calculated")
{
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
REQUIRE_FALSE(modif.isValid());
modif.calculateMasses(nullptr);
double mono = 0;
double avg = 0;
REQUIRE(modif.accountMasses(mono, avg, /*times*/ 1) == modif);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
mono = 0;
avg = 0;
REQUIRE(modif.accountMasses(&mono, &avg, /*times*/ 1) == modif);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
mono = 0;
avg = 0;
REQUIRE(modif.accountMasses(nullptr, nullptr, /*times*/ 1) == modif);
REQUIRE_THAT(mono, Catch::Matchers::WithinAbs(0, 0.0000000001));
REQUIRE_THAT(avg, Catch::Matchers::WithinAbs(0, 0.0000000001));
}
THEN("Calculating masses proactively should work")
{
REQUIRE(
modif ==
modif.calculateMasses(
ok,
test_utils_1_letter_modif.msp_polChemDef->getIsotopicDataCstSPtr()));
REQUIRE(modif == modif.calculateMasses(ok, nullptr));
REQUIRE(modif.calculateMasses(nullptr));
}
THEN("The Modif in the PolChemDef can be retrieved by member name")
{
ModifCstSPtr modif_csp = test_utils_1_letter_modif.msp_polChemDef->getModifCstSPtrByName(modif.getName());
REQUIRE(modif_csp != nullptr);
REQUIRE(modif_csp->getName().toStdString() == "Acetylation");
}
THEN(
"The Modif in the PolChemDef can be retrieved by explicit name")
{
ModifCstSPtr modif_csp = test_utils_1_letter_modif.msp_polChemDef->getModifCstSPtrByName(modif.getName());
REQUIRE(modif_csp != nullptr);
REQUIRE(modif_csp->getName().toStdString() == "Acetylation");
modif_csp = test_utils_1_letter_modif.msp_polChemDef->getModifCstSPtrByName("");
REQUIRE(
modif_csp == nullptr);
}
THEN("The Modif in the PolChemDef can checked by name")
{
REQUIRE(modif.isKnownByNameInPolChemDef() == Enums::PolChemDefEntityStatus::ENTITY_KNOWN);
}
}
WHEN(
"A Modif is created with PolChemDef, inexisting name, correct formula, "
"targets and max count")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Notacetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("M;C");
modif.setMaxCount(2);
THEN(
"The Modif is valid and validates successfully with masses properly "
"calculated")
{
error_list.clear();
REQUIRE(modif.validate(&error_list));
REQUIRE(modif.isValid());
modif.calculateMasses(nullptr);
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
THEN("Calculating masses proactively should work")
{
REQUIRE(
modif ==
modif.calculateMasses(
ok,
test_utils_1_letter_modif.msp_polChemDef->getIsotopicDataCstSPtr()));
}
THEN("The Modif in the PolChemDef cannot be retrieved by member name")
{
ModifCstSPtr modif_csp = test_utils_1_letter_modif.msp_polChemDef->getModifCstSPtrByName(modif.getName());
REQUIRE(modif_csp == nullptr);
modif_csp = modif.getFromPolChemDefByName();
REQUIRE(modif_csp == nullptr);
REQUIRE(modif.isKnownByNameInPolChemDef() ==
Enums::PolChemDefEntityStatus::ENTITY_NOT_KNOWN);
}
}
}
SCENARIO("Construction of a Modif with the copy constructor", "[Modif]")
{
WHEN("A Modif is created with PolChemDef, name and formula")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("M;C");
modif.setMaxCount(2);
THEN(
"The Modif is valid and validates successfully with masses properly "
"calculated")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(modif.getMass(Enums::MassType::MONO),
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(modif.getMass(Enums::MassType::AVG),
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
AND_WHEN("Another Modif is copy-constructed")
{
Modif new_modif(modif);
THEN("It should be identical to the previous one")
{
REQUIRE(new_modif.getName().toStdString() ==
modif.getName().toStdString());
REQUIRE(new_modif.getFormula().toStdString() ==
modif.getFormula().toStdString());
REQUIRE(new_modif.formula(/*with_title*/ false).toStdString() ==
modif.formula(/*with_title*/ false).toStdString());
REQUIRE(new_modif.getTargets().toStdString() ==
modif.getTargets().toStdString());
REQUIRE(new_modif.getMaxCount() == modif.getMaxCount());
}
THEN("The equality operator should work fine")
{
REQUIRE(new_modif == modif);
REQUIRE_FALSE(new_modif != modif);
}
}
AND_WHEN(
"Another Modif is initialized using it with the assignment operator=()")
{
Modif another_new_modif;
another_new_modif = modif;
THEN("It should be identical to the previous one")
{
REQUIRE(another_new_modif.getName().toStdString() ==
modif.getName().toStdString());
REQUIRE(another_new_modif.getFormula().toStdString() ==
modif.getFormula().toStdString());
REQUIRE(another_new_modif.formula(/*with_title*/ false).toStdString() ==
modif.formula(/*with_title*/ false).toStdString());
REQUIRE(another_new_modif.getTargets().toStdString() ==
modif.getTargets().toStdString());
REQUIRE(another_new_modif.getMaxCount() == modif.getMaxCount());
}
THEN("Assigning a Modif to itself should return itself.")
{
REQUIRE((another_new_modif = another_new_modif) == another_new_modif);
}
THEN("The equality operator should work fine")
{
REQUIRE(another_new_modif == modif);
REQUIRE_FALSE(another_new_modif != modif);
REQUIRE(another_new_modif == another_new_modif);
REQUIRE_FALSE(another_new_modif != another_new_modif);
}
}
}
}
SCENARIO("A Modif can be checked for its targets", "[Modif]")
{
WHEN(
"A Modif is created with PolChemDef, name and formula, then targets are "
"set using setter")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("M;C");
modif.setMaxCount(2);
THEN("The Modif is checked")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
REQUIRE(modif.doesTargetMonomer("M"));
REQUIRE(modif.doesTargetMonomer("C"));
REQUIRE_FALSE(modif.doesTargetMonomer("A"));
}
AND_WHEN("Set targets '*'")
{
modif.setTargets("*");
THEN("All codes should be targeted")
{
REQUIRE(modif.doesTargetMonomer("M"));
REQUIRE(modif.doesTargetMonomer("C"));
REQUIRE(modif.doesTargetMonomer("A"));
}
}
AND_WHEN("Set targets '!'")
{
modif.setTargets("!");
THEN("No code should be targeted")
{
REQUIRE_FALSE(modif.doesTargetMonomer("M"));
REQUIRE_FALSE(modif.doesTargetMonomer("C"));
REQUIRE_FALSE(modif.doesTargetMonomer("A"));
}
}
}
}
SCENARIO("A Modif can output itself as a string", "[Modif]")
{
WHEN(
"A Modif is created with PolChemDef, name, formula, then set with targets "
"and max count")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("M;C");
modif.setMaxCount(2);
qDebug() << "The modif: " << modif.toString();
THEN(
"The Modif is valid and validates successfully with masses properly "
"calculated")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
THEN("The string has the right contents")
{
REQUIRE(modif.toString().toStdString() ==
"Acetylation, \"The title\"-H2O+CH3COOH, ;M;C;, 2");
}
}
}
SCENARIO("Modif instances can be constructed using a correct XML element",
"[Modif]")
{
QStringList dom_strings;
dom_strings << "mdf"
<< "name"
<< "Acetylation"
<< "formula"
<< "-H2O+CH3COOH"
<< "targets"
<< "K"
<< "maxcount"
<< "3";
GIVEN("A proper set of strings, a proper XML element can be crafted")
{
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(dom_strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
REQUIRE(
document.toString().toStdString() ==
"<mdf>\n <name>Acetylation</name>\n <formula>-H2O+CH3COOH</formula>\n "
"<targets>K</targets>\n <maxcount>3</maxcount>\n</mdf>\n");
// qDebug() << "The document:" << document.toString();
WHEN("A Modif instance is allocated using that string and no PolChemDef")
{
Modif modif(nullptr, mdf_element, 1);
THEN("The Modif instance has only partial proper member data")
{
REQUIRE(modif.getPolChemDefCstSPtr() == nullptr);
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE(modif.getFormula().toStdString() == "-H2O+CH3COOH");
REQUIRE(modif.getTargets().toStdString() == "K");
REQUIRE(modif.getMaxCount() == -1);
AND_THEN(
"The Modif instance cannot validate successfully because of missing "
"PolChemDef and targets string that could not validate because of "
"the missing PolChemDef.")
{
error_list.clear();
REQUIRE_FALSE(modif.validate(&error_list));
REQUIRE_FALSE(modif.isValid());
}
}
}
WHEN("A Modif instance is allocated using that string and valid PolChemDef")
{
Modif modif =
Modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance has proper member data")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE(modif.getFormula().toStdString() == "-H2O+CH3COOH");
REQUIRE(modif.getTargets().toStdString() == ";K;");
REQUIRE(modif.getMaxCount() == 3);
AND_THEN("The Modif instance is valid and must validate successfully")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
}
}
}
}
}
SCENARIO(
"Modif instances cannot be correctly constructed using incorrect XML "
"elements",
"[Modif]")
{
QStringList dom_strings;
dom_strings << "mdf"
<< "name"
<< "Acetylation"
<< "formula"
<< "-H2O+CH3COOH"
<< "targets"
<< "K"
<< "maxcount"
<< "3";
// int mdf_element_index = 0;
// int name_element_index = 1;
// int name_text_index = 2;
// int formula_element_index = 3;
// int formula_text_index = 4;
// int targets_element_index = 5;
// int targets_text_index = 6;
// int maxcount_element_index = 7;
// int maxcount_text_index = 8;
GIVEN("An XML element with an incorrect mdf element tag")
{
QStringList strings(dom_strings);
strings[mdf_element_index] = "not_mdf";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect name element tag")
{
QStringList strings(dom_strings);
strings[name_element_index] = "not_name";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect formula element tag")
{
QStringList strings(dom_strings);
strings[formula_element_index] = "not_formula";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect formula element text")
{
QStringList strings(dom_strings);
strings[formula_text_index] = "+h2O";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect target element tag")
{
QStringList strings(dom_strings);
strings[targets_element_index] = "not-targets";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect target element text")
{
QStringList strings(dom_strings);
strings[targets_text_index] = "$";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect target element text")
{
QStringList strings(dom_strings);
strings[targets_text_index] = "m";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect max count element tag")
{
QStringList strings(dom_strings);
strings[maxcount_element_index] = "not-maxcount";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
GIVEN("An XML element with an incorrect max count element text")
{
QStringList strings(dom_strings);
strings[maxcount_text_index] = "-1";
QDomDocument document =
test_utils_1_letter_modif.craftMdfDomDocument(strings);
QDomElement mdf_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
WHEN("A Modif instance is allocated using that string")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef, mdf_element, 1);
THEN("The Modif instance is incorrect")
{
REQUIRE(modif.getName().toStdString() == "Acetylation");
REQUIRE_FALSE(modif.isValid());
REQUIRE_FALSE(modif.validate(&error_list));
}
}
}
}
SCENARIO("A Modif can output itself as an XML element string", "[Modif]")
{
WHEN("A Modif is created with PolChemDef, name and formula")
{
Modif modif(test_utils_1_letter_modif.msp_polChemDef,
"Acetylation",
"\"The title\"-H2O+CH3COOH");
modif.setTargets("M;C");
modif.setMaxCount(2);
THEN(
"The Modif is valid and validates successfully with masses properly "
"calculated")
{
REQUIRE(modif.isValid());
error_list.clear();
REQUIRE(modif.validate(&error_list));
double mono = 0;
double avg = 0;
modif.accountMasses(mono, avg, /*times*/ 1);
REQUIRE_THAT(mono,
Catch::Matchers::WithinAbs(42.0105646847, 0.0000000001));
REQUIRE_THAT(avg,
Catch::Matchers::WithinAbs(42.0369401545, 0.0000000001));
}
THEN("The string has the right contents")
{
QString xml_element_string =
modif.formatXmlMdfElement(0, Utils::xmlIndentationToken);
QString expected_xml_string =
"<mdf>\n"
" <name>Acetylation</name>\n"
" <formula>\"The title\"-H2O+CH3COOH</formula>\n"
" <targets>;M;C;</targets>\n"
" <maxcount>2</maxcount>\n"
"</mdf>\n"
"";
REQUIRE(xml_element_string.toStdString() ==
expected_xml_string.toStdString());
}
}
}
} // namespace libXpertMassCore
} // namespace MsXpS
|