Skip to content

Commit

Permalink
Test location prediction RHS functions
Browse files Browse the repository at this point in the history
Tests are from @jrkirk.
  • Loading branch information
garfieldnate committed Sep 27, 2024
1 parent 3bbee22 commit dad0d83
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
56 changes: 56 additions & 0 deletions UnitTests/SoarTestAgents/predict-location.soar
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Exercises predict-x, predict-y, and compute-closest-intercept RHS functions

sp {elaborate*predict-position*variables
(state <s> ^superstate nil)
-->
(<s> ^current-x 0
^current-y 0
^heading 120
^speed 10
^elapsed-time 2)
}

#Result for predict-x is 10
sp {test*rhs*predict-x
(state <s> ^current-x <x>
^heading <heading>
^speed <speed>
^elapsed-time <time>)
-->
(<s> ^new-x-position (predict-x <x> <heading> <speed> <time>))
}

#Result for predict-y is 17
sp {test*rhs*predict-y
(state <s> ^current-y <y>
^heading <heading>
^speed <speed>
^elapsed-time <time>)
-->
(<s> ^new-y-position (predict-y <y> <heading> <speed> <time>))
}

sp {elaborate*locations
(state <s> ^superstate nil)
-->
(<s> ^locations <locations>)
(<locations> ^point <a> <b> <c> <d> <e> <f> <g> <h>)
(<a> ^x 5 ^y 0 ^id |east-location|)
(<b> ^x 5 ^y -5 ^id |northeast-location|)
(<c> ^x 0 ^y -5 ^id |north-location|)
(<d> ^x -5 ^y -5 ^id |northwest-location|)
(<e> ^x -5 ^y 0 ^id |west-location|)
(<f> ^x -5 ^y 5 ^id |southwest-location|)
(<g> ^x 0 ^y 5 ^id |south-location|)
(<h> ^x 5 ^y 5 ^id |southeast-location|)
}

# Result for compute-closest-intercept is southeast-location
sp {test*rhs*compute-nearest-intercept
(state <s> ^current-y <y>
^current-x <x>
^heading <heading>
^locations <locations>)
-->
(<s> ^predicted-destination (compute-closest-intercept <x> <y> <heading> <locations>))
}
22 changes: 13 additions & 9 deletions UnitTests/SoarUnitTests/MiscTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,12 @@ void MiscTests::testStopPhaseRetrieval()
assertTrue(response.GetArgInt(sml::sml_Names::kParamPhase, -1) == sml::smlPhase::sml_APPLY_PHASE);
}



void MiscTests::testProductionPrinting()
{
// Tries to fully exercise Symbol::to_string
agent->ExecuteCommandLine("sp {foo (state <s> ^superstate nil) --> (<s> ^one 1 ^two 2.0 ^three 3.0e0 ^foo bar ^|| hi ^|<bar>| bar ^|^baz| baz ^1 one ^|2.0| two)}");
no_agent_assertTrue(agent->GetLastCommandLineResult());
std::string spMessage = agent->ExecuteCommandLine("print foo");
// sp {foo
// (state <s> ^superstate nil)
// -->
// (<s> ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|<bar>| bar
// ^|^baz| baz ^1 one ^|2.0| two)
// }
//
no_agent_assertTrue(spMessage == "sp {foo\n (state <s> ^superstate nil)\n -->\n (<s> ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|<bar>| bar\n ^|^baz| baz ^1 one ^|2.0| two)\n}\n\n");
}

Expand All @@ -403,6 +394,19 @@ void MiscTests::testSvsSceneCaseInsensitivity()
no_agent_assertTrue_msg("D34 scene name found: " + result, result == "path not found\n");
}

void MiscTests::testLocationPredictionRhs()
{
source("predict-location.soar");
agent->RunSelf(1);
std::string result = agent->ExecuteCommandLine("p s1");
// Should contain "^new-x-position 17"
no_agent_assertTrue_msg("predict-x failed: " + result, result.find("^new-x-position 17") != std::string::npos);
// Should contain ^new-y-position 10
no_agent_assertTrue_msg("predict-y failed: " + result, result.find("^new-y-position 10") != std::string::npos);
// Should contain ^predicted-destination southeast-location
no_agent_assertTrue_msg("compute-closest-intercept failed: " + result, result.find("^predicted-destination southeast-location") != std::string::npos);
}

//void MiscTests::testSoarDebugger()
//{
// bool result = agent->SpawnDebugger();
Expand Down
3 changes: 3 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class MiscTests : public FunctionalTestHarness
TEST(testSvsSceneCaseInsensitivity, -1)
void testSvsSceneCaseInsensitivity();

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

// If you would like to test the Soar Debugger Spawning, uncomment below.
// It may or may not work but should unless you're running without a GUI.
// TEST(testSoarDebugger, -1)
Expand Down

0 comments on commit dad0d83

Please sign in to comment.