Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for LLMUtils #1269

Merged
merged 11 commits into from
Oct 18, 2023
4 changes: 2 additions & 2 deletions morpheus/_lib/src/llm/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ input_mappings_t process_input_names(user_input_mappings_t user_inputs, const st
{
auto& single_input = user_inputs[i];

bool found_star_input_name = single_input.external_name.find('*') != std::string::npos;
bool found_star_node_name = single_input.internal_name == "*";
bool found_star_node_name = single_input.external_name.find('*') != std::string::npos;
bool found_star_input_name = single_input.internal_name == "*";

if (found_star_input_name != found_star_node_name)
{
Expand Down
149 changes: 146 additions & 3 deletions morpheus/_lib/tests/llm/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ TEST_F(TestLLMUtils, IsValidNameSpace)
}
}

TEST_F(TestLLMUtils, ProcessInputNamesSingleString)
TEST_F(TestLLMUtils, ProcessInputNamesSingleMapping)
{
auto user_inputs = llm::user_input_mappings_t{{"/ext1", "input1"}};
auto input_names = std::vector<std::string>{"input1"};
auto user_inputs = llm::user_input_mappings_t{{"/ext1"}};

auto returned = llm::process_input_names(user_inputs, input_names);

Expand All @@ -82,10 +82,153 @@ TEST_F(TestLLMUtils, ProcessInputNamesSingleString)
EXPECT_EQ(returned[0].internal_name, "input1");
}

TEST_F(TestLLMUtils, ProcessInputNamesSingleString)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1"}};
auto input_names_1 = std::vector<std::string>{"input1"};

auto returned_1 = llm::process_input_names(user_inputs_1, input_names_1);

EXPECT_EQ(returned_1.size(), 1);
EXPECT_EQ(returned_1[0].external_name, "/ext1");
EXPECT_EQ(returned_1[0].internal_name, "input1");

auto user_inputs_2 = llm::user_input_mappings_t{{"input1"}};
auto input_names_2 = std::vector<std::string>{"input1"};

auto returned_2 = llm::process_input_names(user_inputs_2, input_names_2);

EXPECT_EQ(returned_2.size(), 1);
EXPECT_EQ(returned_2[0].external_name, "input1");
EXPECT_EQ(returned_2[0].internal_name, "input1");
}

TEST_F(TestLLMUtils, ProcessInputNamesMultipleMappings)
{
auto user_inputs = llm::user_input_mappings_t{{"/ext1", "input1"}, {"/ext2", "input2"}};
auto input_names = std::vector<std::string>{"input1", "input2"};

auto returned = llm::process_input_names(user_inputs, input_names);

EXPECT_EQ(returned.size(), 2);
EXPECT_EQ(returned[0].external_name, "/ext1");
EXPECT_EQ(returned[0].internal_name, "input1");
EXPECT_EQ(returned[1].external_name, "/ext2");
EXPECT_EQ(returned[1].internal_name, "input2");
}

TEST_F(TestLLMUtils, ProcessInputNamesMismatchInputNames)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1", "input2"}};
auto input_names_1 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_1, input_names_1), std::invalid_argument);

auto user_inputs_2 = llm::user_input_mappings_t{{"/ext1", "input1"}, {"/ext2", "input3"}};
auto input_names_2 = std::vector<std::string>{"input1", "input2"};

EXPECT_THROW(llm::process_input_names(user_inputs_2, input_names_2), std::invalid_argument);
}

TEST_F(TestLLMUtils, ProcessInputNamesCountMismatch)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1", "input1"}, {"/ext2", "input1"}};
auto input_names_1 = std::vector<std::string>{"input1", "input2"};

EXPECT_THROW(llm::process_input_names(user_inputs_1, input_names_1), std::invalid_argument);

auto input_names_2 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_1, input_names_2), std::invalid_argument);
}

TEST_F(TestLLMUtils, ProcessInputNamesPlaceholderMappings)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1/*", "*"}};
auto input_names_1 = std::vector<std::string>{"input1"};

auto returned_1 = llm::process_input_names(user_inputs_1, input_names_1);

EXPECT_EQ(returned_1.size(), 1);
EXPECT_EQ(returned_1[0].external_name, "/ext1/input1");
EXPECT_EQ(returned_1[0].internal_name, "input1");

auto user_inputs_2 = llm::user_input_mappings_t{{"/ext1/*", "*"}};
auto input_names_2 = std::vector<std::string>{"input1, input2"};

auto returned_2 = llm::process_input_names(user_inputs_2, input_names_2);

EXPECT_EQ(returned_2.size(), 1);
EXPECT_EQ(returned_2[0].external_name, "/ext1/input1, input2");
EXPECT_EQ(returned_2[0].internal_name, "input1, input2");
}

TEST_F(TestLLMUtils, ProcessInputNamesPlaceholderMismatch)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1", "*"}};
auto input_names_1 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_1, input_names_1), std::invalid_argument);

auto user_inputs_2 = llm::user_input_mappings_t{{"/ext1/*", "input1"}};
auto input_names_2 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_2, input_names_2), std::invalid_argument);
}

TEST_F(TestLLMUtils, ProcessInputNamesIndexMatching)
{
auto user_inputs = llm::user_input_mappings_t{{"/ext1"}, {"/ext2"}};
auto input_names = std::vector<std::string>{"input1", "input2"};
auto user_inputs = llm::user_input_mappings_t{{"/ext1", "input1"}, {"/ext2", "input1"}};

auto returned = llm::process_input_names(user_inputs, input_names);

EXPECT_EQ(returned.size(), 2);
EXPECT_EQ(returned[0].external_name, "/ext1");
EXPECT_EQ(returned[0].internal_name, "input1");
EXPECT_EQ(returned[1].external_name, "/ext2");
EXPECT_EQ(returned[1].internal_name, "input2");
}

TEST_F(TestLLMUtils, ProcessInputNamesNameMatching)
{
auto user_inputs = llm::user_input_mappings_t{{"input1"}, {"input2"}};
auto input_names = std::vector<std::string>{"input1", "input2"};

auto returned = llm::process_input_names(user_inputs, input_names);

EXPECT_EQ(returned.size(), 2);
EXPECT_EQ(returned[0].external_name, "input1");
EXPECT_EQ(returned[0].internal_name, "input1");
EXPECT_EQ(returned[1].external_name, "input2");
EXPECT_EQ(returned[1].internal_name, "input2");
}

TEST_F(TestLLMUtils, ProcessInputNamesMixNameAndIndexMatching)
{
auto user_inputs = llm::user_input_mappings_t{{"input1"}, {"/ext1"}};
auto input_names = std::vector<std::string>{"input1", "input2"};

EXPECT_THROW(llm::process_input_names(user_inputs, input_names), std::invalid_argument);
}

TEST_F(TestLLMUtils, ProcessInputNamesSiblingWithInputNameMatching)
{
auto user_inputs = llm::user_input_mappings_t{{"/ext1/input1"}};
auto input_names = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs, input_names), std::invalid_argument);
}

TEST_F(TestLLMUtils, ProcessInputNamesMatchingIndexExceeded)
{
auto user_inputs_1 = llm::user_input_mappings_t{{"/ext1"}, {"/ext2"}};
auto input_names_1 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_1, input_names_1), std::invalid_argument);

auto user_inputs_2 = llm::user_input_mappings_t{{"input1"}, {"input2"}};
auto input_names_2 = std::vector<std::string>{"input1"};

EXPECT_THROW(llm::process_input_names(user_inputs_2, input_names_2), std::invalid_argument);
}
Loading