plot: AugmentSample5 test case

pull/434/head
nick black 4 years ago committed by Nick Black
parent e8a4badf8b
commit a3f7dd486b

@ -2530,6 +2530,7 @@ typedef struct ncplot_options {
// independent variable can either be a contiguous range, or a finite set
// of keys. for a time range, say the previous hour sampled with second
// resolution, the independent variable would be the range [0..3600): 3600.
// if rangex is 0, it is dynamically set to the number of columns.
uint64_t rangex;
// y axis min and max. for autodiscovery, these both must be equal to 0,
// and detectdomain must be additionally be set.

@ -8,9 +8,6 @@ ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){
if(opts->maxy < opts->miny){
return NULL;
}
if(opts->rangex == 0){
return NULL;
}
int sdimy, sdimx;
ncplane_dim_yx(n, &sdimy, &sdimx);
if(sdimx <= 0){
@ -19,8 +16,11 @@ ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){
uint64_t dimx = sdimx;
ncplot* ret = malloc(sizeof(*ret));
if(ret){
ret->slotcount = opts->rangex;
if(dimx < opts->rangex){
if((ret->rangex = opts->rangex) == 0){
ret->rangex = dimx;
}
ret->slotcount = ret->rangex;
if(dimx < ret->rangex){
ret->slotcount = dimx;
}
size_t slotsize = sizeof(*ret->slots) * ret->slotcount;
@ -30,7 +30,6 @@ ncplot* ncplot_create(ncplane* n, const ncplot_options* opts){
ret->ncp = n;
ret->maxchannel = opts->maxchannel;
ret->minchannel = opts->minchannel;
ret->rangex = opts->rangex;
ret->miny = opts->miny;
ret->maxy = opts->maxy;
ret->vertical_indep = opts->vertical_indep;

@ -1,4 +1,5 @@
#include "main.h"
#include "internal.h"
#include <cstring>
#include <iostream>
@ -50,6 +51,33 @@ TEST_CASE("Plot") {
ncplot_destroy(p);
}
// 5-ary slot space without any window movement
SUBCASE("AugmentSamples5"){
ncplot_options popts{};
popts.rangex = 5;
popts.maxy = 10;
popts.miny = 0;
ncplot* p = ncplot_create(n_, &popts);
REQUIRE(p);
CHECK(0 == p->slots[0]);
ncplot_add_sample(p, 0, 1);
CHECK(1 == p->slots[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(3 == p->slots[2]);
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(6 == p->slots[4]);
CHECK(2 == p->slots[0]);
ncplot_destroy(p);
}
CHECK(0 == notcurses_stop(nc_));
CHECK(0 == fclose(outfp_));
}

Loading…
Cancel
Save