libfort/tests/wb_tests/test_table_geometry.c

170 lines
4.6 KiB
C
Raw Permalink Normal View History

2018-03-19 21:07:18 +01:00
#include "tests.h"
#include "table.h"
2018-11-24 21:14:26 +01:00
#include "test_utils.h"
2018-03-19 21:07:18 +01:00
void test_table_sizes(void)
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-11-03 21:50:30 +01:00
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
size_t rows = 0;
size_t cols = 0;
int status = FT_SUCCESS;
WHEN("Table is empty") {
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 0);
assert_true(cols == 0);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert one cell") {
int n = ft_printf_ln(table, "%c", 'c');
2018-03-31 12:33:37 +02:00
assert_true(n == 1);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 1);
assert_true(cols == 1);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert two cells in the next row") {
int n = ft_printf_ln(table, "%c|%c", 'c', 'd');
2018-03-31 12:33:37 +02:00
assert_true(n == 2);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 2);
assert_true(cols == 2);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert five cells in the next row") {
int n = ft_printf_ln(table, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5);
2018-03-31 12:33:37 +02:00
assert_true(n == 5);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 3);
assert_true(cols == 5);
2018-03-19 21:07:18 +01:00
}
ft_destroy_table(table);
}
void test_table_counts(void)
{
ft_table_t *table = ft_create_table();
assert_true(table != NULL);
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
size_t rows = 0;
size_t cols = 0;
int empty = 0;
WHEN("Table is empty") {
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(empty);
assert_true(rows == 0);
assert_true(cols == 0);
}
WHEN("Insert one cell") {
int n = ft_printf(table, "%s", "1");
assert_true(n == 1);
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(!empty);
assert_true(rows == 1);
assert_true(cols == 1);
}
WHEN("Insert two cells in the same row") {
int n = ft_printf_ln(table, "%s|%s", "2", "3");
assert_true(n == 2);
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(!empty);
assert_true(rows == 1);
assert_true(cols == 3);
}
WHEN("Insert one cell in the next row") {
int status = ft_write(table, "hello");
assert_true(FT_IS_SUCCESS(status));
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(!empty);
assert_true(rows == 2);
assert_true(cols == 3);
}
WHEN("Delete first row") {
int status = ft_erase_range(table, 0, 0, 0, DEFAULT_VECTOR_CAPACITY);
assert_true(FT_IS_SUCCESS(status));
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(!empty);
assert_true(rows == 1);
assert_true(cols == 1);
}
WHEN("Delete second/last row") {
int status = ft_erase_range(table, 0, 0, 0, DEFAULT_VECTOR_CAPACITY);
assert_true(FT_IS_SUCCESS(status));
empty = ft_is_empty(table);
rows = ft_row_count(table);
cols = ft_col_count(table);
assert_true(empty);
assert_true(rows == 0);
assert_true(cols == 0);
}
ft_destroy_table(table);
}
2018-03-19 21:07:18 +01:00
void test_table_geometry(void)
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-11-03 21:50:30 +01:00
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
size_t height = 0;
size_t width = 0;
int status = FT_SUCCESS;
WHEN("Table is empty") {
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 2);
assert_true(width == 3);
2018-03-19 21:07:18 +01:00
}
WHEN("Table has one cell") {
int n = ft_printf_ln(table, "%c", 'c');
2018-03-31 12:33:37 +02:00
assert_true(n == 1);
2018-03-19 21:07:18 +01:00
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 5);
assert_true(width == 6);
2018-03-19 21:07:18 +01:00
}
WHEN("Inserting 3 cells in the next row") {
int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e');
2018-03-31 12:33:37 +02:00
assert_true(n == 3);
2018-03-19 21:07:18 +01:00
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 9);
assert_true(width == 15);
2018-03-19 21:07:18 +01:00
}
ft_destroy_table(table);
}