Skip to content
Snippets Groups Projects
Commit fa763121 authored by j2-tulloch's avatar j2-tulloch :speech_balloon:
Browse files

Upload test1

parent 01dc0693
Branches
No related tags found
No related merge requests found
#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 << "\nTest 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 << "\nTest 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 << "\nTest 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment