BigMult unit test, fix ncmetric bogon #929

This commit is contained in:
nick black 2020-08-20 17:34:35 -04:00
parent f8854f84e8
commit bc0016b827
3 changed files with 14 additions and 2 deletions

View File

@ -374,7 +374,8 @@ summary_table(struct ncdirect* nc, const char* spec){
qprefix(results[i].stats.render_ns, GIG, rtimebuf, 0);
bprefix(results[i].stats.render_bytes, 1, totalbuf, 0);
if(results[i].stats.renders){
qprefix((uintmax_t)results[i].stats.renders * GIG * 1000 / results[i].stats.render_ns, 1000, tfpsbuf, 0);
qprefix((uintmax_t)results[i].stats.renders * GIG * 1000 / results[i].stats.render_ns,
1000, tfpsbuf, 0);
}else{
qprefix(0, GIG, tfpsbuf, 0);
}

View File

@ -57,7 +57,7 @@ const char *ncmetric(uintmax_t val, uintmax_t decimal, char *buf, int omitdec,
}
int sprintfed;
if(dv != mult){ // if consumed == 0, dv must equal mult
if(val / dv > 0){
if((val / decimal) / dv > 0){
++consumed;
}else{
dv /= mult;

View File

@ -447,4 +447,15 @@ TEST_CASE("Metric") {
CHECK(wcslen(smallsuffixes) * 3 > i);
}
// inspired by #929
SUBCASE("BigMult") {
char qbuf[IPREFIXSTRLEN + 1];
CHECK(nullptr != qprefix(1115614, 1000, qbuf, '\0'));
CHECK(0 == strcmp("1.11K", qbuf));
CHECK(nullptr != iprefix(372688, 1024, qbuf, '\0'));
CHECK(0 == strcmp("363.95", qbuf));
CHECK(nullptr != iprefix(372688, 1, qbuf, '\0'));
CHECK(0 == strcmp("363.95K", qbuf));
}
}