mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
添加测试用的数据
This commit is contained in:
parent
5954acb1a0
commit
1bf06756b7
@ -463,11 +463,53 @@ void test_rbtree_struct(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const int const expected_int_array[9][15] = {
|
static const int expected_int_array[9][15] = {
|
||||||
{ 5, 2, 3, 1, 7, 8, 6, 4, 9, 10, 12, 11, 15, 14, 13, }, // original data
|
{ 5, 2, 3, 1, 7, 8, 6, 4, 9, 10, 12, 11, 15, 14, 13}, // original data
|
||||||
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 14, 12, 13, 15, }, // order_left_pre
|
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 14, 12, 13, 15}, // order_left_pre
|
||||||
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, // order_left_in
|
||||||
|
{ 1, 2, 4, 6, 5, 3, 8, 10, 9, 13, 12, 15, 14, 11, 7}, // order_left_post
|
||||||
|
{ 7, 3, 11, 2, 5, 9, 14, 1, 4, 6, 8, 10, 12, 15, 13}, // order_left_breadth
|
||||||
|
{ 7, 11, 14, 15, 12, 13, 9, 10, 8, 3, 5, 6, 4, 2, 1}, // order_right_pre
|
||||||
|
{ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, // order_right_in
|
||||||
|
{ 15, 13, 12, 14, 10, 8, 9, 11, 6, 4, 5, 1, 2, 3, 7}, // order_right_post
|
||||||
|
{ 7, 11, 3, 14, 9, 5, 2, 15, 12, 10, 8, 6, 4, 1, 13}, // order_right_breadth
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int expected_int_array_orderpre_insert[15][15] = {
|
||||||
|
{ 5, },
|
||||||
|
{ 5, 2, },
|
||||||
|
{ 3, 2, 5, },
|
||||||
|
{ 3, 2, 1, 5, },
|
||||||
|
{ 3, 2, 1, 5, 7, },
|
||||||
|
{ 3, 2, 1, 7, 5, 8, },
|
||||||
|
{ 3, 2, 1, 7, 5, 6, 8, },
|
||||||
|
{ 3, 2, 1, 7, 5, 4, 6, 8, },
|
||||||
|
{ 3, 2, 1, 7, 5, 4, 6, 8, 9, },
|
||||||
|
{ 3, 2, 1, 7, 5, 4, 6, 9, 8, 10, },
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 9, 8, 10, 12, },
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 9, 8, 11, 10, 12, },
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 12, 15, },
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 14, 12, 15, },
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int expected_int_array_orderpre_delete[15][15] = {
|
||||||
|
{ 7, 3, 2, 1, 5, 4, 6, 11, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
{ 7, 3, 2, 1, 6, 4, 11, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
{ 7, 3, 1, 6, 4, 11, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
{ 7, 4, 1, 6, 11, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
{ 11, 7, 4, 6, 9, 8, 10, 14, 12, 13, 15, },
|
||||||
|
{ 11, 8, 4, 6, 9, 10, 14, 12, 13, 15, },
|
||||||
|
{ 11, 9, 4, 6, 10, 14, 12, 13, 15, },
|
||||||
|
{ 11, 9, 4, 10, 14, 12, 13, 15, },
|
||||||
|
{ 11, 9, 10, 14, 12, 13, 15, },
|
||||||
|
{ 12, 11, 10, 14, 13, 15, },
|
||||||
|
{ 12, 11, 14, 13, 15, },
|
||||||
|
{ 13, 11, 14, 15, },
|
||||||
|
{ 14, 13, 15, },
|
||||||
|
{ 14, 13, },
|
||||||
|
{ 13, },
|
||||||
|
};
|
||||||
|
|
||||||
static void test_tree_iter(void)
|
static void test_tree_iter(void)
|
||||||
{
|
{
|
||||||
@ -478,11 +520,15 @@ static void test_tree_iter(void)
|
|||||||
// int data[] = { 5,2,3,1,7,8,6,4,9,10,12,11,15,14,13 };
|
// int data[] = { 5,2,3,1,7,8,6,4,9,10,12,11,15,14,13 };
|
||||||
int data[15] = { 5, 2, 3, 1, 7, 8, 6, 4, 9, 10, 12, 11, 15, 14, 13, };
|
int data[15] = { 5, 2, 3, 1, 7, 8, 6, 4, 9, 10, 12, 11, 15, 14, 13, };
|
||||||
int buff[32];
|
int buff[32];
|
||||||
int count = 0;
|
|
||||||
int temp = 0;
|
int temp = 0;
|
||||||
uint32_t len = sizeof(data) / sizeof(data[0]);
|
uint32_t len = sizeof(data) / sizeof(data[0]);
|
||||||
|
|
||||||
|
int * iter = NULL;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
tree_t tree = tree_new();
|
tree_t tree = tree_new();
|
||||||
|
TEST_ASSERT_NOT_NULL(tree);
|
||||||
|
|
||||||
tree_avl_init(tree, sizeof(int));
|
tree_avl_init(tree, sizeof(int));
|
||||||
tree->print_obj = print_num;
|
tree->print_obj = print_num;
|
||||||
tree->compare = compare_num;
|
tree->compare = compare_num;
|
||||||
@ -490,28 +536,25 @@ static void test_tree_iter(void)
|
|||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
temp = data[i];
|
temp = data[i];
|
||||||
tree->insert(tree, &temp);
|
TEST_ASSERT_TRUE(tree->insert(tree, &temp));
|
||||||
|
|
||||||
|
for (count = 0, iter = tree->begin(tree); iter != tree->end(tree); iter = tree->next(tree))
|
||||||
|
{
|
||||||
|
buff[count++] = *iter;
|
||||||
|
}
|
||||||
|
TEST_ASSERT_EQUAL_INT_ARRAY(expected_int_array_orderpre_insert[i], buff, count);
|
||||||
|
}
|
||||||
// printf("insert = ");
|
// printf("insert = ");
|
||||||
// tree->print_obj(&temp);
|
// tree->print_obj(&temp);
|
||||||
// printf("size = %2d : ", tree->size(tree));
|
// printf("size = %2d : \n", tree->size(tree));
|
||||||
// tree->preorder(tree, tree->_root);
|
// tree->preorder(tree, tree->_root);
|
||||||
// printf("\n");
|
// printf("\n");
|
||||||
}
|
|
||||||
printf("insert = ");
|
|
||||||
tree->print_obj(&temp);
|
|
||||||
printf("size = %2d : \n", tree->size(tree));
|
|
||||||
tree->preorder(tree, tree->_root);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
|
|
||||||
// set order
|
// set order
|
||||||
tree->order(tree, ORDER_LEFT_PRE);
|
tree->set_order(tree, ORDER_LEFT_PRE);
|
||||||
// tree->set_order(tree, ORDER_LEFT_IN);
|
// tree->set_order(tree, ORDER_LEFT_IN);
|
||||||
|
printf("\n ----- iter test -----\n");
|
||||||
printf("\niter test\n");
|
for (count = 0, iter = tree->begin(tree); iter != tree->end(tree); iter = tree->next(tree))
|
||||||
int * iter = NULL;
|
|
||||||
for(iter = tree->begin(tree); iter != tree->end(tree); iter = tree->next(tree))
|
|
||||||
{
|
{
|
||||||
printf("(%2d ) ", *iter);
|
printf("(%2d ) ", *iter);
|
||||||
buff[count++] = *iter;
|
buff[count++] = *iter;
|
||||||
|
Loading…
Reference in New Issue
Block a user