Skip to content

Commit

Permalink
Test interaction between SVS enable and substates
Browse files Browse the repository at this point in the history
See #475.
  • Loading branch information
garfieldnate committed Jun 26, 2024
1 parent c556fcb commit 3d0d4ba
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 0 deletions.
1 change: 1 addition & 0 deletions UnitTests/SoarUnitTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MultiAgentTest.cpp"
#include "SimpleListener.cpp"
#include "SMemFunctionalTests.cpp"
#include "SvsTests.cpp"
#include "TokenizerTest.cpp"
#include "wma/WmaFunctionalTests.cpp"
#include "ExampleTests.cpp"
Expand Down
162 changes: 162 additions & 0 deletions UnitTests/SoarUnitTests/SvsTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include "SvsTests.hpp"
#include "soar_instance.h"

void SvsTests::setUp()
{
kernel = sml::Kernel::CreateKernelInCurrentThread(true, sml::Kernel::kUseAnyPort);
configure_for_unit_tests();
agent = kernel->CreateAgent("soar1");
configure_agent_for_unit_tests(NULL);
}

void SvsTests::tearDown(bool caught)
{
kernel->DestroyAgent(agent);
kernel->Shutdown();
delete kernel;
kernel = nullptr;
}

void SvsTests::testEnableFromTopState()
{
// enable, step, check that ^svs exists everywhere

agent->ExecuteCommandLine("svs --enable");
assertTrue_msg("Failed to enable SVS.",
agent->GetLastCommandLineResult());

agent->ExecuteCommandLine("svs --enable-in-substates");
assertTrue_msg("Failed to enable SVS in substates.",
agent->GetLastCommandLineResult());

std::string result = agent->ExecuteCommandLine("print S1");
assertFalse_msg("Expected to find ^svs in S1; return was " + result,
result.find("^svs") == std::string::npos);

// no productions, so agent will subgoal each step
agent->ExecuteCommandLine("step 2");

result = agent->ExecuteCommandLine("print S2");
assertFalse_msg("Expected to find ^svs in S2; return was: " + result,
result.find("^svs") == std::string::npos);
result = agent->ExecuteCommandLine("print S3");
assertFalse_msg("Expected to find ^svs in S3",
result.find("^svs") == std::string::npos);
}

void SvsTests::testEnableAndDisableInSubstatesFromTopState() {
// disable-in-substates, step, ^svs should not exist in substates

agent->ExecuteCommandLine("svs --enable");
assertTrue_msg("Failed to enable SVS.",
agent->GetLastCommandLineResult());

agent->ExecuteCommandLine("svs --disable-in-substates");
assertTrue_msg("Failed to enable SVS in substates.",
agent->GetLastCommandLineResult());

std::string result = agent->ExecuteCommandLine("print S1");
assertFalse_msg("Expected to find ^svs in S1",
result.find("^svs") == std::string::npos);

// no productions, so agent will subgoal each step
agent->ExecuteCommandLine("step 2");

result = agent->ExecuteCommandLine("print S2");
assertTrue_msg("Expected to not find ^svs in S2; return was: " + result,
result.find("^svs") == std::string::npos);
result = agent->ExecuteCommandLine("print S3");
assertTrue_msg("Expected to not find ^svs in S3",
result.find("^svs") == std::string::npos);
}

void SvsTests::testCannotDisableInSubstate()
{
// enable, step, try to disable, should fail

agent->ExecuteCommandLine("svs --enable");
assertTrue_msg("Failed to enable SVS.",
agent->GetLastCommandLineResult());

// no productions, so agent will subgoal each step
agent->ExecuteCommandLine("step 1");

std::string result = agent->ExecuteCommandLine("svs --disable");
assertFalse_msg("Expected not to be able to disable SVS from a substate; return was: " + result + " (" + (agent->GetLastCommandLineResult() ? "true" : "false") + ")",
agent->GetLastCommandLineResult());

result = agent->ExecuteCommandLine("svs --disable-in-substates");
assertFalse_msg("Expected not to be able to disable SVS in substates from a substate; return was: " + result,
agent->GetLastCommandLineResult());
}

void SvsTests::testEnableFromSubstate()
{
// disable, step, enable, check that ^svs exists in all states



agent->ExecuteCommandLine("svs --disable");
assertTrue_msg("Failed to disable SVS.",
agent->GetLastCommandLineResult());

// no productions, so agent will subgoal each step
agent->ExecuteCommandLine("step 2");
agent->ExecuteCommandLine("svs --enable");
assertTrue_msg("Failed to enable SVS.",
agent->GetLastCommandLineResult());

std::string result = agent->ExecuteCommandLine("print S1");
assertFalse_msg("Expected to find ^svs in S1",
result.find("^svs") == std::string::npos);
result = agent->ExecuteCommandLine("print S2");
assertFalse_msg("Expected to find ^svs in S2",
result.find("^svs") == std::string::npos);
result = agent->ExecuteCommandLine("print S3");
assertFalse_msg("Expected to find ^svs in S3",
result.find("^svs") == std::string::npos);

}

void SvsTests::testEnableInSubstatesFromSubstate()
{
// disable-in-substates, step and then enable, check that ^svs exists only on top state

agent->ExecuteCommandLine("svs --disable");
assertTrue_msg("Failed to disable SVS.",
agent->GetLastCommandLineResult());
agent->ExecuteCommandLine("svs --disable-in-substates");
assertTrue_msg("Failed to disable SVS in substates.",
agent->GetLastCommandLineResult());

// no productions, so agent will subgoal each step
agent->ExecuteCommandLine("step 2");

std::string result = agent->ExecuteCommandLine("print S1");
assertTrue_msg("Expected to not find ^svs in S1; return was " + result,
result.find("^svs") == std::string::npos);
result = agent->ExecuteCommandLine("print S3");
assertTrue_msg("Expected to not find ^svs in S3",
result.find("^svs") == std::string::npos);

agent->ExecuteCommandLine("svs --enable");
assertTrue_msg("Failed to enable SVS.",
agent->GetLastCommandLineResult());
result = agent->ExecuteCommandLine("print S3");
assertTrue_msg("Expected to not find ^svs in S3",
result.find("^svs") == std::string::npos);

// then enable-in-substates and check that ^svs exists on all states

agent->ExecuteCommandLine("svs --enable-in-substates");
assertTrue_msg("Failed to enable SVS in substates.",
agent->GetLastCommandLineResult());
result = agent->ExecuteCommandLine("print S3");
assertFalse_msg("Expected to find ^svs in S3",
result.find("^svs") == std::string::npos);
}

void SvsTests::testSubstateWhenDisabledInSubstates()
{
// TODO
}
59 changes: 59 additions & 0 deletions UnitTests/SoarUnitTests/SvsTests.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// SvsTests.hpp
// Soar-xcode
//
// Created by Alex Turner on 6/27/15.
// Copyright © 2015 University of Michigan – Soar Group. All rights reserved.
//

#ifndef SvsTests_cpp
#define SvsTests_cpp

#include "portability.h"

#include <string>
#include <vector>
#include <sstream>

#include "sml_Connection.h"
#include "sml_Client.h"
#include "sml_Utils.h"
#include "thread_Event.h"
#include "sml_Names.h"

#include "FunctionalTestHarness.hpp"

class SvsTests : public FunctionalTestHarness
{
private:
sml::Agent* agent;
sml::Kernel* kernel;

public:
TEST_CATEGORY(SvsTests);
void before() { setUp(); }
void setUp();

void after(bool caught) { tearDown(caught); }
void tearDown(bool caught);

TEST(testEnableFromTopState, -1);
void testEnableFromTopState();

TEST(testEnableAndDisableInSubstatesFromTopState, -1);
void testEnableAndDisableInSubstatesFromTopState();

TEST(testCannotDisableInSubstate, -1);
void testCannotDisableInSubstate();

TEST(testEnableFromSubstate, -1);
void testEnableFromSubstate();

TEST(testEnableInSubstatesFromSubstate, -1);
void testEnableInSubstatesFromSubstate();

TEST(testSubstateWhenDisabledInSubstates, -1);
void testSubstateWhenDisabledInSubstates();
};

#endif /* SvsTests_cpp */
2 changes: 2 additions & 0 deletions UnitTests/TestHarness/testMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "MultiAgentTest.hpp"
#include "SimpleListener.hpp"
#include "SMemFunctionalTests.hpp"
#include "SvsTests.hpp"
#include "TokenizerTest.hpp"
#include "wma/WmaFunctionalTests.hpp"
#include "TestCategory.hpp"
Expand Down Expand Up @@ -202,6 +203,7 @@ int main(int argc, char** argv)
TEST_DECLARATION(MiscTests);
TEST_DECLARATION(MultiAgentTest);
TEST_DECLARATION(SMemFunctionalTests);
TEST_DECLARATION(SvsTests);
TEST_DECLARATION(TokenizerTest);
TEST_DECLARATION(WmaFunctionalTests);

Expand Down

0 comments on commit 3d0d4ba

Please sign in to comment.