From d03cb95135eae338d8fa864f05325cd5cd5eb7e6 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 21 Jan 2025 09:54:43 -0500 Subject: feat: testing printing cpu core functionality and graphing behavior --- graphtest.c | 41 +++++++++++++++++++++++++++++++++++++++++ squaretest.c | 7 +++++++ 2 files changed, 48 insertions(+) create mode 100644 graphtest.c create mode 100644 squaretest.c diff --git a/graphtest.c b/graphtest.c new file mode 100644 index 0000000..7f6e825 --- /dev/null +++ b/graphtest.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +char* rightshift(char* data, size_t size) { + char* res = malloc(size * sizeof(char)); + *res = ' '; + memcpy(res + 1, data, size - 1); + free(data); + return res; +} + +// Graph with have a height of 10 characters and width of 12 +int printgraph(int max, int inuse, char** graphdata, char prog, char* yaxis, char* xaxis) { + float percentage = ((float)inuse)/((float) max); + int percent = floorf(percentage * 10); + printf("%d\n", percent); + for (int i = 9; i > 0; i--) { + graphdata[i] = rightshift(graphdata[i], 12); + if (percent == i) { + graphdata[i][0] = '#'; + } + printf("%s\n", graphdata[i]); + } + printf("End of graph\n"); + return 0; +} + +int main() { + int max = 50; + int arr[] = {12, 32, 40, 30, 20, 50, 10, 30}; + char** data = malloc(10 * sizeof(char*)); + for (int i = 0; i < 10; i++) { + *(data+i) = malloc(12 * sizeof(char)); + strcpy(*(data + i), " "); + } + for (int i = 0; i < 8; i++) { + printgraph(max, arr[i], data, '#', "y", "x"); + } +} diff --git a/squaretest.c b/squaretest.c new file mode 100644 index 0000000..e518fe9 --- /dev/null +++ b/squaretest.c @@ -0,0 +1,7 @@ +#include + +int main() { + for (int i = 0; i < 10; i++) { + printf("+---+\n| |\n+---+"); + } +} -- cgit v1.2.3