Skip to content
Snippets Groups Projects
Commit 9d8f4cca authored by AYAZ SELIN-PINAR's avatar AYAZ SELIN-PINAR
Browse files

first demo of test

parent 9d5346fb
Branches
No related merge requests found
#include <stdbool.h>
#include <stdlib.h>
#include <check.h>
#include "treemap.h"
#include "place.h"
#include "split-binary.c"
#include "place.c"
// It checks the process of adding data elements.
START_TEST(test_add_elements)
{
int size = 2;
int current_size = 0;
Data *array = malloc(size * sizeof(Data));
// Add elements to array
add_data(&array, &current_size, &size, 3.0, "Ali");
ck_assert_int_eq(current_size, 1);
ck_assert_double_eq(array[0].number, 3.0);
ck_assert_str_eq(array[0].label, "Ali");
add_data(&array, &current_size, &size, 5.0, "Bob");
ck_assert_int_eq(current_size, 2);
ck_assert_double_eq(array[1].number, 5.0);
ck_assert_str_eq(array[1].label, "Bob");
add_data(&array, &current_size, &size, 4.0, "Cai");
ck_assert_int_eq(current_size, 3);
ck_assert_double_eq(array[2].number, 4.0);
ck_assert_str_eq(array[2].label, "Cai");
free(array);
}
END_TEST
// It checks the creation of a tree and verifies if it's built correctly.
START_TEST(test_create_tree)
{
Data array[] = {{3.0, "Ali"}, {5.0, "Bob"}, {4.0, "Cai"}, {2.0, "Dan"}, {6.0, "Eva"}};
TreeNode *root = build_tree(array, 0, 4);
ck_assert(root != NULL);
ck_assert_double_eq(root->sum, 20.0);
ck_assert(root->children[0] != NULL); // Left node !=NULL
ck_assert(root->children[1] != NULL); // Right node !=NULL
free_tree(root);
}
END_TEST
// Test to check assigning boxes to tree nodes
START_TEST(test_assign_boxes)
{
Data array[] = {{3.0, "Ali"}, {5.0, "Bob"}, {4.0, "Cai"}, {2.0, "Dan"}, {6.0, "Eva"}};
TreeNode *root = build_tree(array, 0, 4);
root->box = (Box){0, 0, 1, 1}; // Set the initial box for the root node
place(root, "WNES", 0);
// Check if the boxes are assigned correctly (w non-negative)
ck_assert(root->children[0]->box.w >= 0);
ck_assert(root->children[1]->box.w >= 0);
free_tree(root);
}
END_TEST
Suite *treemap_suite(void)
{
Suite *s = suite_create("Treemap");
TCase *tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_add_elements);
tcase_add_test(tc_core, test_create_tree);
tcase_add_test(tc_core, test_assign_boxes);
suite_add_tcase(s, tc_core);
return s;
}
int main(void)
{
Suite *s = treemap_suite();
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment