Files
leetcode/tests/test_1717.cpp
2025-07-24 18:31:35 +08:00

30 lines
734 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/1717.h>
class MaximumGainTest : public ::testing::Test
{
protected:
void AssertMaximumGain(const std::string &input, int x, int y, int expected)
{
char *s = strdup(input.c_str()); // 复制字符串,防止修改原始数据
int result = maximumGain(s, x, y);
ASSERT_EQ(result, expected);
free(s);
}
};
// 示例 1
TEST_F(MaximumGainTest, Example1)
{
// 输入s = "cdbcbbaaabab", x = 4, y = 5
// 输出19
AssertMaximumGain("cdbcbbaaabab", 4, 5, 19);
}
// 示例 2
TEST_F(MaximumGainTest, Example2)
{
// 输入s = "aabbaaxybbaabb", x = 5, y = 4
// 输出20
AssertMaximumGain("aabbaaxybbaabb", 5, 4, 20);
}