Skip to content
Snippets Groups Projects
Commit 9f05b702 authored by KyleKlenk's avatar KyleKlenk
Browse files

Created new container class and tests for it

parent a99f36d4
No related branches found
No related tags found
No related merge requests found
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment