1 /*
2 IGraph library.
3 Copyright (C) 2021 The igraph development team <igraph@igraph.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include <igraph.h>
20 #include "test_utilities.inc"
21
main()22 int main() {
23 igraph_vector_t data, result;
24
25 igraph_set_error_handler(igraph_error_handler_ignore);
26 igraph_vector_init_int(&result, 0);
27
28 printf("No values, binwidth 0 should fail.\n");
29 igraph_vector_init_int(&data, 0);
30 IGRAPH_ASSERT(igraph_running_mean(&data, &result, /*binwidth*/ 0) == IGRAPH_EINVAL);
31 igraph_vector_destroy(&data);
32
33 printf("No values, binwidth 1 should fail.\n");
34 igraph_vector_init_int(&data, 0);
35 IGRAPH_ASSERT(igraph_running_mean(&data, &result, /*binwidth*/ 1) == IGRAPH_EINVAL);
36 igraph_vector_destroy(&data);
37
38 printf("One value, binwidth 1:\n");
39 igraph_vector_init_int(&data, 1, 1);
40 IGRAPH_ASSERT(igraph_running_mean(&data, &result, /*binwidth*/ 1) == IGRAPH_SUCCESS);
41 print_vector(&result);
42 igraph_vector_destroy(&data);
43
44 printf("1, 2, 3, 4, 5, binwidth 1:\n");
45 igraph_vector_init_int(&data, 5, 1, 2, 3, 4, 5);
46 IGRAPH_ASSERT(igraph_running_mean(&data, &result, /*binwidth*/ 1) == IGRAPH_SUCCESS);
47 print_vector(&result);
48 igraph_vector_destroy(&data);
49
50 printf("1, 2, 3, 4, 5, binwidth 2:\n");
51 igraph_vector_init_int(&data, 5, 1, 2, 3, 4, 5);
52 IGRAPH_ASSERT(igraph_running_mean(&data, &result, /*binwidth*/ 2) == IGRAPH_SUCCESS);
53 print_vector(&result);
54 igraph_vector_destroy(&data);
55
56 igraph_vector_destroy(&result);
57
58 VERIFY_FINALLY_STACK();
59 return 0;
60 }
61