From 9f05b70217f4d7d307c1033a096df9ee8a42161a Mon Sep 17 00:00:00 2001 From: KyleKlenk <kyle.c.klenk@gmail.com> Date: Tue, 3 May 2022 14:15:37 -0600 Subject: [PATCH] Created new container class and tests for it --- build/source/actors/OutputManager.h | 70 ++++++++++++++++++++++++++++ build/source/testing/testing_main.cc | 70 ++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 build/source/actors/OutputManager.h diff --git a/build/source/actors/OutputManager.h b/build/source/actors/OutputManager.h new file mode 100644 index 0000000..ff95bec --- /dev/null +++ b/build/source/actors/OutputManager.h @@ -0,0 +1,70 @@ +#ifndef OutputManager_H_ +#define OutputManager_H_ + +#include "caf/all.hpp" +#include <vector> + +class ActorRefList { + private: + int currentSize; + int maxSize; + std::vector<caf::actor> list; + + public: + // Constructor + ActorRefList(int maxSize){ + this->currentSize = 0; + this->maxSize = maxSize; + } + + // Deconstructor + ~ActorRefList(){}; + + int getCurrentSize() { + return this->currentSize; + } + + bool isFull() { + return list.size() == this->maxSize; + } + + void addActor(caf::actor actor) { + if (this->isFull()) { + throw "List is full, cannot add actor to this list"; + } + this->currentSize++; + list.push_back(actor); + } + + caf::actor popActor() { + if (list.empty()) { + throw "List is empty, nothing to pop."; + } + auto actor = list.back(); + list.pop_back(); + this->currentSize--; + return actor; + } + + + + +}; + +class OutputManager { + private: + + int numVectors; + + std::vector<std::vector<caf::actor>> actorRefList; + + + + public: + // Constructor + OutputManager(){} + // Deconstructor + ~OutputManager(){}; +}; + +#endif \ No newline at end of file diff --git a/build/source/testing/testing_main.cc b/build/source/testing/testing_main.cc index 74ea6a3..8fc1382 100644 --- a/build/source/testing/testing_main.cc +++ b/build/source/testing/testing_main.cc @@ -1,6 +1,8 @@ #include "testCoordinator.h" -#include "../actors/commonFunctions.h" +#include "../actors/global.h" +#include "../actors/OutputManager.h" #include <chrono> +#include <iostream> #include <thread> #define IS_TRUE(x) { if (!(x)) std::cout << __FUNCTION__ << " failed on line " << __LINE__ << std::endl; } @@ -79,7 +81,6 @@ bool calcTimeAccumulate3Val(int sleepTime1, int sleepTime2, int sleepTime3) { } } - void test_calculateTime() { IS_TRUE(calcTimeTest(2)); IS_TRUE(calcTimeTest(4)); @@ -92,10 +93,73 @@ void test_calculateTime() { IS_TRUE(calcTimeAccumulate3Val(5, 2, 3)); } + +void testOutputManager(caf::actor_system& sys) { + auto a1 = sys.spawn(test_coordinator); + auto a2 = sys.spawn(test_coordinator); + auto a3 = sys.spawn(test_coordinator); + auto a4 = sys.spawn(test_coordinator); + auto a5 = sys.spawn(test_coordinator); + auto a6 = sys.spawn(test_coordinator); + + auto om = new ActorRefList(5); + + IS_TRUE(om->getCurrentSize() == 0); + om->addActor(a1); + IS_TRUE(om->getCurrentSize() == 1); + om->addActor(a2); + IS_TRUE(om->getCurrentSize() == 2); + om->addActor(a3); + IS_TRUE(om->getCurrentSize() == 3); + om->addActor(a4); + IS_TRUE(om->getCurrentSize() == 4); + om->addActor(a5); + IS_TRUE(om->getCurrentSize() == 5); + try { + om->addActor(a6); + } catch (const char* msg) { + std::cerr << msg << std::endl; + IS_TRUE(om->getCurrentSize() == 5) + } + + IS_TRUE(om->isFull()); + + auto a7 = om->popActor(); + IS_TRUE(a7 == a5); + IS_TRUE(om->getCurrentSize() == 4); + auto a8 = om->popActor(); + IS_TRUE(a8 == a4); + IS_TRUE(om->getCurrentSize() == 3); + auto a9 = om->popActor(); + IS_TRUE(a9 == a3); + IS_TRUE(om->getCurrentSize() == 2); + auto a10 = om->popActor(); + IS_TRUE(a10 == a2); + IS_TRUE(om->getCurrentSize() == 1); + auto a11 = om->popActor(); + IS_TRUE(a11 == a1); + try { + om->popActor(); + } catch (const char* msg) { + std::cerr << msg << std::endl; + IS_TRUE(om->getCurrentSize() == 0) + } + + + + + + +} + + + + void caf_main(caf::actor_system& sys) { caf::scoped_actor self{sys}; aout(self) << "Starting Test \n"; - test_calculateTime(); + // test_calculateTime(); + testOutputManager(sys); } CAF_MAIN() \ No newline at end of file -- GitLab