File: test_CleavageConfig.cpp

package info (click to toggle)
libxpertmass 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,908 kB
  • sloc: cpp: 50,586; xml: 2,193; python: 417; ansic: 70; makefile: 33
file content (231 lines) | stat: -rw-r--r-- 7,855 bytes parent folder | download
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
/////////////////////// Qt includes
#include <QDebug>
#include <QString>
#include <QDir>


/////////////////////// Catch2 includes
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>


/////////////////////// Local includes
#include "TestUtils.hpp"
#include <libXpertMass/CleavageConfig.hpp>
#include <libXpertMass/Sequence.hpp>
#include <libXpertMass/Monomer.hpp>

namespace MsXpS
{
namespace libXpertMassCore
{

TestUtils test_utils_cleavage_config_1_letter("protein-1-letter", 1);
TestUtils test_utils_cleavage_config_3_letters("protein-3-letters", 1);

ErrorList error_list_cleavage_config;

SCENARIO("Construction of a CleavageConfig object", "[CleavageConfig]")
{
  test_utils_cleavage_config_1_letter.initializeXpertmassLibrary();
  PolChemDefCstSPtr pol_chem_def_csp =
    test_utils_cleavage_config_1_letter.msp_polChemDef;

  WHEN("A CleavageConfig constructed with all params")
  {
    CleavageConfig cleavage_config(pol_chem_def_csp,
                                   "Trypsin",
                                   "K/;-K/P;R/",
                                   0,
                                   /*is_sequence_embedded*/ true);

    cleavage_config.setStartIonizeLevel(1);
    cleavage_config.setStopIonizeLevel(10);

    THEN("All the members are set accordingly")
    {
      REQUIRE(cleavage_config.getPartials() == 0);
      REQUIRE(cleavage_config.getStartIonizeLevel() == 1);
      REQUIRE(cleavage_config.getStopIonizeLevel() == 10);
      REQUIRE(cleavage_config.isSequenceEmbedded());
    }

    AND_WHEN("Some data members are modified")
    {
      cleavage_config.setPartials(1);
      cleavage_config.setSequenceEmbedded(false);

      THEN("The corresponding members are updated")
      {
        REQUIRE(cleavage_config.getPartials() == 1);
        REQUIRE(cleavage_config.getStartIonizeLevel() == 1);
        REQUIRE(cleavage_config.getStopIonizeLevel() == 10);
        REQUIRE_FALSE(cleavage_config.isSequenceEmbedded());
      }

      AND_WHEN(
        "Another CleavageConfig instance is created by copy-construction or "
        "assignment")
      {
        CleavageConfig other_cleavage_config(cleavage_config);
        CleavageConfig another_cleavage_config;
        another_cleavage_config = other_cleavage_config;

        THEN(
          "The other CleavageConfig instances are identical to the initial one")
        {
          REQUIRE(another_cleavage_config.getPartials() == 1);
          REQUIRE(another_cleavage_config.getStartIonizeLevel() == 1);
          REQUIRE(another_cleavage_config.getStopIonizeLevel() == 10);
          REQUIRE_FALSE(another_cleavage_config.isSequenceEmbedded());
        }
      }
    }
  }
}


SCENARIO("CleavageConfig objects can be compared with operators ==() and !=().",
         "[CleavageConfig]")
{
  test_utils_cleavage_config_1_letter.initializeXpertmassLibrary();
  PolChemDefCstSPtr pol_chem_def_csp =
    test_utils_cleavage_config_1_letter.msp_polChemDef;

  WHEN("Two identical CleavageConfig objects are constructed with all params")
  {
    CleavageConfig cleavage_config_1(pol_chem_def_csp,
                                     "Trypsin",
                                     "K/;-K/P;R/",
                                     0,
                                     /*is_sequence_embedded*/ true);

    cleavage_config_1.setStartIonizeLevel(1);
    cleavage_config_1.setStopIonizeLevel(10);

    CleavageConfig cleavage_config_2(pol_chem_def_csp,
                                     "Trypsin",
                                     "K/;-K/P;R/",
                                     0,
                                     /*is_sequence_embedded*/ true);

    // Choose on purpose this variant :-)
    cleavage_config_2.setIonizeLevels(1, 10);


    THEN("All the members are set accordingly")
    {
      REQUIRE(cleavage_config_1.getName().toStdString() == "Trypsin");
      REQUIRE(cleavage_config_1.getPattern().toStdString() == "K/;-K/P;R/");
      REQUIRE(cleavage_config_1.isValid());

      REQUIRE(cleavage_config_1.getPartials() == 0);
      REQUIRE(cleavage_config_1.getStartIonizeLevel() == 1);
      REQUIRE(cleavage_config_1.getStopIonizeLevel() == 10);
      REQUIRE(cleavage_config_1.isSequenceEmbedded());

      REQUIRE(cleavage_config_2.getName().toStdString() == "Trypsin");
      REQUIRE(cleavage_config_2.getPattern().toStdString() == "K/;-K/P;R/");
      REQUIRE(cleavage_config_2.isValid());

      REQUIRE(cleavage_config_2.getPartials() == 0);
      REQUIRE(cleavage_config_2.getStartIonizeLevel() == 1);
      REQUIRE(cleavage_config_2.getStopIonizeLevel() == 10);
      REQUIRE(cleavage_config_2.isSequenceEmbedded());
    }

    AND_THEN("The comparison operators return proper results")
    {
      REQUIRE(cleavage_config_1 == cleavage_config_2);
      REQUIRE_FALSE(cleavage_config_1 != cleavage_config_2);
    }
  }
}


SCENARIO("CleavageConfig objects can be copy- or assignment- constructed",
         "[CleavageConfig]")
{
  test_utils_cleavage_config_1_letter.initializeXpertmassLibrary();
  PolChemDefCstSPtr pol_chem_def_csp =
    test_utils_cleavage_config_1_letter.msp_polChemDef;

  WHEN("A CleavageConfig constructed with all params")
  {
    CleavageConfig cleavage_config(pol_chem_def_csp,
                                   "Trypsin",
                                   "K/;-K/P;R/",
                                   0,
                                   /*is_sequence_embedded*/ true);

    cleavage_config.setStartIonizeLevel(1);
    cleavage_config.setStopIonizeLevel(10);

    THEN("All the members are set accordingly")
    {
      REQUIRE(cleavage_config.getPartials() == 0);
      REQUIRE(cleavage_config.getStartIonizeLevel() == 1);
      REQUIRE(cleavage_config.getStopIonizeLevel() == 10);
      REQUIRE(cleavage_config.isSequenceEmbedded());
    }

    AND_WHEN("New CleavageConfig objects are instantiated")
    {
      CleavageConfig another_cleavage_config(cleavage_config);
      CleavageConfig other_cleavage_config;
      other_cleavage_config = another_cleavage_config;

      THEN("The copies must be identical to the original object")
      {
        REQUIRE(other_cleavage_config.getPartials() == 0);
        REQUIRE(other_cleavage_config.getStartIonizeLevel() == 1);
        REQUIRE(other_cleavage_config.getStopIonizeLevel() == 10);
        REQUIRE(other_cleavage_config.isSequenceEmbedded());

        REQUIRE(other_cleavage_config == cleavage_config);
        REQUIRE_FALSE(other_cleavage_config != cleavage_config);
      }
    }
  }
}

SCENARIO("Construction of an empty CleavageConfig object", "[CleavageConfig]")
{
  test_utils_cleavage_config_1_letter.initializeXpertmassLibrary();
  PolChemDefCstSPtr pol_chem_def_csp =
    test_utils_cleavage_config_1_letter.msp_polChemDef;

  WHEN("An empty CleavageConfig constructed")
  {
    CleavageConfig cleavage_config;

    AND_WHEN("A Cleavage agent is used to initialize it")
    {
      CleavageAgent cleavage_agent(pol_chem_def_csp, "Trypsin", "K/;-K/P;R/");

      cleavage_config.setCleavageAgent(cleavage_agent);

      AND_WHEN("The setter functions are used to configure the CleavageConfig")
      {
        cleavage_config.setPartials(0);
        cleavage_config.setSequenceEmbedded(false);
        cleavage_config.setStartIonizeLevel(1);
        cleavage_config.setStopIonizeLevel(10);

        THEN("The member data are correctly set")
        {
          REQUIRE(cleavage_config.getPartials() == 0);
          REQUIRE(cleavage_config.getStartIonizeLevel() == 1);
          REQUIRE(cleavage_config.getStopIonizeLevel() == 10);
          REQUIRE_FALSE(cleavage_config.isSequenceEmbedded());

          REQUIRE(static_cast<CleavageAgent>(cleavage_config) ==
                  cleavage_agent);
        }
      }
    }
  }
}

} // namespace libXpertMassCore
} // namespace MsXpS