Debian Codegraph @

tests/test_nb.c

raw
1 #include <check.h>
2 #include <freesasa_internal.h>
3 #include <nb.h>
4
5 #include "tools.h"
6
7 const double v[18] = {0, 0, 0, 1, 1, 1, -1, 1, -1, 2, 0, -2, 2, 2, 0, -5, 5, 5};
8 const double r[6] = {4, 2, 2, 2, 2, 2};
9
10 START_TEST(test_nb)
11 {
12 coord_t *coord = freesasa_coord_new();
13 nb_list *nb;
14 freesasa_coord_append(coord, v, 6);
15 ck_assert_ptr_eq(freesasa_nb_new(NULL, NULL), NULL);
16 ck_assert_ptr_eq(freesasa_nb_new(NULL, r), NULL);
17 ck_assert_ptr_eq(freesasa_nb_new(coord, NULL), NULL);
18
19 nb = freesasa_nb_new(coord, r);
20 ck_assert(nb != NULL);
21 ck_assert(freesasa_nb_contact(nb, 0, 1));
22 ck_assert(freesasa_nb_contact(nb, 1, 0));
23 ck_assert(freesasa_nb_contact(nb, 0, 5) == 0);
24 freesasa_nb_free(nb);
25 freesasa_coord_free(coord);
26 }
27 END_TEST
28
29 START_TEST(test_memerr)
30 {
31 freesasa_set_verbosity(FREESASA_V_SILENT);
32 double v[18] = {0, 0, 0, 1, 1, 1, -1, 1, -1, 2, 0, -2, 2, 2, 0, -5, 5, 5};
33 struct coord_t coord = {.xyz = v, .n = 6, .is_linked = 0};
34 const double r[6] = {4, 2, 2, 2, 2, 2};
35
36 for (int i = 1; i < 30; ++i) {
37 set_fail_after(i);
38 void *ptr = freesasa_nb_new(&coord, r);
39 set_fail_after(0);
40 ck_assert_ptr_eq(ptr, NULL);
41 }
42 freesasa_set_verbosity(FREESASA_V_NORMAL);
43 }
44 END_TEST
45
46 extern TCase *test_nb_static();
47
48 Suite *nb_suite()
49 {
50 Suite *s = suite_create("Neighbor lists");
51
52 TCase *tc_nb = tcase_create("Basic");
53 tcase_add_test(tc_nb, test_nb);
54 tcase_add_test(tc_nb, test_memerr);
55
56 TCase *tc_static = test_nb_static();
57
58 suite_add_tcase(s, tc_nb);
59 suite_add_tcase(s, tc_static);
60
61 return s;
62 }