#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);
}