From 78da8fabe69db6cf5bd3f8cdd121d3df8699d19a Mon Sep 17 00:00:00 2001 From: KyleKlenk <kyle.c.klenk@gmail.com> Date: Wed, 18 May 2022 13:43:40 -0600 Subject: [PATCH] modified unit tests to compliment the changes to the output structure --- build/source/actors/OutputManager.h | 12 ++++ build/source/testing/testing_main.cc | 99 +++++++++++++++------------- 2 files changed, 67 insertions(+), 44 deletions(-) diff --git a/build/source/actors/OutputManager.h b/build/source/actors/OutputManager.h index aa3fa4c..74aa7c5 100644 --- a/build/source/actors/OutputManager.h +++ b/build/source/actors/OutputManager.h @@ -41,6 +41,13 @@ class ActorRefList { return list.size() == this->maxSize; } + /** + * Adds An Actor and its return message as a tuple to this->list + * actor - the actor ref of the actor being added to this->list + * returnMessage - Either 9999 (place holder and specifies to send a done_write_v message) or + * this is the current forcingFileList index that allows the file_access actor to know the number + * of steps the HRU actor that needs to compute + */ void addActor(caf::actor actor, int index, int returnMessage) { if (this->isFull()) { throw "List is full, cannot add actor to this list"; @@ -56,6 +63,10 @@ class ActorRefList { list.push_back(std::make_tuple(actor, returnMessage)); } + /** + * Return a tuple of an actor and its returnMessage. + * The return message is 9999 or the index of the forcingFile it needs to acces + */ std::tuple<caf::actor,int> popActor() { if (list.empty()) { throw "List is empty, nothing to pop"; @@ -114,6 +125,7 @@ class OutputManager { * * @param actor Actor reference * @param index Actor Index + * @param returnMessage Forcing File index or 9999 * @return int The list index that actor is added to. */ int addActor(caf::actor actor, int index, int returnMessage) { diff --git a/build/source/testing/testing_main.cc b/build/source/testing/testing_main.cc index c935b0f..9c034a5 100644 --- a/build/source/testing/testing_main.cc +++ b/build/source/testing/testing_main.cc @@ -94,6 +94,8 @@ void test_calculateTime() { void testActorRefList(caf::actor_system& sys) { + caf::scoped_actor self{sys}; + auto a1 = sys.spawn(test_coordinator); auto a2 = sys.spawn(test_coordinator); auto a3 = sys.spawn(test_coordinator); @@ -103,49 +105,57 @@ void testActorRefList(caf::actor_system& sys) { auto om = new ActorRefList(5); + // Test Adding Actor To ActorRefList IS_TRUE(om->getCurrentSize() == 0); - om->addActor(a1); + om->addActor(a1, 1, 9999); IS_TRUE(om->getCurrentSize() == 1); - om->addActor(a2); + om->addActor(a2, 2, 3); IS_TRUE(om->getCurrentSize() == 2); - om->addActor(a3); + om->addActor(a3, 3, 7); IS_TRUE(om->getCurrentSize() == 3); - om->addActor(a4); + om->addActor(a4, 4, 9999); IS_TRUE(om->getCurrentSize() == 4); - om->addActor(a5); + om->addActor(a5, 5, 8); IS_TRUE(om->getCurrentSize() == 5); + + // Try adding an actor to a full list try { - om->addActor(a6); + om->addActor(a6, 6, 9999); } catch (const char* msg) { std::cerr << msg << std::endl; IS_TRUE(om->getCurrentSize() == 5) } - + // Test isFull IS_TRUE(om->isFull()); + // Test removing actors from the list auto a7 = om->popActor(); - IS_TRUE(a7 == a5); + IS_TRUE(get<0>(a7) == a5 && get<1>(a7) == 8); IS_TRUE(om->getCurrentSize() == 4); auto a8 = om->popActor(); - IS_TRUE(a8 == a4); + IS_TRUE(get<0>(a8) == a4 && get<1>(a8) == 9999); IS_TRUE(om->getCurrentSize() == 3); auto a9 = om->popActor(); - IS_TRUE(a9 == a3); + IS_TRUE(get<0>(a9) == a3 && get<1>(a9) == 7); IS_TRUE(om->getCurrentSize() == 2); auto a10 = om->popActor(); - IS_TRUE(a10 == a2); + IS_TRUE(get<0>(a10) == a2 && get<1>(a10) == 3); IS_TRUE(om->getCurrentSize() == 1); auto a11 = om->popActor(); - IS_TRUE(a11 == a1); + IS_TRUE(get<0>(a11) == a1 && get<1>(a11) == 9999); try { om->popActor(); } catch (const char* msg) { std::cerr << msg << std::endl; IS_TRUE(om->getCurrentSize() == 0) } + + IS_TRUE(om->isEmpty()) } void testOutputManager(caf::actor_system& sys) { + caf::scoped_actor self{sys}; + auto a1 = sys.spawn(test_coordinator); auto a2 = sys.spawn(test_coordinator); auto a3 = sys.spawn(test_coordinator); @@ -157,7 +167,6 @@ void testOutputManager(caf::actor_system& sys) { auto a9 = sys.spawn(test_coordinator); auto a10 = sys.spawn(test_coordinator); - std::cout << "Creating Output Manager" << std::endl; auto OM = new OutputManager(5, 10); for (int i = 0; i < 5; i++) { @@ -169,55 +178,56 @@ void testOutputManager(caf::actor_system& sys) { std::cerr << msg << std::endl; } - OM->addActor(a1, 1); + // Test adding actors and ensuring they go to the correct List + OM->addActor(a1, 1, 1); IS_TRUE(OM->getSize(0) == 1); IS_TRUE(OM->getSize(1) == 0); IS_TRUE(OM->getSize(2) == 0); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a2, 2); + OM->addActor(a2, 2, 2); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 0); IS_TRUE(OM->getSize(2) == 0); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a3, 3); + OM->addActor(a3, 3, 3); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 1); IS_TRUE(OM->getSize(2) == 0); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a4, 4); + OM->addActor(a4, 4, 4); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 0); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a5, 5); + OM->addActor(a5, 5, 5); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 1); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a6, 6); + OM->addActor(a6, 6, 6); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 2); IS_TRUE(OM->getSize(3) == 0); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a7, 7); + OM->addActor(a7, 7, 7); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 2); IS_TRUE(OM->getSize(3) == 1); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a8, 8); + OM->addActor(a8, 8, 8); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 2); IS_TRUE(OM->getSize(3) == 2); IS_TRUE(OM->getSize(4) == 0); - OM->addActor(a9, 9); + OM->addActor(a9, 9, 9); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 2); @@ -225,7 +235,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM->getSize(4) == 1); IS_TRUE(!OM->isFull(4)) - OM->addActor(a10, 10); + OM->addActor(a10, 10, 10); IS_TRUE(OM->getSize(0) == 2); IS_TRUE(OM->getSize(1) == 2); IS_TRUE(OM->getSize(2) == 2); @@ -237,14 +247,15 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM->isFull(3)) IS_TRUE(OM->isFull(4)) + // Test Poping Actors auto a11 = OM->popActor(0); - IS_TRUE(a11 == a2); + IS_TRUE(get<0>(a11) == a2 && get<1>(a11) == 2); auto a14 = OM->popActor(0); - IS_TRUE(a14 == a1); + IS_TRUE(get<0>(a14) == a1 && get<1>(a14) == 1); auto a12 = OM->popActor(1); - IS_TRUE(a12 == a4); + IS_TRUE(get<0>(a12) == a4 && get<1>(a12) == 4); auto a13 = OM->popActor(4); - IS_TRUE(a13 == a10); + IS_TRUE(get<0>(a13) == a10 && get<1>(a13) == 10); IS_TRUE(OM->getSize(0) == 0); IS_TRUE(OM->getSize(1) == 1); IS_TRUE(OM->getSize(2) == 2); @@ -266,11 +277,11 @@ void testOutputManager(caf::actor_system& sys) { delete OM; - std::cout << "Creating Output Manager 2 with 3 vectors" << std::endl; + // std::cout << "Creating Output Manager 2 with 3 vectors" << std::endl; auto OM2 = new OutputManager(3, 10); try { - OM2->addActor(a1, 1); + OM2->addActor(a1, 1, 1); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -278,7 +289,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->getSize(1) == 0); IS_TRUE(OM2->getSize(2) == 0); try { - OM2->addActor(a2, 2); + OM2->addActor(a2, 2, 2); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -286,7 +297,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->getSize(1) == 0); IS_TRUE(OM2->getSize(2) == 0); try { - OM2->addActor(a3, 3); + OM2->addActor(a3, 3, 3); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -294,7 +305,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->getSize(1) == 0); IS_TRUE(OM2->getSize(2) == 0); try { - OM2->addActor(a4, 4); + OM2->addActor(a4, 4, 4); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -302,31 +313,31 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->getSize(1) == 1); IS_TRUE(OM2->getSize(2) == 0); try { - OM2->addActor(a5, 5); + OM2->addActor(a7, 7, 7); } catch (const char* msg) { std::cerr << msg << std::endl; } IS_TRUE(OM2->getSize(0) == 3); - IS_TRUE(OM2->getSize(1) == 2); - IS_TRUE(OM2->getSize(2) == 0); + IS_TRUE(OM2->getSize(1) == 1); + IS_TRUE(OM2->getSize(2) == 1); try { - OM2->addActor(a6, 6); + OM2->addActor(a8, 8, 8); } catch (const char* msg) { std::cerr << msg << std::endl; } IS_TRUE(OM2->getSize(0) == 3); - IS_TRUE(OM2->getSize(1) == 3); - IS_TRUE(OM2->getSize(2) == 0); + IS_TRUE(OM2->getSize(1) == 1); + IS_TRUE(OM2->getSize(2) == 2); try { - OM2->addActor(a7, 7); + OM2->addActor(a5, 5, 5); } catch (const char* msg) { std::cerr << msg << std::endl; } IS_TRUE(OM2->getSize(0) == 3); - IS_TRUE(OM2->getSize(1) == 3); - IS_TRUE(OM2->getSize(2) == 1); + IS_TRUE(OM2->getSize(1) == 2); + IS_TRUE(OM2->getSize(2) == 2); try { - OM2->addActor(a8, 8); + OM2->addActor(a6, 6, 6); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -334,7 +345,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->getSize(1) == 3); IS_TRUE(OM2->getSize(2) == 2); try { - OM2->addActor(a9, 9); + OM2->addActor(a9, 9, 9); } catch (const char* msg) { std::cerr << msg << std::endl; } @@ -345,7 +356,7 @@ void testOutputManager(caf::actor_system& sys) { IS_TRUE(OM2->isFull(1)); IS_TRUE(!OM2->isFull(2)); try { - OM2->addActor(a10, 10); + OM2->addActor(a10, 10, 10); } catch (const char* msg) { std::cerr << msg << 10 << std::endl; } -- GitLab