skip to content
==> tests/sparkline.c <==
1/* Bars in eighths, scaled to the largest value or to max, bottom up. */
2#include "mesh/check.h"
3#include "tui/sparkline.h"
4
5#include <string.h>
6
7int main(void) {
8    tui_arena a = {0};
9    tui_buffer b;
10    tui_buffer_init(&b, (tui_rect){0, 0, 4, 2});
11    uint64_t data[3] = {0, 8, 16};
12    tui_sparkline s = {.data = data, .n = 3};
13    tui_sparkline_render(&a, &s, b.area, &b);
14    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 2, 0)), "█");
15    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 1, 1)), "█");
16    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 1, 0)), " ");
17    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 0, 1)), " ");
18    s.has_max = true;
19    s.max = 64;
20    tui_sparkline_render(&a, &s, b.area, &b);
21    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 2, 1)), "▄");
22    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 1, 1)), "▂");
23    uint64_t huge[1] = {UINT64_MAX};
24    tui_sparkline h = {.data = huge, .n = 1, .has_max = true, .max = 3};
25    tui_sparkline_render(&a, &h, b.area, &b);
26    CHECK_S(tui_cell_symbol(tui_buffer_cell(&b, 0, 0)), "█");
27    tui_buffer_free(&b);
28    tui_arena_free(&a);
29    return mesh_check_done();
30}