Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_144 - B+ Tree Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_144 - B+ Tree Project
Commits
637147ea
Commit
637147ea
authored
2 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests
parent
172741e8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/BPTree.c
+15
-3
15 additions, 3 deletions
src/BPTree.c
src/tests/BPTreeTests.c
+26
-11
26 additions, 11 deletions
src/tests/BPTreeTests.c
with
41 additions
and
14 deletions
src/BPTree.c
+
15
−
3
View file @
637147ea
...
...
@@ -53,14 +53,24 @@ void BPTree_print(BPTreeNode *root, int depth) {
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
{
printf
(
" "
);
}
printf
(
"%p
\n
"
,
(
void
*
)
root
);
for
(
int
i
=
0
;
i
<
depth
+
1
;
i
++
)
{
printf
(
" "
);
}
IntegerArray_print
(
root
->
keys
);
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
{
for
(
int
i
=
0
;
i
<
depth
+
1
;
i
++
)
{
printf
(
" "
);
}
printf
(
" "
);
printf
(
"
Data =
"
);
IntegerArray_print
(
root
->
data
);
for
(
int
i
=
0
;
i
<
depth
+
1
;
i
++
)
{
printf
(
" "
);
}
printf
(
"Next = %p
\n
"
,
(
void
*
)
root
->
next
);
for
(
int
i
=
0
;
i
<
root
->
children
->
size
;
i
++
)
{
BPTree_print
(
root
->
children
->
items
[
i
],
depth
+
1
);
}
...
...
@@ -205,8 +215,10 @@ static uint64_t insert_full(BPTreeNode *node, uint64_t key, uint64_t data, BPTre
}
static
void
grow
(
BPTreeNode
*
root
,
uint64_t
median_value
,
BPTreeNode
*
split_right_node
)
{
BPTreeNode
*
left_node
=
BPTreeNode_init
(
root
->
order
,
split_right_node
->
is_leaf
);
root
->
is_leaf
=
false
;
BPTreeNode
*
left_node
=
BPTreeNode_init
(
root
->
order
,
split_right_node
->
is_leaf
);
left_node
->
next
=
root
->
next
;
root
->
next
=
NULL
;
IntegerArray_copy
(
root
->
keys
,
left_node
->
keys
);
IntegerArray_copy
(
root
->
data
,
left_node
->
data
);
...
...
This diff is collapsed.
Click to expand it.
src/tests/BPTreeTests.c
+
26
−
11
View file @
637147ea
...
...
@@ -22,8 +22,14 @@ void setUp() {
void
tearDown
()
{
}
// BEGIN : Functions that check that a B+
T
ree is compliant with the rules
// BEGIN : Functions that check that a B+
t
ree is compliant with the
B+ Tree
rules
.
/**
* @brief Finds the leftmost leaf node.
*
* @param root The root node.
* @return BPTreeNode* The leftmost leaf node.
*/
static
BPTreeNode
*
find_first_leaf
(
BPTreeNode
*
root
)
{
if
(
root
->
is_leaf
)
{
return
root
;
...
...
@@ -234,15 +240,15 @@ static bool check_BPTree_compliance(BPTreeNode *root) {
return
is_compliant
;
}
// END : Functions that check that a B+
T
ree is compliant with the rules
// END : Functions that check that a B+
t
ree is compliant with the
B+ Tree
rules
.
/**
* @brief
Performs a linear search for an item in an
array.
* @brief
Checks if an item is present in the
array.
*
* @param array The array in which the
search is to be perform
ed.
* @param item The
item searched for
.
* @param array The array in which the
item is search
ed.
* @param item The
sought-after item
.
* @return true The item has been found.
* @return false The item
w
as not found.
* @return false The item
h
as not
been
found.
*/
static
bool
IntegerArray_search
(
IntegerArray
*
array
,
uint64_t
item
)
{
for
(
int
i
=
0
;
i
<
array
->
size
;
i
++
)
{
...
...
@@ -257,10 +263,10 @@ static bool IntegerArray_search(IntegerArray *array, uint64_t item) {
/**
* @brief Generates an array of random numbers.
*
* @param size The number of numbers to generate.
* @param size The number of
random
numbers to generate.
* @param random_min The smallest random value.
* @param random_max The greatest random value.
* @return IntegerArray* The random number
array
.
* @return IntegerArray* The
generated array filled with
random number
s
.
*/
static
IntegerArray
*
generate_random_numbers_array
(
int
size
,
int
random_min
,
int
random_max
)
{
IntegerArray
*
array
=
IntegerArray_init
(
size
);
...
...
@@ -279,6 +285,12 @@ static IntegerArray *generate_random_numbers_array(int size, int random_min, int
return
array
;
}
/**
* @brief Transforms a key into data, this function allows to make a kind of hash to check the relation between a key and a data.
*
* @param key The key to transform.
* @return uint64_t The key transformed into data.
*/
static
uint64_t
transform_key_to_data
(
uint64_t
key
)
{
return
key
*
10000
;
}
...
...
@@ -302,7 +314,7 @@ static void test_BPTree_insert_should_comply_with_BPTree_rules_using_BPTree_of_g
for
(
int
i
=
0
;
i
<
keys
->
size
;
i
++
)
{
BPTree_insert
(
root
,
keys
->
items
[
i
],
transform_key_to_data
(
keys
->
items
[
i
]));
// After each insertion
is verified
that the B+
T
ree is compliant with the rules.
// After each insertion
, we check
that the B+
t
ree is compliant with the
B+ Tree
rules.
TEST_ASSERT
(
check_BPTree_compliance
(
root
));
}
...
...
@@ -348,12 +360,12 @@ void test_BPTree_delete_should_comply_with_BPTree_rules_using_BPTree_of_given_or
int
size
=
1
;
// Test 10 times, variable i being the seed.
for
(
int
i
=
0
;
i
<
1
0
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
srand
(
i
);
// Test with seed "i" 8 array size, at each end of loop the size variable is multiplied by 2, the array of random keys
// will have the size of 1 then 2, 4, 8, 16, 32, ...
for
(
int
j
=
0
;
j
<
8
;
j
++
)
{
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
IntegerArray
*
keys
=
generate_random_numbers_array
(
size
,
RANDOM_MIN
,
RANDOM_MAX
);
BPTreeNode
*
root
=
BPTree_init
(
order
);
...
...
@@ -364,6 +376,8 @@ void test_BPTree_delete_should_comply_with_BPTree_rules_using_BPTree_of_given_or
while
(
keys
->
size
>
0
)
{
int
index
=
rand
()
%
keys
->
size
;
BPTree_delete
(
root
,
keys
->
items
[
index
]);
// After each deletion, we check that the B+ tree conforms to the B+ Tree rules.
TEST_ASSERT
(
check_BPTree_compliance
(
root
));
IntegerArray_delete_at_index
(
keys
,
index
);
}
...
...
@@ -423,6 +437,7 @@ void test_BPTree_search_should_find_the_keys_that_exist_in_the_BPTree_using_BPTr
uint64_t
data
;
bool
is_found
=
BPTree_search
(
root
,
keys
->
items
[
i
],
&
data
);
// After each search, we check that the key has been found and that the relationship between it and the data is correct.
TEST_ASSERT
(
is_found
);
TEST_ASSERT_EQUAL_UINT64
(
transform_key_to_data
(
keys
->
items
[
i
]),
data
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment