Skip to content

Commit 88d4b68

Browse files
committed
Removed superfluous if-statement
1 parent b566323 commit 88d4b68

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

unitttest/unittest.c

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,19 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
184184
}
185185

186186
// test that EXPECTED solution is there (if requested)
187-
if (str) {
188-
nrTests++;
189-
for (i = 0; i < nrresults; i++) {
190-
const char *m = mapcodes.mapcode[i];
191-
if (strstr(m, clean) == m) {
192-
found = 1;
193-
break;
194-
}
195-
}
196-
if (!found) {
197-
nrErrors++;
198-
printf("*** ERROR *** encode(%0.8f , %0.8f) does not deliver \"%s\"\n", y, x, clean);
199-
printGeneratedMapcodes("Delivered", &mapcodes);
187+
nrTests++;
188+
for (i = 0; i < nrresults; i++) {
189+
const char *m = mapcodes.mapcode[i];
190+
if (strstr(m, clean) == m) {
191+
found = 1;
192+
break;
200193
}
201194
}
195+
if (!found) {
196+
nrErrors++;
197+
printf("*** ERROR *** encode(%0.8f , %0.8f) does not deliver \"%s\"\n", y, x, clean);
198+
printGeneratedMapcodes("Delivered", &mapcodes);
199+
}
202200
}
203201

204202

@@ -217,14 +215,14 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
217215
for (precision = 0; precision <= 8; precision++) {
218216
nrresults = encodeLatLonToMapcodes(&mapcodes, y, x, 0, precision);
219217
for (i = 0; i < nrresults; i++) {
220-
const char *str = mapcodes.mapcode[i];
218+
const char *strResult = mapcodes.mapcode[i];
221219

222220
// check if every solution decodes
223221
nrTests++;
224-
err = decodeMapcodeToLatLon(&lat, &lon, str, 0);
222+
err = decodeMapcodeToLatLon(&lat, &lon, strResult, 0);
225223
if (err) {
226224
nrErrors++;
227-
printf("*** ERROR *** decode('%s') = no result, expected ~(%0.8f , %0.8f)\n", str, y, x);
225+
printf("*** ERROR *** decode('%s') = no result, expected ~(%0.8f , %0.8f)\n", strResult, y, x);
228226
}
229227
else {
230228
double dm = distanceInMeters(y, x, lat, lon);
@@ -234,17 +232,20 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
234232
if (dm > maxerror) {
235233
nrErrors++;
236234
printf("*** ERROR *** decode('%s') = (%0.8f , %0.8f), which is %0.4f cm way (>%0.4f cm) from (%0.8f , %0.8f)\n",
237-
str, lat, lon,
235+
strResult, lat, lon,
238236
dm * 100.0, maxerror * 100.0, y, x);
239237
}
240238
else {
241239
Mapcodes mapcodesTerritory;
242240
Mapcodes mapcodesParent;
243-
int tc2 = -1, tcParent = -1, j, found = 0;
244-
char *e = strchr(str, ' ');
241+
int tc2 = -1;
242+
int tcParent = -1;
243+
int j;
244+
found = 0;
245+
char *e = strchr(strResult, ' ');
245246
if (e) {
246247
*e = 0;
247-
tc2 = convertTerritoryIsoNameToCode(str, 0);
248+
tc2 = convertTerritoryIsoNameToCode(strResult, 0);
248249
tcParent = getParentCountryOf(tc2);
249250
*e = ' ';
250251
}
@@ -255,7 +256,7 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
255256
{
256257
const int nr = encodeLatLonToMapcodes(&mapcodesTerritory, lat, lon, tc2, precision);
257258
for (j = 0; j < nr; j++) {
258-
if (strcmp(mapcodesTerritory.mapcode[j], str) == 0) {
259+
if (strcmp(mapcodesTerritory.mapcode[j], strResult) == 0) {
259260
found = 1;
260261
break;
261262
}
@@ -265,7 +266,7 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
265266
if (!found && (tcParent >= 0)) {
266267
const int nr = encodeLatLonToMapcodes(&mapcodesParent, lat, lon, tcParent, precision);
267268
for (j = 0; j < nr; j++) {
268-
if (strcmp(strchr(mapcodesParent.mapcode[j], ' '), strchr(str, ' ')) == 0) {
269+
if (strcmp(strchr(mapcodesParent.mapcode[j], ' '), strchr(strResult, ' ')) == 0) {
269270
found = 1;
270271
break;
271272
}
@@ -276,7 +277,7 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
276277
if (!multipleBordersNearby(lat, lon, tc2)) { // but SHOULD be reproduced!
277278
nrErrors++;
278279
printf("*** ERROR *** %s does not re-encode (%0.15f,%0.15f) from (%0.15f,%0.15f)\n",
279-
str, lat, lon, y, x);
280+
strResult, lat, lon, y, x);
280281
printGeneratedMapcodes("Global ", &mapcodes);
281282
printGeneratedMapcodes("Territory", &mapcodesTerritory);
282283
if (tcParent >= 0) {
@@ -588,39 +589,39 @@ void territory_code_tests() {
588589
int context;
589590
const char *inputstring;
590591
} tcTestData[] = {
591-
{ -1, 0, ""},
592-
{ -1, 0, "R"},
593-
{ -1, 0, "RX"},
594-
{ -1, 0, "RXX"},
595-
{497, 0, "RUS"},
596-
{ -1, 0, "RUSSIA"},
597-
{411, 0, "US"},
598-
{411, 0, "USA"},
599-
{411, 0, "usa"},
600-
{ -1, 0, "US-TEST"},
601-
{411, 0, "US TEST"},
602-
{392, 0, "US-CA"},
603-
{392, 0, "US-CA TEST"},
604-
{392, 0, "USA-CA"},
605-
{431, 0, "RUS-TAM"},
606-
{ -1, 0, "RUS-TAMX"},
607-
{431, 0, "RUS-TAM X"},
608-
{319, 0, "AL"}, //
609-
{483,497, "AL"}, // 497=rus
610-
{483,431, "AL"}, // 431=ru-tam
611-
{365,411, "AL"}, // 411=usa
612-
{365,392, "AL"}, // 392=us-ca
613-
{0,0,NULL}
592+
{-1, 0, ""},
593+
{-1, 0, "R"},
594+
{-1, 0, "RX"},
595+
{-1, 0, "RXX"},
596+
{497, 0, "RUS"},
597+
{-1, 0, "RUSSIA"},
598+
{411, 0, "US"},
599+
{411, 0, "USA"},
600+
{411, 0, "usa"},
601+
{-1, 0, "US-TEST"},
602+
{411, 0, "US TEST"},
603+
{392, 0, "US-CA"},
604+
{392, 0, "US-CA TEST"},
605+
{392, 0, "USA-CA"},
606+
{431, 0, "RUS-TAM"},
607+
{-1, 0, "RUS-TAMX"},
608+
{431, 0, "RUS-TAM X"},
609+
{319, 0, "AL"}, //
610+
{483, 497, "AL"}, // 497=rus
611+
{483, 431, "AL"}, // 431=ru-tam
612+
{365, 411, "AL"}, // 411=usa
613+
{365, 392, "AL"}, // 392=us-ca
614+
{0, 0, NULL}
614615
};
615616

616-
for (i = 0; tcTestData[i].inputstring!=NULL; i++ ) {
617+
for (i = 0; tcTestData[i].inputstring != NULL; i++) {
617618
int tc = getTerritoryCode(tcTestData[i].inputstring, tcTestData[i].context);
618619
nrTests++;
619620
if (tc != tcTestData[i].expectedresult) {
620621
nrErrors++;
621622
printf("*** ERROR *** getTerritoryCode(\"%s\", %d)=%d, expected %d\n",
622-
tcTestData[i].inputstring, tcTestData[i].context,
623-
tc, tcTestData[i].expectedresult);
623+
tcTestData[i].inputstring, tcTestData[i].context,
624+
tc, tcTestData[i].expectedresult);
624625
}
625626
}
626627
}

0 commit comments

Comments
 (0)