pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__add_scores_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 static void
15 score1_minus_inf(void **state)
16 {
17  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY,
20  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, -1),
22  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, 0),
24  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, 1),
26  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY,
29 }
30 
31 static void
32 score2_minus_inf(void **state)
33 {
34  assert_int_equal(pcmk__add_scores(-1, -PCMK_SCORE_INFINITY),
36  assert_int_equal(pcmk__add_scores(0, -PCMK_SCORE_INFINITY),
38  assert_int_equal(pcmk__add_scores(1, -PCMK_SCORE_INFINITY),
40  assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY,
43 }
44 
45 static void
46 score1_pos_inf(void **state)
47 {
50  assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, -1),
52  assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, 0),
54  assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, 1),
56 }
57 
58 static void
59 score2_pos_inf(void **state)
60 {
61  assert_int_equal(pcmk__add_scores(-1, PCMK_SCORE_INFINITY),
63  assert_int_equal(pcmk__add_scores(0, PCMK_SCORE_INFINITY),
65  assert_int_equal(pcmk__add_scores(1, PCMK_SCORE_INFINITY),
67 }
68 
69 static void
70 result_infinite(void **state)
71 {
72  assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), PCMK_SCORE_INFINITY);
73  assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -PCMK_SCORE_INFINITY);
74  assert_int_equal(pcmk__add_scores(2000000, 50), PCMK_SCORE_INFINITY);
75  assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY/2,
78  assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY/2,
81  assert_int_equal(pcmk__add_scores(-4000000, 50), -PCMK_SCORE_INFINITY);
82 }
83 
84 static void
85 result_finite(void **state)
86 {
87  assert_int_equal(pcmk__add_scores(0, 0), 0);
88  assert_int_equal(pcmk__add_scores(0, 100), 100);
89  assert_int_equal(pcmk__add_scores(200, 0), 200);
90  assert_int_equal(pcmk__add_scores(200, -50), 150);
91 }
92 
93 PCMK__UNIT_TEST(NULL, NULL,
94  cmocka_unit_test(score1_minus_inf),
95  cmocka_unit_test(score2_minus_inf),
96  cmocka_unit_test(score1_pos_inf),
97  cmocka_unit_test(score2_pos_inf),
98  cmocka_unit_test(result_infinite),
99  cmocka_unit_test(result_finite))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk__add_scores(int score1, int score2)
Definition: scores.c:167
#define PCMK_SCORE_INFINITY
Integer score to use to represent "infinity".
Definition: scores.h:24