TU-Programmieren_2/lab3/modules/iue-io/ccsv.test.c
2025-04-09 10:22:44 +02:00

63 lines
1.3 KiB
C

#include "iue-io/ccsv.h"
#include <assert.h> // assert
#include <stddef.h> // size_t
int main(void) {
// prep input data
struct Table table1 = {NULL, 0};
{
double data[3] = {1, 2, 3};
table_append_copy(&table1, data, 3);
}
{
double data[4] = {10, 20, 30, 40};
table_append_copy(&table1, data, 4);
}
{
double data[4] = {1e3, 2e3, 3e3, 4e3};
table_append_copy(&table1, data, 4);
}
{ // write
int res = iueio_savetxt("ccsv_test.csv", &table1, ';', "this is a multiline \n header comment", '#');
if (res != EXIT_SUCCESS)
return EXIT_FAILURE;
}
struct Table table2 = {NULL, 0};
{ // read
int res = iueio_loadtxt("ccsv_test.csv", &table2, ';', '#');
if (res != EXIT_SUCCESS)
return EXIT_FAILURE;
for (size_t i = 0; i != table2.n; ++i) {
for (size_t j = 0; j != table2.rows[i].n; ++j)
printf("%lf ", table2.rows[i].values[j]);
printf("\n");
}
}
// compare
assert(table1.n == table2.n);
for (size_t r = 0; r != table1.n; ++r) {
assert(table1.rows[r].n == table2.rows[r].n);
for (size_t c = 0; c != table1.rows[r].n; ++c) {
assert(table1.rows[r].values[c] == table2.rows[r].values[c]);
}
}
table_clear(&table1);
table_clear(&table2);
return EXIT_SUCCESS;
}