-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy
committed
Jun 18, 2024
1 parent
ffbd793
commit 631b816
Showing
11 changed files
with
362 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...mponents/problem-solver/cxx/message-reply-module/test/agent/GenerateReplyMessageAgent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <sc-agents-common/utils/AgentUtils.hpp> | ||
#include "sc-agents-common/utils/IteratorUtils.hpp" | ||
#include "sc-agents-common/keynodes/coreKeynodes.hpp" | ||
#include "keynodes/MessageReplyKeynodes.hpp" | ||
#include "GenerateReplyMessageAgent.hpp" | ||
|
||
using namespace messageReplyModuleTest; | ||
|
||
SC_AGENT_IMPLEMENTATION(GenerateReplyMessageAgent) | ||
{ | ||
ScAddr const & actionAddr = otherAddr; | ||
if (!m_memoryCtx.HelperCheckEdge( | ||
messageReplyModule::MessageReplyKeynodes::action_interpret_non_atomic_action, actionAddr, ScType::EdgeAccessConstPosPerm)) | ||
{ | ||
return SC_RESULT_OK; | ||
} | ||
SC_LOG_DEBUG("GenerateMessageReplyAgent started"); | ||
if(!actionIsValid(actionAddr)) | ||
{ | ||
utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, false); | ||
} | ||
|
||
ScAddr argsSet = utils::IteratorUtils::getAnyByOutRelation( | ||
& m_memoryCtx, | ||
actionAddr, | ||
scAgentsCommon::CoreKeynodes::rrel_2); | ||
ScAddr messageAddr = utils::IteratorUtils::getAnyByOutRelation( | ||
& m_memoryCtx, | ||
argsSet, | ||
scAgentsCommon::CoreKeynodes::rrel_1); | ||
|
||
ScTemplate scTemplate; | ||
scTemplate.Quintuple( | ||
messageAddr, | ||
ScType::EdgeDCommonVar, | ||
ScType::NodeVar, | ||
ScType::EdgeAccessVarPosPerm, | ||
messageReplyModule::MessageReplyKeynodes::nrel_reply); | ||
ScTemplateParams templateParams; | ||
ScTemplateGenResult templateGenResult; | ||
m_memoryCtx.HelperGenTemplate(scTemplate, templateGenResult, templateParams); | ||
SC_LOG_DEBUG("GenerateMessageReplyAgent finished"); | ||
utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, true); | ||
return SC_RESULT_OK; | ||
} | ||
|
||
bool GenerateReplyMessageAgent::actionIsValid(const ScAddr & actionAddr) | ||
{ | ||
ScTemplate scTemplate; | ||
scTemplate.Quintuple( | ||
actionAddr, | ||
ScType::EdgeAccessVarPosPerm, | ||
messageReplyModule::MessageReplyKeynodes::message_processing_program, | ||
ScType::EdgeAccessVarPosPerm, | ||
scAgentsCommon::CoreKeynodes::rrel_1); | ||
scTemplate.Quintuple( | ||
actionAddr, | ||
ScType::EdgeAccessVarPosPerm, | ||
ScType::NodeVar >> "_args_set", | ||
ScType::EdgeAccessVarPosPerm, | ||
scAgentsCommon::CoreKeynodes::rrel_2); | ||
scTemplate.Quintuple( | ||
"_args_set", | ||
ScType::EdgeAccessVarPosPerm, | ||
ScType::NodeVar >> "_message", | ||
ScType::EdgeAccessVarPosPerm, | ||
scAgentsCommon::CoreKeynodes::rrel_1); | ||
scTemplate.Triple( | ||
messageReplyModule::MessageReplyKeynodes::concept_message, | ||
ScType::EdgeAccessVarPosPerm, | ||
"_message"); | ||
ScTemplateSearchResult searchResult; | ||
m_memoryCtx.HelperSearchTemplate(scTemplate, searchResult); | ||
return searchResult.Size() == 1; | ||
} |
20 changes: 20 additions & 0 deletions
20
...mponents/problem-solver/cxx/message-reply-module/test/agent/GenerateReplyMessageAgent.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "sc-memory/kpm/sc_agent.hpp" | ||
#include "sc-agents-common/keynodes/coreKeynodes.hpp" | ||
|
||
#include "GenerateReplyMessageAgent.generated.hpp" | ||
|
||
namespace messageReplyModuleTest | ||
{ | ||
|
||
class GenerateReplyMessageAgent : public ScAgent | ||
{ | ||
SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) | ||
SC_GENERATED_BODY() | ||
|
||
private: | ||
bool actionIsValid(ScAddr const & actionAddr); | ||
}; | ||
|
||
} // namespace commonTest |
20 changes: 20 additions & 0 deletions
20
...nents/problem-solver/cxx/message-reply-module/test/agent/NotGenerateReplyMessageAgent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <sc-agents-common/utils/AgentUtils.hpp> | ||
|
||
#include "sc-agents-common/keynodes/coreKeynodes.hpp" | ||
|
||
#include "NotGenerateReplyMessageAgent.hpp" | ||
|
||
using namespace messageReplyModuleTest; | ||
|
||
SC_AGENT_IMPLEMENTATION(NotGenerateReplyMessageAgent) | ||
{ | ||
ScAddr const & actionAddr = otherAddr; | ||
if(!m_memoryCtx.HelperCheckEdge( | ||
messageReplyModule::MessageReplyKeynodes::action_interpret_non_atomic_action, actionAddr, ScType::EdgeAccessConstPosPerm)) | ||
{ | ||
return SC_RESULT_OK; | ||
} | ||
|
||
utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, true); | ||
return SC_RESULT_OK; | ||
} |
18 changes: 18 additions & 0 deletions
18
...nents/problem-solver/cxx/message-reply-module/test/agent/NotGenerateReplyMessageAgent.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "sc-memory/kpm/sc_agent.hpp" | ||
#include "keynodes/MessageReplyKeynodes.hpp" | ||
#include "sc-agents-common/keynodes/coreKeynodes.hpp" | ||
|
||
#include "NotGenerateReplyMessageAgent.generated.hpp" | ||
|
||
namespace messageReplyModuleTest | ||
{ | ||
|
||
class NotGenerateReplyMessageAgent : public ScAgent | ||
{ | ||
SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) | ||
SC_GENERATED_BODY() | ||
}; | ||
|
||
} // namespace commonTest |
17 changes: 17 additions & 0 deletions
17
...eply-module/test/testStructures/replyMessageAgentTestStructureFirstArgumentIsNotALink.scs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
test_action_node | ||
<- action_reply_to_message; | ||
<- question; | ||
=> nrel_authors: ...; | ||
-> rrel_1: ... | ||
(* | ||
<- format_wav;; | ||
<- concept_sound_file;; | ||
<- lang_en;; | ||
*);; | ||
|
||
message_processing_program <- sc_node_struct;; | ||
|
||
languages | ||
<- sc_node_not_relation; | ||
-> lang_ru (* <- sc_node_not_relation;; *); | ||
-> lang_en (* <- sc_node_not_relation;; *);; |
16 changes: 16 additions & 0 deletions
16
...module/test/testStructures/replyMessageAgentTestStructureWithIncorrectlySpecifiedLink.scs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test_action_node | ||
<- action_reply_to_message; | ||
<- question; | ||
=> nrel_authors: ...; | ||
-> rrel_1: [smth here] | ||
(* | ||
<- concept_sound_file;; | ||
<- lang_en;; | ||
*);; | ||
|
||
message_processing_program <- sc_node_struct;; | ||
|
||
languages | ||
<- sc_node_not_relation; | ||
-> lang_ru (* <- sc_node_not_relation;; *); | ||
-> lang_en (* <- sc_node_not_relation;; *);; |
15 changes: 15 additions & 0 deletions
15
...ply-module/test/testStructures/replyMessageAgentTestStructureWithoutProcessingProgram.scs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
test_action_node | ||
<- action_reply_to_message; | ||
<- question; | ||
=> nrel_authors: ...; | ||
-> rrel_1: [smth here] | ||
(* | ||
<- format_wav;; | ||
<- concept_sound_file;; | ||
<- lang_en;; | ||
*);; | ||
|
||
languages | ||
<- sc_node_not_relation; | ||
-> lang_ru (* <- sc_node_not_relation;; *); | ||
-> lang_en (* <- sc_node_not_relation;; *);; |
16 changes: 16 additions & 0 deletions
16
...r/cxx/message-reply-module/test/testStructures/replyMessageAgentTextLinkTestStructure.scs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test_action_node | ||
<- action_reply_to_message; | ||
<- question; | ||
-> rrel_1: [smth here] | ||
(* | ||
<- concept_text_file;; | ||
<- lang_en;; | ||
*); | ||
-> rrel_2: chat_node;; | ||
|
||
message_processing_program <- sc_node_struct;; | ||
|
||
languages | ||
<- sc_node_not_relation; | ||
-> lang_ru (* <- sc_node_not_relation;; *); | ||
-> lang_en (* <- sc_node_not_relation;; *);; |
21 changes: 21 additions & 0 deletions
21
platform-dependent-components/problem-solver/cxx/message-reply-module/test/tests.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
file(GLOB MESSAGE_REPLY_TEST_AGENTS_SOURCE | ||
"${CMAKE_CURRENT_LIST_DIR}/agent/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/agent/*.hpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/../keynodes/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/../keynodes/*.hpp" | ||
) | ||
add_library(message_reply_test_agents ${MESSAGE_REPLY_TEST_AGENTS_SOURCE}) | ||
target_link_libraries( | ||
message_reply_test_agents | ||
message-reply | ||
sc-agents-common | ||
) | ||
|
||
make_tests_from_folder(${CMAKE_CURRENT_LIST_DIR}/units | ||
NAME message_reply_module_test_starter | ||
DEPENDS sc-builder-lib message_reply_test_agents message-reply sc-core | ||
INCLUDES ${SC_MEMORY_SRC}/tests/sc-memory/_test ${CMAKE_CURRENT_LIST_DIR}/.. ${SC_TOOLS_SRC}/sc-builder/src ${SC_MEMORY_SRC}/sc-memory ${SC_MACHINE_ROOT}/sc-tools | ||
) | ||
|
||
add_definitions(-DMESSAGE_REPLY_MODULE_TEST_SRC_PATH="${CMAKE_CURRENT_LIST_DIR}") | ||
if(${SC_CLANG_FORMAT_CODE}) | ||
target_clangformat_setup(message_reply_module_test_starter) | ||
endif() |
141 changes: 141 additions & 0 deletions
141
...t-components/problem-solver/cxx/message-reply-module/test/units/testMessageReplyAgent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include "scs_loader.hpp" | ||
#include "sc_test.hpp" | ||
#include "sc-memory/kpm/sc_agent.hpp" | ||
#include "sc-agents-common/keynodes/coreKeynodes.hpp" | ||
#include "sc-agents-common/utils/AgentUtils.hpp" | ||
#include "sc-agents-common/utils/IteratorUtils.hpp" | ||
#include "agent/MessageReplyAgent.hpp" | ||
#include "keynodes/MessageReplyKeynodes.hpp" | ||
#include "test/agent/GenerateReplyMessageAgent.hpp" | ||
#include "utils/sc_log.hpp" | ||
|
||
namespace messageReplyModuleTest | ||
{ | ||
ScsLoader loader; | ||
const std::string TEST_FILES_DIR_PATH = MESSAGE_REPLY_MODULE_TEST_SRC_PATH "/testStructures/"; | ||
const int WAIT_TIME = 5000; | ||
|
||
using MessageReplyAgentTest = ScMemoryTest; | ||
|
||
void initialize() | ||
{ | ||
scAgentsCommon::CoreKeynodes::InitGlobal(); | ||
messageReplyModule::MessageReplyKeynodes::InitGlobal(); | ||
|
||
ScAgentInit(true); | ||
SC_AGENT_REGISTER(messageReplyModule::MessageReplyAgent) | ||
} | ||
|
||
void shutdown() | ||
{ | ||
SC_AGENT_UNREGISTER(messageReplyModule::MessageReplyAgent) | ||
} | ||
|
||
bool generatedMessageIsValid(ScMemoryContext * context, ScAddr const & textLinkAddr) | ||
{ | ||
ScTemplate scTemplate; | ||
scTemplate.Triple( | ||
messageReplyModule::MessageReplyKeynodes::concept_message, | ||
ScType::EdgeAccessVarPosPerm, | ||
ScType::NodeVar >> "_user_message"); | ||
scTemplate.Quintuple( | ||
ScType::NodeVar >> "_translation_node", | ||
ScType::EdgeDCommonVar, | ||
"_user_message", | ||
ScType::EdgeAccessVarPosPerm, | ||
scAgentsCommon::CoreKeynodes::nrel_sc_text_translation); | ||
scTemplate.Triple( | ||
"_translation_node", | ||
ScType::EdgeAccessVarPosPerm, | ||
textLinkAddr); | ||
ScTemplateSearchResult searchResult; | ||
context->HelperSearchTemplate(scTemplate, searchResult); | ||
return searchResult.Size() == 1; | ||
} | ||
|
||
TEST_F(MessageReplyAgentTest, messageProcessingWithTextLinkSuccessful) | ||
{ | ||
ScMemoryContext & context = *m_ctx; | ||
|
||
loader.loadScsFile( | ||
context, | ||
TEST_FILES_DIR_PATH + "replyMessageAgentTextLinkTestStructure.scs"); | ||
initialize(); | ||
SC_AGENT_REGISTER(GenerateReplyMessageAgent) | ||
|
||
ScAddr test_action_node = context.HelperFindBySystemIdtf("test_action_node"); | ||
EXPECT_TRUE(test_action_node.IsValid()); | ||
|
||
EXPECT_TRUE(utils::AgentUtils::applyAction(&context, test_action_node, WAIT_TIME)); | ||
EXPECT_TRUE(context.HelperCheckEdge( | ||
scAgentsCommon::CoreKeynodes::question_finished_successfully, | ||
test_action_node, | ||
ScType::EdgeAccessConstPosPerm)); | ||
|
||
EXPECT_TRUE(generatedMessageIsValid(&context, utils::IteratorUtils::getAnyByOutRelation( | ||
&context, | ||
test_action_node, | ||
scAgentsCommon::CoreKeynodes::rrel_1))); | ||
|
||
SC_AGENT_UNREGISTER(GenerateReplyMessageAgent) | ||
shutdown(); | ||
} | ||
|
||
|
||
TEST_F(MessageReplyAgentTest, argumentIsNotALink) | ||
{ | ||
ScMemoryContext & context = *m_ctx; | ||
|
||
loader.loadScsFile( | ||
context, | ||
TEST_FILES_DIR_PATH + "replyMessageAgentTestStructureFirstArgumentIsNotALink.scs"); | ||
initialize(); | ||
SC_AGENT_REGISTER(GenerateReplyMessageAgent) | ||
|
||
ScAddr test_action_node = context.HelperFindBySystemIdtf("test_action_node"); | ||
EXPECT_TRUE(test_action_node.IsValid()); | ||
|
||
context.CreateEdge( | ||
ScType::EdgeAccessConstPosPerm, | ||
scAgentsCommon::CoreKeynodes::question_initiated, | ||
test_action_node); | ||
|
||
EXPECT_TRUE(utils::AgentUtils::applyAction(&context, test_action_node, WAIT_TIME)); | ||
EXPECT_TRUE(context.HelperCheckEdge( | ||
scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, | ||
test_action_node, | ||
ScType::EdgeAccessConstPosPerm)); | ||
|
||
SC_AGENT_UNREGISTER(GenerateReplyMessageAgent) | ||
shutdown(); | ||
} | ||
|
||
TEST_F(MessageReplyAgentTest, linkSpecifiedIncorrectly) | ||
{ | ||
ScMemoryContext & context = *m_ctx; | ||
|
||
loader.loadScsFile( | ||
context, | ||
TEST_FILES_DIR_PATH + "replyMessageAgentTestStructureWithIncorrectlySpecifiedLink.scs"); | ||
initialize(); | ||
SC_AGENT_REGISTER(GenerateReplyMessageAgent) | ||
|
||
ScAddr test_action_node = context.HelperFindBySystemIdtf("test_action_node"); | ||
EXPECT_TRUE(test_action_node.IsValid()); | ||
|
||
context.CreateEdge( | ||
ScType::EdgeAccessConstPosPerm, | ||
scAgentsCommon::CoreKeynodes::question_initiated, | ||
test_action_node); | ||
|
||
EXPECT_TRUE(utils::AgentUtils::applyAction(&context, test_action_node, WAIT_TIME)); | ||
EXPECT_TRUE(context.HelperCheckEdge( | ||
scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, | ||
test_action_node, | ||
ScType::EdgeAccessConstPosPerm)); | ||
|
||
SC_AGENT_UNREGISTER(GenerateReplyMessageAgent) | ||
shutdown(); | ||
} | ||
|
||
}//namespace messageReplyModuleTest |