From afd26b08fa165469b3c8429aadd6f75b83028ea7 Mon Sep 17 00:00:00 2001
From: j2-tulloch <james2.tulloch@live.uwe.ac.uk>
Date: Wed, 20 Dec 2023 21:00:57 +0000
Subject: [PATCH] Upload New File

---
 Worksheet2/test2.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Worksheet2/test2.cpp

diff --git a/Worksheet2/test2.cpp b/Worksheet2/test2.cpp
new file mode 100644
index 0000000..79447be
--- /dev/null
+++ b/Worksheet2/test2.cpp
@@ -0,0 +1,40 @@
+#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;
+}
-- 
GitLab