[A] Added adding_strategy
property to the tables
This commit is contained in:
@@ -1608,8 +1608,95 @@ void test_table_write(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
SCENARIO("Test write and printf functions simultaneously") {
|
||||
table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "0", "1")));
|
||||
assert_true(FT_IS_SUCCESS(ft_printf(table, "2|3")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "5", "6")));
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---+---+---+---+---+---+\n"
|
||||
"| 0 | 1 | 2 | 3 | 5 | 6 |\n"
|
||||
"+---+---+---+---+---+---+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
||||
|
||||
void test_table_insert_strategy(void)
|
||||
{
|
||||
SCENARIO("Test ft_ln") {
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
ft_set_tbl_prop(table, FT_TPROP_ADDING_STRATEGY, FT_STRATEGY_INSERT);
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "0", "1", "2")));
|
||||
ft_set_cur_cell(table, 0, 2);
|
||||
assert_true(FT_IS_SUCCESS(ft_ln(table)));
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---+---+\n"
|
||||
"| 0 | 1 |\n"
|
||||
"| 2 | 3 |\n"
|
||||
"+---+---+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
SCENARIO("Test write functions") {
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
ft_set_tbl_prop(table, FT_TPROP_ADDING_STRATEGY, FT_STRATEGY_INSERT);
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "0", "1", "2", "4", "5")));
|
||||
ft_set_cur_cell(table, 0, 2);
|
||||
assert_true(FT_IS_SUCCESS(ft_ln(table)));
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "3")));
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---+---+\n"
|
||||
"| 0 | 1 |\n"
|
||||
"| 2 | 3 |\n"
|
||||
"| 4 | 5 |\n"
|
||||
"+---+---+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
SCENARIO("Test printf functions") {
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
ft_set_tbl_prop(table, FT_TPROP_ADDING_STRATEGY, FT_STRATEGY_INSERT);
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "0", "1", "2", "5", "6")));
|
||||
ft_set_cur_cell(table, 0, 2);
|
||||
assert_true(FT_IS_SUCCESS(ft_ln(table)));
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(FT_IS_SUCCESS(ft_printf_ln(table, "3|4")));
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---+---+---+\n"
|
||||
"| 0 | 1 | |\n"
|
||||
"| 2 | 3 | 4 |\n"
|
||||
"| 5 | 6 | |\n"
|
||||
"+---+---+---+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
||||
|
||||
void test_table_copy(void)
|
||||
{
|
||||
|
@@ -300,6 +300,52 @@ void test_cpp_table_write(void)
|
||||
}
|
||||
}
|
||||
|
||||
void test_cpp_table_insert(void)
|
||||
{
|
||||
SCENARIO("Test insert into beginning") {
|
||||
fort::char_table table;
|
||||
table.set_adding_strategy(fort::add_strategy::insert);
|
||||
table.set_border_style(FT_BOLD_STYLE);
|
||||
table << "val1" << "val2" << fort::endr
|
||||
<< "val3" << "val4" << fort::endr;
|
||||
|
||||
table.set_cur_cell(0, 0);
|
||||
table << fort::header
|
||||
<< "hdr1" << "hdr2" << fort::endr;
|
||||
|
||||
std::string table_str = table.to_string();
|
||||
std::string table_str_etalon =
|
||||
"┏━━━━━━┳━━━━━━┓\n"
|
||||
"┃ hdr1 ┃ hdr2 ┃\n"
|
||||
"┣━━━━━━╋━━━━━━┫\n"
|
||||
"┃ val1 ┃ val2 ┃\n"
|
||||
"┃ val3 ┃ val4 ┃\n"
|
||||
"┗━━━━━━┻━━━━━━┛\n";
|
||||
assert_string_equal(table_str, table_str_etalon);
|
||||
}
|
||||
|
||||
SCENARIO("Test insert into the middle") {
|
||||
fort::char_table table;
|
||||
table.set_adding_strategy(fort::add_strategy::insert);
|
||||
table.set_border_style(FT_BOLD_STYLE);
|
||||
table << fort::header << "hdr1" << "hdr2" << fort::endr
|
||||
<< "val1" << "val4" << fort::endr;
|
||||
|
||||
table.set_cur_cell(1, 1);
|
||||
table << "val2" << fort::endr << "val3";
|
||||
|
||||
std::string table_str = table.to_string();
|
||||
std::string table_str_etalon =
|
||||
"┏━━━━━━┳━━━━━━┓\n"
|
||||
"┃ hdr1 ┃ hdr2 ┃\n"
|
||||
"┣━━━━━━╋━━━━━━┫\n"
|
||||
"┃ val1 ┃ val2 ┃\n"
|
||||
"┃ val3 ┃ val4 ┃\n"
|
||||
"┗━━━━━━┻━━━━━━┛\n";
|
||||
assert_string_equal(table_str, table_str_etalon);
|
||||
}
|
||||
}
|
||||
|
||||
void test_cpp_table_changing_cell(void)
|
||||
{
|
||||
WHEN("All columns are equal and not empty") {
|
||||
|
@@ -16,6 +16,7 @@ void test_table_changing_cell(void);
|
||||
void test_wcs_table_boundaries(void);
|
||||
#endif
|
||||
void test_table_write(void);
|
||||
void test_table_insert_strategy(void);
|
||||
void test_table_border_style(void);
|
||||
void test_table_builtin_border_styles(void);
|
||||
void test_table_cell_properties(void);
|
||||
@@ -49,6 +50,7 @@ struct test_case bb_test_suite [] = {
|
||||
{"test_utf8_table", test_utf8_table},
|
||||
#endif
|
||||
{"test_table_write", test_table_write},
|
||||
{"test_table_insert_strategy", test_table_insert_strategy},
|
||||
{"test_table_changing_cell", test_table_changing_cell},
|
||||
{"test_table_border_style", test_table_border_style},
|
||||
{"test_table_builtin_border_styles", test_table_builtin_border_styles},
|
||||
|
@@ -5,6 +5,7 @@
|
||||
/* Test cases */
|
||||
void test_cpp_table_basic(void);
|
||||
void test_cpp_table_write(void);
|
||||
void test_cpp_table_insert(void);
|
||||
void test_cpp_table_changing_cell(void);
|
||||
void test_cpp_table_tbl_properties(void);
|
||||
void test_cpp_table_cell_properties(void);
|
||||
@@ -15,6 +16,7 @@ void test_cpp_bug_fixes(void);
|
||||
struct test_case bb_test_suite [] = {
|
||||
{"test_cpp_table_basic", test_cpp_table_basic},
|
||||
{"test_cpp_table_write", test_cpp_table_write},
|
||||
{"test_cpp_table_insert", test_cpp_table_insert},
|
||||
{"test_cpp_table_changing_cell", test_cpp_table_changing_cell},
|
||||
{"test_cpp_table_tbl_properties", test_cpp_table_tbl_properties},
|
||||
{"test_cpp_table_cell_properties", test_cpp_table_cell_properties},
|
||||
|
@@ -87,6 +87,30 @@ void test_vector_basic(void)
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Testing insert method vector") {
|
||||
vector_clear(vector);
|
||||
|
||||
size_t capacity = 10 * init_capacity;
|
||||
for (i = 0; i < capacity; ++i) {
|
||||
item_t item = (item_t)i;
|
||||
vector_insert(vector, &item, 0);
|
||||
}
|
||||
assert_true(vector_size(vector) == capacity);
|
||||
for (i = 0; i < capacity; ++i) {
|
||||
assert_true(*(item_t *)vector_at(vector, i) == (item_t)(capacity - i) - 1);
|
||||
}
|
||||
|
||||
item_t item_666 = 666;
|
||||
vector_insert(vector, &item_666, 5 * capacity - 1);
|
||||
assert_true(vector_size(vector) == 5 * capacity);
|
||||
assert_true(*(item_t *)vector_at(vector, 5 * capacity - 1) == item_666);
|
||||
|
||||
item_t item_777 = 777;
|
||||
vector_insert(vector, &item_777, 10);
|
||||
assert_true(vector_size(vector) == 5 * capacity + 1);
|
||||
assert_true(*(item_t *)vector_at(vector, 10) == item_777);
|
||||
}
|
||||
|
||||
WHEN("Moving from another vector") {
|
||||
vector_clear(vector);
|
||||
for (i = 0; i < 10; ++i) {
|
||||
|
Reference in New Issue
Block a user