pacemaker
2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
lib
common
tests
scores
pcmk__add_scores_test.c
Go to the documentation of this file.
1
/*
2
* Copyright 2022-2023 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
12
#include <
crm/common/unittest_internal.h
>
13
14
static
void
15
score1_minus_inf(
void
**state)
16
{
17
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
, -
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
18
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
, -1), -
CRM_SCORE_INFINITY
);
19
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
, 0), -
CRM_SCORE_INFINITY
);
20
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
, 1), -
CRM_SCORE_INFINITY
);
21
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
,
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
22
}
23
24
static
void
25
score2_minus_inf(
void
**state)
26
{
27
assert_int_equal(
pcmk__add_scores
(-1, -
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
28
assert_int_equal(
pcmk__add_scores
(0, -
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
29
assert_int_equal(
pcmk__add_scores
(1, -
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
30
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
, -
CRM_SCORE_INFINITY
), -
CRM_SCORE_INFINITY
);
31
}
32
33
static
void
34
score1_pos_inf(
void
**state)
35
{
36
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
,
CRM_SCORE_INFINITY
),
CRM_SCORE_INFINITY
);
37
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
, -1),
CRM_SCORE_INFINITY
);
38
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
, 0),
CRM_SCORE_INFINITY
);
39
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
, 1),
CRM_SCORE_INFINITY
);
40
}
41
42
static
void
43
score2_pos_inf(
void
**state)
44
{
45
assert_int_equal(
pcmk__add_scores
(-1,
CRM_SCORE_INFINITY
),
CRM_SCORE_INFINITY
);
46
assert_int_equal(
pcmk__add_scores
(0,
CRM_SCORE_INFINITY
),
CRM_SCORE_INFINITY
);
47
assert_int_equal(
pcmk__add_scores
(1,
CRM_SCORE_INFINITY
),
CRM_SCORE_INFINITY
);
48
}
49
50
static
void
51
result_infinite(
void
**state)
52
{
53
assert_int_equal(
pcmk__add_scores
(INT_MAX, INT_MAX),
CRM_SCORE_INFINITY
);
54
assert_int_equal(
pcmk__add_scores
(INT_MIN, INT_MIN), -
CRM_SCORE_INFINITY
);
55
assert_int_equal(
pcmk__add_scores
(2000000, 50),
CRM_SCORE_INFINITY
);
56
assert_int_equal(
pcmk__add_scores
(
CRM_SCORE_INFINITY
/2,
CRM_SCORE_INFINITY
/2),
CRM_SCORE_INFINITY
);
57
assert_int_equal(
pcmk__add_scores
(-
CRM_SCORE_INFINITY
/2, -
CRM_SCORE_INFINITY
/2), -
CRM_SCORE_INFINITY
);
58
assert_int_equal(
pcmk__add_scores
(-4000000, 50), -
CRM_SCORE_INFINITY
);
59
}
60
61
static
void
62
result_finite(
void
**state)
63
{
64
assert_int_equal(
pcmk__add_scores
(0, 0), 0);
65
assert_int_equal(
pcmk__add_scores
(0, 100), 100);
66
assert_int_equal(
pcmk__add_scores
(200, 0), 200);
67
assert_int_equal(
pcmk__add_scores
(200, -50), 150);
68
}
69
70
PCMK__UNIT_TEST
(NULL, NULL,
71
cmocka_unit_test(score1_minus_inf),
72
cmocka_unit_test(score2_minus_inf),
73
cmocka_unit_test(score1_pos_inf),
74
cmocka_unit_test(score2_pos_inf),
75
cmocka_unit_test(result_infinite),
76
cmocka_unit_test(result_finite))
PCMK__UNIT_TEST
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
CRM_SCORE_INFINITY
#define CRM_SCORE_INFINITY
Definition:
crm.h:84
crm_internal.h
unittest_internal.h
pcmk__add_scores
int pcmk__add_scores(int score1, int score2)
Definition:
scores.c:116
Generated on Tue Dec 19 2023 17:32:56 for pacemaker by
1.8.14