plot: fix off-by-one on wide window shift, asdd unit test

pull/435/head
nick black 4 years ago committed by Nick Black
parent 8a23124c4a
commit 6b74ea7718

@ -101,8 +101,8 @@ window_slide(ncplot* n, uint64_t x){
// x must be within n's window
static inline void
update_sample(ncplot* n, uint64_t x, int64_t y, bool reset){
uint64_t delta = x - n->slotx;
uint64_t idx = (n->slotstart + delta) % n->slotcount;
uint64_t idx = x/*(n->slotstart + delta)*/ % n->slotcount;
fprintf(stderr, "WRITING %jd to IFX %ju (DELTA: %ju, SLOTX: %ju)\n", y, idx, 0, n->slotx);
if(reset){
n->slots[idx] = y;
}else{

@ -60,19 +60,19 @@ TEST_CASE("Plot") {
ncplot* p = ncplot_create(n_, &popts);
REQUIRE(p);
CHECK(0 == p->slots[0]);
ncplot_add_sample(p, 0, 1);
CHECK(0 == ncplot_add_sample(p, 0, 1));
CHECK(1 == p->slots[0]);
ncplot_add_sample(p, 0, 1);
CHECK(0 == ncplot_add_sample(p, 0, 1));
CHECK(2 == p->slots[0]);
CHECK(0 == p->slots[1]);
CHECK(0 == p->slots[2]);
ncplot_add_sample(p, 2, 3);
CHECK(0 == ncplot_add_sample(p, 2, 3));
CHECK(3 == p->slots[2]);
ncplot_set_sample(p, 2, 3);
CHECK(0 == ncplot_set_sample(p, 2, 3));
CHECK(3 == p->slots[2]);
CHECK(0 == p->slots[3]);
CHECK(0 == p->slots[4]);
ncplot_add_sample(p, 4, 6);
CHECK(0 == ncplot_add_sample(p, 4, 6));
CHECK(6 == p->slots[4]);
CHECK(2 == p->slots[0]);
CHECK(0 == p->slotx);
@ -88,26 +88,61 @@ TEST_CASE("Plot") {
ncplot* p = ncplot_create(n_, &popts);
REQUIRE(p);
CHECK(0 == p->slots[0]);
ncplot_add_sample(p, 0, 1);
CHECK(0 == ncplot_add_sample(p, 0, 1));
CHECK(1 == p->slots[0]);
ncplot_add_sample(p, 0, 1);
CHECK(0 == ncplot_add_sample(p, 0, 1));
CHECK(2 == p->slots[0]);
ncplot_set_sample(p, 1, 5);
CHECK(0 == ncplot_set_sample(p, 1, 5));
CHECK(5 == p->slots[1]);
ncplot_set_sample(p, 2, 9);
CHECK(0 == ncplot_set_sample(p, 2, 9));
CHECK(5 == p->slots[1]);
CHECK(9 == p->slots[0]);
ncplot_add_sample(p, 3, 4);
CHECK(0 == ncplot_add_sample(p, 3, 4));
CHECK(9 == p->slots[0]);
CHECK(4 == p->slots[1]);
CHECK(2 == p->slotx);
ncplot_add_sample(p, 5, 1);
CHECK(0 == ncplot_add_sample(p, 5, 1));
CHECK(0 == p->slots[0]);
CHECK(1 == p->slots[1]);
CHECK(4 == p->slotx);
ncplot_destroy(p);
}
// augment past the window, ensuring everything gets zeroed
SUBCASE("AugmentLong"){
ncplot_options popts{};
popts.rangex = 5;
popts.maxy = 10;
popts.miny = 0;
ncplot* p = ncplot_create(n_, &popts);
REQUIRE(p);
for(int x = 0 ; x < 5 ; ++x){
CHECK(0 == p->slots[x]);
}
CHECK(0 == ncplot_add_sample(p, 4, 4));
for(int x = 0 ; x < 4 ; ++x){
CHECK(0 == p->slots[x]);
}
CHECK(4 == p->slots[4]);
CHECK(0 == ncplot_add_sample(p, 10, 5));
fprintf(stderr, "SLOT 0: %ju\n", p->slots[0]);
CHECK(5 == p->slots[0]);
for(int x = 1 ; x < 4 ; ++x){
fprintf(stderr, "SLOT %d: %ju\n", x, p->slots[x]);
CHECK(0 == p->slots[x]);
}
CHECK(0 == ncplot_add_sample(p, 24, 7));
for(int x = 0 ; x < 4 ; ++x){
CHECK(0 == p->slots[x]);
}
CHECK(7 == p->slots[4]);
CHECK(0 == ncplot_add_sample(p, 100, 0));
for(int x = 0 ; x < 5 ; ++x){
CHECK(0 == p->slots[x]);
}
ncplot_destroy(p);
}
CHECK(0 == notcurses_stop(nc_));
CHECK(0 == fclose(outfp_));
}

Loading…
Cancel
Save