Skip to content

Commit 34af12e

Browse files
committed
solve unreached codecov lines by raising warning
1 parent ff8a23c commit 34af12e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/froll.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,11 @@ void frollprodExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill
10781078
* algo="fast" is a novel sort-median algorithm
10791079
* names suffixed with "2" are corresponding versions that support even k window size, as opposed to the algorithm described in the original paper
10801080
*/
1081-
1081+
1082+
// four branches have missing codecov, we use those flags to detect that users' code reached those lines
1083+
// then we raise a warning asking for report and to use algo=exact for now
1084+
int codecov_delete_else = 0, codecov_m0_i = 0, codecov_s0_0 = 0, codecov_xam = 0;
1085+
10821086
#ifdef MIN
10831087
#undef MIN
10841088
#endif
@@ -1125,14 +1129,20 @@ static void delete(int i, const double *x, int *prev, int *next, int *m, int *s,
11251129
prev[next[i]] = prev[i];
11261130
if (SMALL(i)) {
11271131
s[0]--;
1132+
//codecov_delete_else = 1; // search for codecov above; this is only dev testing warning from the branch below, uncomment this and run frollmedian(1:9, 3)
11281133
} else {
1134+
// # nocov start
1135+
codecov_delete_else = 1; // search for codecov above
11291136
if (m[0] == i) {
1137+
codecov_m0_i = 1; // search for codecov above
11301138
m[0] = next[m[0]];
11311139
}
11321140
if (s[0] > 0) {
1141+
codecov_s0_0 = 1; // search for codecov above
11331142
m[0] = prev[m[0]];
11341143
s[0]--;
11351144
}
1145+
// # nocov end
11361146
}
11371147
}
11381148
#define DELETE(j) delete(i, &x[(j)*k], &prev[(j)*(k+1)], &next[(j)*(k+1)], &m[(j)], &s[(j)], tail)
@@ -1159,7 +1169,10 @@ static double med2(const double *xa, const double *xb, int ma, int na, int mb, i
11591169
double xbm = mb == tail ? R_PosInf : xb[mb];
11601170
double xbn = nb == tail ? R_PosInf : xb[nb];
11611171
if (xam == xbm) {
1172+
// # nocov start
1173+
codecov_xam = 1; // search for codecov above
11621174
return xam;
1175+
// # nocov end
11631176
} else if (xam < xbm) { // so xam < xbn
11641177
if (xan <= xbm) { // so xan <= xbn
11651178
return (xam + xan) / 2;
@@ -1365,6 +1378,11 @@ void frollmedianFast(const double *x, uint64_t nx, ans_t *ans, int k, double fil
13651378
for (int i=0; i<k-1; i++) {
13661379
ansv[i] = fill;
13671380
}
1381+
// missing codecov lines catching - search for codecov above
1382+
codecov_delete_else = 0;
1383+
codecov_m0_i = 0;
1384+
codecov_s0_0 = 0;
1385+
codecov_xam = 0;
13681386
// main rolling loop - called post processing in the paper
13691387
if (verbose)
13701388
tic = omp_get_wtime();
@@ -1452,6 +1470,12 @@ void frollmedianFast(const double *x, uint64_t nx, ans_t *ans, int k, double fil
14521470
}
14531471
}
14541472
free(next); free(prev); free(s); free(n); free(m); free(o);
1473+
if (codecov_delete_else || codecov_m0_i || codecov_s0_0 || codecov_xam) {
1474+
// # nocov start
1475+
ans->status = 2;
1476+
snprintf(end(ans->message[2]), 500, _("%s: algo='fast' algorithm has reached an untested lines of code: %d%d%d%d. Please report to data.table issue tracker including this error message and ideally a reproducible example. Please use algo='exact' for now.\n"), "frollmedianFast", codecov_delete_else, codecov_m0_i, codecov_s0_0, codecov_xam);
1477+
// # nocov end
1478+
}
14551479
if (verbose)
14561480
snprintf(end(ans->message[0]), 500, _("%s: rolling took %.3f\n"), "frollmedianFast", omp_get_wtime()-tic);
14571481
}

0 commit comments

Comments
 (0)