root/lib/common/tests/scores/pcmk__add_scores_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. score1_minus_inf
  2. score2_minus_inf
  3. score1_pos_inf
  4. score2_pos_inf
  5. result_infinite
  6. result_finite

   1 /*
   2  * Copyright 2022 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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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(-4000000, 50), -CRM_SCORE_INFINITY);
  57 }
  58 
  59 static void
  60 result_finite(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62     assert_int_equal(pcmk__add_scores(0, 0), 0);
  63     assert_int_equal(pcmk__add_scores(0, 100), 100);
  64     assert_int_equal(pcmk__add_scores(200, 0), 200);
  65     assert_int_equal(pcmk__add_scores(200, -50), 150);
  66 }
  67 
  68 PCMK__UNIT_TEST(NULL, NULL,
  69                 cmocka_unit_test(score1_minus_inf),
  70                 cmocka_unit_test(score2_minus_inf),
  71                 cmocka_unit_test(score1_pos_inf),
  72                 cmocka_unit_test(score2_pos_inf),
  73                 cmocka_unit_test(result_infinite),
  74                 cmocka_unit_test(result_finite))

/* [previous][next][first][last][top][bottom][index][help] */