mirror of https://github.com/google/gemma.cpp.git
Fix testing::SrcDir() path resolution in wheat_from_chaff_test
Also use a list of acceptable substring matchers for each question instead of just one PiperOrigin-RevId: 883198819
This commit is contained in:
parent
529c201eb6
commit
0110ddfee7
|
|
@ -46,11 +46,18 @@ static const char* kQuestions =
|
||||||
"Which people first proposed the quark model of hadrons, and when?";
|
"Which people first proposed the quark model of hadrons, and when?";
|
||||||
|
|
||||||
// All phrases in kAnswers must appear in the response in the order given for
|
// All phrases in kAnswers must appear in the response in the order given for
|
||||||
// the test to pass.
|
// the test to pass. Multiple acceptable answers can be provided for each
|
||||||
static const char* kAnswers[] = {
|
// expected phrase.
|
||||||
"a ship's anchor", "a dark forest", "an hour",
|
static const std::vector<std::vector<const char*>> kAnswers = {
|
||||||
"enormous sand", "castles", "limpet shells",
|
{"rusty metal", "ship's anchor"},
|
||||||
"Murray Gell-Mann", "George Zweig", "1964"};
|
{"dark forest"},
|
||||||
|
{"an hour"},
|
||||||
|
{"sand"},
|
||||||
|
{"castle"},
|
||||||
|
{"limpet shells"},
|
||||||
|
{"Murray Gell-Mann"},
|
||||||
|
{"George Zweig"},
|
||||||
|
{"1964"}};
|
||||||
|
|
||||||
std::string LoadPromptFile(const std::string& filename) {
|
std::string LoadPromptFile(const std::string& filename) {
|
||||||
// If the filename is empty, return an empty string.
|
// If the filename is empty, return an empty string.
|
||||||
|
|
@ -108,12 +115,22 @@ class GemmaTest : public ::testing::Test {
|
||||||
void TestExpectations(const std::string& response) {
|
void TestExpectations(const std::string& response) {
|
||||||
fprintf(stderr, "Response: '%s'\n", response.c_str());
|
fprintf(stderr, "Response: '%s'\n", response.c_str());
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
for (const char* answer : kAnswers) {
|
for (const auto& answer_group : kAnswers) {
|
||||||
auto found = response.find(answer, pos);
|
size_t earliest_pos = std::string::npos;
|
||||||
EXPECT_NE(found, std::string::npos)
|
const char* matched_answer = nullptr;
|
||||||
<< "Response does not contain " << answer;
|
for (const char* answer : answer_group) {
|
||||||
if (found != std::string::npos) {
|
auto found = response.find(answer, pos);
|
||||||
pos = found + strlen(answer);
|
if (found != std::string::npos &&
|
||||||
|
(earliest_pos == std::string::npos || found < earliest_pos)) {
|
||||||
|
earliest_pos = found;
|
||||||
|
matched_answer = answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EXPECT_NE(earliest_pos, std::string::npos)
|
||||||
|
<< "Response does not contain acceptable answers, e.g., "
|
||||||
|
<< answer_group[0];
|
||||||
|
if (earliest_pos != std::string::npos) {
|
||||||
|
pos = earliest_pos + strlen(matched_answer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_env->PrintProfileResults();
|
s_env->PrintProfileResults();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue