1 /*
2 * DO NOT EDIT THIS FILE. Generated by checkmk.
3 * Edit the original source file "constraints_soft.ts" instead.
4 */
5
6 #include <check.h>
7
8 #line 1 "constraints_soft.ts"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <math.h>
13
14 #include <ViennaRNA/data_structures.h>
15 #include <ViennaRNA/utils/strings.h>
16 #include <ViennaRNA/constraints/soft.h>
17
18
19
START_TEST(test_vrna_sc_add_up_simple)20 START_TEST(test_vrna_sc_add_up_simple)
21 {
22 #line 15
23 {
24 int i, j;
25
26 char *seq = vrna_random_string(10, "ACGU");
27
28 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
29
30 for (i = 1; i <= fc->length; i++)
31 vrna_sc_add_up(fc, i, -1. * i, VRNA_OPTION_DEFAULT);
32
33 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
34
35 vrna_sc_t *sc = fc->sc;
36
37 ck_assert(sc != NULL);
38 ck_assert(sc->energy_up != NULL);
39
40 for (i = 1; i <= fc->length; i++) {
41 int counter = 0;
42 for (j = 1; i + j - 1 <= fc->length; j++) {
43 counter += (j + i - 1) * -100;
44 ck_assert_int_eq(sc->energy_up[i][j], counter);
45 }
46 }
47
48 vrna_sc_remove(fc);
49 ck_assert(fc->sc == NULL);
50
51 /* clean up */
52 vrna_fold_compound_free(fc);
53 free(seq);
54 }
55
56 }
57 END_TEST
58
START_TEST(test_vrna_sc_add_up_addition)59 START_TEST(test_vrna_sc_add_up_addition)
60 {
61 #line 49
62 {
63 int i, e;
64
65 char *seq = vrna_random_string(10, "ACGU");
66
67 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
68
69 for (e = 0, i = 1; i <= fc->length; i++) {
70 vrna_sc_add_up(fc, 1, -1. * i, VRNA_OPTION_DEFAULT);
71 e += -100 * i;
72 }
73
74 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
75
76 vrna_sc_t *sc = fc->sc;
77
78 ck_assert(sc != NULL);
79 ck_assert(sc->energy_up != NULL);
80
81 for (i = 1; i <= fc->length; i++)
82 ck_assert_int_eq(sc->energy_up[1][i], e);
83
84 vrna_sc_remove(fc);
85 ck_assert(fc->sc == NULL);
86
87 /* clean up */
88 vrna_fold_compound_free(fc);
89 free(seq);
90 }
91
92 }
93 END_TEST
94
START_TEST(test_vrna_sc_add_up_addition_extended)95 START_TEST(test_vrna_sc_add_up_addition_extended)
96 {
97 #line 80
98 {
99 int i, j, e;
100
101 char *seq = vrna_random_string(10, "ACGU");
102
103 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
104
105 for (i = 1, e = 0; i <= fc->length; i++) {
106 e += -100 * i;
107 for (j = 1; j <= fc->length; j++)
108 vrna_sc_add_up(fc, j, -1. * i, VRNA_OPTION_DEFAULT);
109 }
110
111 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
112
113 vrna_sc_t *sc = fc->sc;
114
115 ck_assert(sc != NULL);
116 ck_assert(sc->energy_up != NULL);
117
118 for (i = 1; i <= fc->length; i++)
119 for (j = 1; i + j - 1 <= fc->length; j++)
120 ck_assert_int_eq(sc->energy_up[i][j], j * e);
121
122 vrna_sc_remove(fc);
123 ck_assert(fc->sc == NULL);
124
125 /* clean up */
126 vrna_fold_compound_free(fc);
127 free(seq);
128 }
129
130 }
131 END_TEST
132
START_TEST(test_vrna_sc_add_bp)133 START_TEST(test_vrna_sc_add_bp)
134 {
135 #line 113
136 {
137 int i, j, turn;
138
139 char *seq = vrna_random_string(10, "ACGU");
140
141 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
142 turn = fc->params->model_details.min_loop_size;
143
144 for (i = 1; i < fc->length; i++)
145 for (j = i + turn + 1; j <= fc->length; j++)
146 vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
147
148 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
149
150 vrna_sc_t *sc = fc->sc;
151
152 ck_assert(sc != NULL);
153 ck_assert(sc->energy_bp != NULL);
154
155 for (i = 1; i < fc->length; i++)
156 for (j = i + turn + 1; j <= fc->length; j++)
157 ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * (i + j));
158
159 vrna_sc_remove(fc);
160 ck_assert(fc->sc == NULL);
161
162 /* clean up */
163 vrna_fold_compound_free(fc);
164 free(seq);
165 }
166
167 }
168 END_TEST
169
START_TEST(test_vrna_sc_add_bp_addition)170 START_TEST(test_vrna_sc_add_bp_addition)
171 {
172 #line 145
173 {
174 int i, j, c, num, turn;
175
176 num = 10;
177
178 char *seq = vrna_random_string(10, "ACGU");
179
180 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
181 turn = fc->params->model_details.min_loop_size;
182
183 for (c = 0; c < num; c++)
184 for (i = 1; i < fc->length; i++)
185 for (j = i + turn + 1; j <= fc->length; j++)
186 vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
187
188 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
189
190 vrna_sc_t *sc = fc->sc;
191
192 ck_assert(sc != NULL);
193 ck_assert(sc->energy_bp != NULL);
194
195 for (i = 1; i < fc->length; i++)
196 for (j = i + turn + 1; j <= fc->length; j++)
197 ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * num * (i + j));
198
199 vrna_sc_remove(fc);
200 ck_assert(fc->sc == NULL);
201
202 /* clean up */
203 vrna_fold_compound_free(fc);
204 free(seq);
205 }
206
207 }
208 END_TEST
209
START_TEST(test_vrna_sc_add_bp_removal)210 START_TEST(test_vrna_sc_add_bp_removal)
211 {
212 #line 180
213 {
214 int i, j, c, num, num_r, turn;
215
216 num = 10;
217 num_r = 3;
218
219 char *seq = vrna_random_string(10, "ACGU");
220
221 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
222 turn = fc->params->model_details.min_loop_size;
223
224 for (c = 0; c < num; c++)
225 for (i = 1; i < fc->length; i++)
226 for (j = i + turn + 1; j <= fc->length; j++)
227 vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
228
229 for (c = 0; c < num_r; c++)
230 for (i = 1; i < fc->length; i++)
231 for (j = i + turn + 1; j <= fc->length; j++)
232 vrna_sc_add_bp(fc, i, j, 1. * (i + j), VRNA_OPTION_DEFAULT);
233
234 vrna_sc_prepare(fc, VRNA_OPTION_MFE);
235
236 vrna_sc_t *sc = fc->sc;
237
238 ck_assert(sc != NULL);
239 ck_assert(sc->energy_bp != NULL);
240
241 for (i = 1; i < fc->length; i++)
242 for (j = i + turn + 1; j <= fc->length; j++)
243 ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * (num - num_r) * (i + j));
244
245 vrna_sc_remove(fc);
246 ck_assert(fc->sc == NULL);
247
248 /* clean up */
249 vrna_fold_compound_free(fc);
250 free(seq);
251 }
252 }
253 END_TEST
254
main(void)255 int main(void)
256 {
257 Suite *s1 = suite_create("Constraints");
258 TCase *tc1_1 = tcase_create("SoftConstraints");
259 SRunner *sr = srunner_create(s1);
260 int nf;
261
262 suite_add_tcase(s1, tc1_1);
263 tcase_add_test(tc1_1, test_vrna_sc_add_up_simple);
264 tcase_add_test(tc1_1, test_vrna_sc_add_up_addition);
265 tcase_add_test(tc1_1, test_vrna_sc_add_up_addition_extended);
266 tcase_add_test(tc1_1, test_vrna_sc_add_bp);
267 tcase_add_test(tc1_1, test_vrna_sc_add_bp_addition);
268 tcase_add_test(tc1_1, test_vrna_sc_add_bp_removal);
269
270 srunner_run_all(sr, CK_ENV);
271 nf = srunner_ntests_failed(sr);
272 srunner_free(sr);
273
274 return nf == 0 ? 0 : 1;
275 }
276