Files
leetcode/tests/test_1957.cpp
2025-07-23 20:19:00 +08:00

37 lines
880 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <gtest/gtest.h>
#include <solution/1957.h>
#include <string>
class MakeFancyStringTest : public ::testing::Test
{
protected:
void AssertFancyString(const std::string &input, const std::string &expected)
{
char *c_input = strdup(input.c_str()); // 复制一份以防原始修改
char *result = makeFancyString(c_input);
ASSERT_STREQ(result, expected.c_str());
// 如函数返回的是 malloc 分配的,则应释放
// free(result);
free(c_input);
}
};
// 示例 1leeetcode → leetcode
TEST_F(MakeFancyStringTest, Example1)
{
AssertFancyString("leeetcode", "leetcode");
}
// 示例 2aaabaaaa → aabaa
TEST_F(MakeFancyStringTest, Example2)
{
AssertFancyString("aaabaaaa", "aabaa");
}
// 示例 3aab → aab
TEST_F(MakeFancyStringTest, Example3)
{
AssertFancyString("aab", "aab");
}