2020-04-01 10:56:34 +00:00
|
|
|
#include "main.h"
|
2020-04-23 07:52:07 +00:00
|
|
|
#include "cpp.h"
|
2020-04-01 10:56:34 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
TEST_CASE("Plot") {
|
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.inhibit_alternate_screen = true;
|
|
|
|
nopts.suppress_banner = true;
|
2020-04-23 07:52:07 +00:00
|
|
|
auto outfp_ = fopen("/dev/tty", "wb");
|
2020-04-01 10:56:34 +00:00
|
|
|
REQUIRE(outfp_);
|
2020-04-23 07:52:07 +00:00
|
|
|
auto nc_ = notcurses_init(&nopts, outfp_);
|
2020-04-01 10:56:34 +00:00
|
|
|
REQUIRE(nc_);
|
2020-04-23 07:52:07 +00:00
|
|
|
auto n_ = notcurses_stdplane(nc_);
|
2020-04-01 10:56:34 +00:00
|
|
|
REQUIRE(n_);
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
2020-04-04 12:56:31 +00:00
|
|
|
// setting miny == maxy with non-zero domain limits is invalid
|
2020-04-03 05:25:49 +00:00
|
|
|
SUBCASE("DetectRangeBadY"){
|
|
|
|
ncplot_options popts{};
|
2020-04-23 07:52:07 +00:00
|
|
|
auto p = ncuplot_create(n_, &popts, -1, -1);
|
2020-04-03 05:25:49 +00:00
|
|
|
CHECK(nullptr == p);
|
2020-04-23 07:52:07 +00:00
|
|
|
p = ncuplot_create(n_, &popts, 1, 1);
|
2020-04-03 05:25:49 +00:00
|
|
|
CHECK(nullptr == p);
|
2020-04-23 07:52:07 +00:00
|
|
|
p = ncuplot_create(n_, &popts, 0, 0);
|
2020-04-04 12:56:31 +00:00
|
|
|
REQUIRE(nullptr != p);
|
2020-04-23 07:52:07 +00:00
|
|
|
ncuplot_destroy(p);
|
2020-04-03 05:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// maxy < miny is invalid
|
|
|
|
SUBCASE("RejectMaxyLessMiny"){
|
|
|
|
ncplot_options popts{};
|
2020-04-23 07:52:07 +00:00
|
|
|
auto p = ncuplot_create(n_, &popts, 2, 1);
|
2020-04-03 05:25:49 +00:00
|
|
|
CHECK(nullptr == p);
|
|
|
|
}
|
|
|
|
|
2020-04-01 10:56:34 +00:00
|
|
|
SUBCASE("SimplePlot"){
|
|
|
|
ncplot_options popts{};
|
2020-04-23 07:52:07 +00:00
|
|
|
auto p = ncuplot_create(n_, &popts, 0, 0);
|
2020-04-01 10:56:34 +00:00
|
|
|
REQUIRE(p);
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(n_ == ncuplot_plane(p));
|
|
|
|
ncuplot_destroy(p);
|
2020-04-01 10:56:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 08:47:34 +00:00
|
|
|
// 5-ary slot space without any window movement
|
|
|
|
SUBCASE("AugmentSamples5"){
|
|
|
|
ncplot_options popts{};
|
|
|
|
popts.rangex = 5;
|
2020-04-23 07:52:07 +00:00
|
|
|
ncppplot<uint64_t> p;
|
|
|
|
ncppplot<uint64_t>::create(&p, n_, &popts, 0, 10);
|
|
|
|
CHECK(0 == p.slots[0]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)0, (uint64_t)1));
|
|
|
|
CHECK(1 == p.slots[0]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)0, (uint64_t)1));
|
|
|
|
CHECK(2 == p.slots[0]);
|
|
|
|
CHECK(0 == p.slots[1]);
|
|
|
|
CHECK(0 == p.slots[2]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)2, (uint64_t)3));
|
|
|
|
CHECK(3 == p.slots[2]);
|
|
|
|
CHECK(0 == p.set_sample((uint64_t)2, (uint64_t)3));
|
|
|
|
CHECK(3 == p.slots[2]);
|
|
|
|
CHECK(0 == p.slots[3]);
|
|
|
|
CHECK(0 == p.slots[4]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)4, (uint64_t)6));
|
|
|
|
CHECK(6 == p.slots[4]);
|
|
|
|
CHECK(2 == p.slots[0]);
|
|
|
|
CHECK(4 == p.slotx);
|
|
|
|
p.destroy();
|
2020-04-03 08:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2-ary slot space with window movement
|
|
|
|
SUBCASE("AugmentCycle2"){
|
|
|
|
ncplot_options popts{};
|
|
|
|
popts.rangex = 2;
|
2020-04-23 07:52:07 +00:00
|
|
|
ncppplot<uint64_t> p;
|
|
|
|
ncppplot<uint64_t>::create(&p, n_, &popts, 0, 10);
|
|
|
|
CHECK(0 == p.slots[0]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)0, (uint64_t)1));
|
|
|
|
CHECK(1 == p.slots[0]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)0, (uint64_t)1));
|
|
|
|
CHECK(2 == p.slots[0]);
|
|
|
|
CHECK(0 == p.set_sample((uint64_t)1, (uint64_t)5));
|
|
|
|
CHECK(5 == p.slots[1]);
|
|
|
|
CHECK(0 == p.set_sample((uint64_t)2, (uint64_t)9));
|
|
|
|
CHECK(5 == p.slots[1]);
|
|
|
|
CHECK(9 == p.slots[0]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)3, (uint64_t)4));
|
|
|
|
CHECK(9 == p.slots[0]);
|
|
|
|
CHECK(4 == p.slots[1]);
|
|
|
|
CHECK(3 == p.slotx);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)5, (uint64_t)1));
|
|
|
|
CHECK(1 == p.slots[0]);
|
|
|
|
CHECK(0 == p.slots[1]);
|
|
|
|
CHECK(5 == p.slotx);
|
|
|
|
p.destroy();
|
2020-04-03 08:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 10:15:43 +00:00
|
|
|
// augment past the window, ensuring everything gets zeroed
|
|
|
|
SUBCASE("AugmentLong"){
|
|
|
|
ncplot_options popts{};
|
|
|
|
popts.rangex = 5;
|
2020-04-23 07:52:07 +00:00
|
|
|
ncppplot<uint64_t> p;
|
|
|
|
ncppplot<uint64_t>::create(&p, n_, &popts, 0, 10);
|
2020-04-03 10:15:43 +00:00
|
|
|
for(int x = 0 ; x < 5 ; ++x){
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.slots[x]);
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.add_sample((uint64_t)4, (uint64_t)4));
|
2020-04-03 10:15:43 +00:00
|
|
|
for(int x = 0 ; x < 4 ; ++x){
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.slots[x]);
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(4 == p.slots[4]);
|
|
|
|
CHECK(0 == p.add_sample((uint64_t)10, (uint64_t)5));
|
|
|
|
CHECK(5 == p.slots[0]);
|
2020-04-03 10:15:43 +00:00
|
|
|
for(int x = 1 ; x < 4 ; ++x){
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.slots[x]);
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.add_sample((uint64_t)24, (uint64_t)7));
|
|
|
|
CHECK(7 == p.slots[0]);
|
2020-04-10 15:22:26 +00:00
|
|
|
for(int x = 1 ; x < 5 ; ++x){
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.slots[x]);
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.add_sample((uint64_t)100, (uint64_t)0));
|
2020-04-03 10:15:43 +00:00
|
|
|
for(int x = 0 ; x < 5 ; ++x){
|
2020-04-23 07:52:07 +00:00
|
|
|
CHECK(0 == p.slots[x]);
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
2020-04-23 07:52:07 +00:00
|
|
|
p.destroy();
|
2020-04-03 10:15:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 07:52:07 +00:00
|
|
|
// FIXME need some high-level rendering tests, one for each geometry
|
|
|
|
|
|
|
|
SUBCASE("SimpleFloatPlot"){
|
|
|
|
ncplot_options popts{};
|
|
|
|
auto p = ncdplot_create(n_, &popts, 0, 0);
|
|
|
|
REQUIRE(p);
|
|
|
|
CHECK(n_ == ncdplot_plane(p));
|
|
|
|
ncdplot_destroy(p);
|
|
|
|
}
|
2020-04-16 09:33:10 +00:00
|
|
|
|
2020-04-01 10:56:34 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
CHECK(0 == fclose(outfp_));
|
|
|
|
}
|