From ff5cb1c62896dc77f88b526e61483d87c94c95f8 Mon Sep 17 00:00:00 2001
From: j2-tulloch <james2.tulloch@live.uwe.ac.uk>
Date: Sat, 6 Jan 2024 09:32:13 +0000
Subject: [PATCH] Test File

---
 Assignment/Task 3/test1.cpp | 62 +++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 Assignment/Task 3/test1.cpp

diff --git a/Assignment/Task 3/test1.cpp b/Assignment/Task 3/test1.cpp
new file mode 100644
index 0000000..c304bfe
--- /dev/null
+++ b/Assignment/Task 3/test1.cpp	
@@ -0,0 +1,62 @@
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <cassert>
+#include "your_fiber_header.h" // Replace with your actual fiber system header file
+
+// Function prototypes
+void testRunWithoutErrors();
+void testSpawnAndExecuteTwoFibers();
+void testPrintOrder();
+// Add more prototypes for other tests
+
+int main() {
+    testRunWithoutErrors();
+    testSpawnAndExecuteTwoFibers();
+    testPrintOrder();
+    // Call other test functions
+
+    std::cout << "All tests passed." << std::endl;
+    return 0;
+}
+
+void testRunWithoutErrors() {
+    int result = main();
+    assert(result == 0);
+}
+
+void testSpawnAndExecuteTwoFibers() {
+    // Redirect cout to capture output
+    std::streambuf* originalCout = std::cout.rdbuf();
+    std::ostringstream capturedCout;
+    std::cout.rdbuf(capturedCout.rdbuf());
+
+    main();
+    std::string output = capturedCout.str();
+
+    // Restore original cout buffer
+    std::cout.rdbuf(originalCout);
+
+    assert(output.find("fiber 1 before") != std::string::npos);
+    assert(output.find("fiber 1 after") != std::string::npos);
+    assert(output.find("fiber 2") != std::string::npos);
+}
+
+void testPrintOrder() {
+    // Redirect cout to capture output
+    std::streambuf* originalCout = std::cout.rdbuf();
+    std::ostringstream capturedCout;
+    std::cout.rdbuf(capturedCout.rdbuf());
+
+    main();
+    std::string output = capturedCout.str();
+
+    // Restore original cout buffer
+    std::cout.rdbuf(originalCout);
+
+    auto posBefore = output.find("fiber 1 before");
+    auto posAfter = output.find("fiber 1 after");
+    assert(posBefore < posAfter);
+}
+
+// Implement other test functions similarly
-- 
GitLab