Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ASP
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
j2-tulloch
ASP
Commits
fa763121
Commit
fa763121
authored
1 year ago
by
j2-tulloch
Browse files
Options
Downloads
Patches
Plain Diff
Upload test1
parent
01dc0693
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Worksheet2/test1.cpp
+38
-0
38 additions, 0 deletions
Worksheet2/test1.cpp
with
38 additions
and
0 deletions
Worksheet2/test1.cpp
0 → 100644
+
38
−
0
View file @
fa763121
#include
<iostream>
#include
<cstddef>
#include
"bumpall.hpp"
// Assuming BumpAllocator is defined in BumpAllocator.h
int
main
()
{
// Test case 1: Create an allocator and allocate some memory
std
::
cout
<<
"Test case 1: Create an allocator and allocate some memory"
<<
std
::
endl
;
BumpAllocator
allocator
(
100
);
// Create an allocator with 100 bytes
void
*
ptr1
=
allocator
.
allocate
(
50
);
// Allocate 50 bytes
if
(
ptr1
!=
nullptr
)
{
std
::
cout
<<
"Allocation of 50 bytes succeeded."
<<
std
::
endl
;
}
// Test case 2: Attempt to allocate more than remaining space
std
::
cout
<<
"
\n
Test case 2: Attempt to allocate more than remaining space"
<<
std
::
endl
;
void
*
ptr2
=
allocator
.
allocate
(
60
);
// Attempt to allocate 60 bytes, should fail
if
(
ptr2
==
nullptr
)
{
std
::
cout
<<
"Allocation of 60 bytes failed as expected."
<<
std
::
endl
;
}
// Test case 3: Allocate remaining space
std
::
cout
<<
"
\n
Test case 3: Allocate remaining space"
<<
std
::
endl
;
void
*
ptr3
=
allocator
.
allocate
(
50
);
// Allocate the remaining 50 bytes
if
(
ptr3
!=
nullptr
)
{
std
::
cout
<<
"Allocation of remaining 50 bytes succeeded."
<<
std
::
endl
;
}
// Test case 4: Reset the allocator and allocate again
std
::
cout
<<
"
\n
Test case 4: Reset the allocator and allocate again"
<<
std
::
endl
;
allocator
.
reset
();
// Reset the allocator
void
*
ptr4
=
allocator
.
allocate
(
100
);
// Allocate 100 bytes again
if
(
ptr4
!=
nullptr
)
{
std
::
cout
<<
"Allocation of 100 bytes after reset succeeded."
<<
std
::
endl
;
}
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