Files
leetcode/tests/test_1900.cpp
2025-07-12 21:47:01 +08:00

34 lines
1.0 KiB
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/1900.h>
class EarliestAndLatestTest : public ::testing::Test
{
protected:
void AssertResult(int *result, int resultSize, const std::vector<int> &expected)
{
ASSERT_EQ(resultSize, expected.size());
for (int i = 0; i < resultSize; ++i)
{
EXPECT_EQ(result[i], expected[i]) << "Mismatch at index " << i;
}
free(result); // 符合题意:假设函数使用 malloc 分配内存
}
};
// Test 1: 输入n = 11, firstPlayer = 2, secondPlayer = 4输出[3,4]
TEST_F(EarliestAndLatestTest, Test1)
{
int returnSize = 0;
int *result = earliestAndLatest(11, 2, 4, &returnSize);
std::vector<int> expected = {3, 4};
AssertResult(result, returnSize, expected);
}
// Test 2: 输入n = 5, firstPlayer = 1, secondPlayer = 5输出[1,1]
TEST_F(EarliestAndLatestTest, Test2)
{
int returnSize = 0;
int *result = earliestAndLatest(5, 1, 5, &returnSize);
std::vector<int> expected = {1, 1};
AssertResult(result, returnSize, expected);
}