Skip to content

Commit

Permalink
Extend and cleanup test code to cover issue Tlf#178 and fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
dl1jbe committed Nov 10, 2020
1 parent 4631cde commit 62bbb7f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,14 @@ int scoreByContinentOrCountry() {
extern char continent[];

int points = 0;
int inList = 0;
bool inList = false;

inList = exist_in_country_list();
if (countrylist_only) {
if (inList == 1 && countrylist_points != -1)
if (inList && countrylist_points != -1)
points = countrylist_points;
} else {

if (inList == 1) {
if (inList) {
if (countrylist_points != -1)
points = countrylist_points;

Expand All @@ -221,16 +220,16 @@ int scoreByContinentOrCountry() {

/* HA2OS mods */
if (continentlist_only) {
points = 0;
// only continent list allowed
if (is_in_continentlist(continent)) {
// are we are on DX continent or not
if (strcmp(continent, my.continent) == 0) {
if ((strcmp(continent, my.continent) == 0) &&
(my_cont_points != -1)) {
points = my_cont_points;
} else if (continentlist_points != -1) {
points = continentlist_points;
}
} else {
points = 0;
}
}

Expand Down
35 changes: 33 additions & 2 deletions test/test_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ static void init_continentlist() {

void test_empty_continentlist(void **state) {
assert_int_equal(is_in_continentlist(""), false);
assert_int_equal(is_in_continentlist("SA"), false);
assert_int_equal(is_in_continentlist("NA"), false);
}

void test_not_in_continnetlist(void ** state) {
void test_not_in_continentlist(void ** state) {
init_continentlist();
assert_int_equal(is_in_continentlist("SA"), false);
}
Expand All @@ -328,15 +328,46 @@ void test_scoreByCorC_countrylistOnly(void **state) {

void test_scoreByCorC_continentlistOnly(void **state) {
continentlist_only = true;
/* empty list */
check_call_points("LZ1AB", 0);

init_continentlist();

/* no list points given */
check_call_points("LZ1AB", 0);
check_call_points("JA4BB", 0);

/* same, but my_cont_points set */
my_cont_points = 1;
check_call_points("LZ1AB", 1);
check_call_points("XE2AAA", 0);
check_call_points("JA4BB", 0);

/* my_cont_points, cont_list_points given */
continentlist_points = 2;
check_call_points("LZ1AB", 1);
check_call_points("XE2AAA", 2);
check_call_points("JA4BB", 0);

/* only cont_list_points given */
my_cont_points = -1;
check_call_points("LZ1AB", 2);
check_call_points("XE2AAA", 2);
check_call_points("JA4BB", 0);
}


void test_scoreByCorC_continentlistOnly_ignoreDxContPoints(void **state) {
continentlist_only = true;
check_call_points("LZ1AB", 0);

dx_cont_points = 2;
init_continentlist();
check_call_points("LZ1AB", 0);
check_call_points("XE2AAA", 0);
}


void test_scoreByCorC_notInList(void **state) {

/* my_country/cont_points and dx_cont_points not set */
Expand Down

0 comments on commit 62bbb7f

Please sign in to comment.