Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advanced systems programming project one
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
Show more breadcrumbs
fork proxy
Advanced systems programming project one
Commits
923fd2e0
Commit
923fd2e0
authored
6 months ago
by
j2-pelczar
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9e485bb8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
worksheet_two/task_2_unit_tests/bump_test.cpp
+56
-0
56 additions, 0 deletions
worksheet_two/task_2_unit_tests/bump_test.cpp
with
56 additions
and
0 deletions
worksheet_two/task_2_unit_tests/bump_test.cpp
0 → 100644
+
56
−
0
View file @
923fd2e0
#include
<iostream>
#include
<cassert>
#include
"bump_allocator.hpp"
void
testBumpAllocator
()
{
std
::
cout
<<
"Running BumpAllocator tests...
\n
"
;
std
::
cout
<<
"---------------------------------
\n
"
;
// Test 1: Create an allocator and allocate some memory
BumpAllocator
allocator
(
1024
);
std
::
cout
<<
"[Test 1] Allocator created with 1024 bytes.
\n
"
;
// Test 2: Allocating memory
int
*
p1
=
allocator
.
alloc
<
int
>
(
10
);
assert
(
p1
!=
nullptr
&&
"Test 2 Failed: Allocation for integers failed!"
);
std
::
cout
<<
"[Test 2] Allocated memory for 10 integers.
\n
"
;
// Test 3: Allocate more memory
double
*
p2
=
allocator
.
alloc
<
double
>
(
5
);
assert
(
p2
!=
nullptr
&&
"Test 3 Failed: Allocation for doubles failed!"
);
std
::
cout
<<
"[Test 3] Allocated memory for 5 doubles.
\n
"
;
// Test 4: Check the status of the allocator
std
::
cout
<<
"[Test 4] Checking allocator status:
\n
"
;
allocator
.
printStatus
();
// Test 5: Deallocate memory partially
allocator
.
dealloc
();
std
::
cout
<<
"[Test 5] Deallocated memory (partial reset).
\n
"
;
allocator
.
printStatus
();
// Test 6: Allocate again after deallocation
int
*
p3
=
allocator
.
alloc
<
int
>
(
20
);
assert
(
p3
!=
nullptr
&&
"Test 6 Failed: Allocation after deallocation failed!"
);
std
::
cout
<<
"[Test 6] Allocated memory for 20 integers after deallocation.
\n
"
;
// Test 7: Exhaust the allocator
int
*
p4
=
allocator
.
alloc
<
int
>
(
1000
);
assert
(
p4
==
nullptr
&&
"Test 7 Failed: Allocator should not allow exceeding capacity!"
);
std
::
cout
<<
"[Test 7] Attempted to allocate beyond capacity (expected failure).
\n
"
;
// Test 8: Completely reset the allocator
allocator
.
dealloc
();
std
::
cout
<<
"[Test 8] Completely reset the allocator.
\n
"
;
allocator
.
printStatus
();
assert
(
allocator
.
alloc
<
int
>
(
128
)
!=
nullptr
&&
"Test 8 Failed: Allocator should work after reset!"
);
std
::
cout
<<
"[Test 8] Allocated memory after full reset.
\n
"
;
std
::
cout
<<
"---------------------------------
\n
"
;
std
::
cout
<<
"All tests passed successfully!
\n
"
;
}
int
main
()
{
testBumpAllocator
();
return
0
;
}
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