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
afd26b08
Commit
afd26b08
authored
1 year ago
by
j2-tulloch
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
fa763121
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
Worksheet2/test2.cpp
+40
-0
40 additions, 0 deletions
Worksheet2/test2.cpp
with
40 additions
and
0 deletions
Worksheet2/test2.cpp
0 → 100644
+
40
−
0
View file @
afd26b08
#include
<iostream>
#include
<cstddef>
#include
"bumpalld.hpp"
// Include the BumpAllocator class definition
// Simple Test Framework
#define TEST_MESSAGE(condition, message) \
if (!(condition)) { \
std::cout << "Test failed: " << message << std::endl; \
return 1; \
} \
else { \
std::cout << "Test passed: " << #condition << std::endl; \
}
int
BumpTest
()
{
std
::
cout
<<
"Running BumpTest..."
<<
std
::
endl
;
BumpAllocator
bumper
(
20
*
sizeof
(
int
));
// Create an allocator with space for 20 integers
int
*
x
=
static_cast
<
int
*>
(
bumper
.
allocate
(
10
*
sizeof
(
int
)));
// Allocate space for 10 integers
TEST_MESSAGE
(
x
!=
nullptr
,
"Failed to allocate 10 integers"
);
int
*
y
=
static_cast
<
int
*>
(
bumper
.
allocate
(
10
*
sizeof
(
int
)));
// Allocate space for another 10 integers
TEST_MESSAGE
(
y
!=
nullptr
,
"Failed to allocate another 10 integers"
);
int
*
z
=
static_cast
<
int
*>
(
bumper
.
allocate
(
10
*
sizeof
(
int
)));
// Try to allocate space for 10 more integers
TEST_MESSAGE
(
z
==
nullptr
,
"Should have failed to allocate 10 more integers"
);
return
0
;
// Return 0 to indicate success
}
int
main
()
{
int
result
=
BumpTest
();
if
(
result
!=
0
)
{
std
::
cerr
<<
"Some tests failed."
<<
std
::
endl
;
return
1
;
}
std
::
cout
<<
"All tests passed!"
<<
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