#include <gtest/gtest.h>
#include <solution/1353.h>

// 辅助函数：创建二维数组
int **create2DArray(const std::vector<std::vector<int>> &input, int *colSizeArray)
{
    int **arr = new int *[input.size()];
    for (size_t i = 0; i < input.size(); ++i)
    {
        arr[i] = new int[input[i].size()];
        colSizeArray[i] = static_cast<int>(input[i].size());
        for (size_t j = 0; j < input[i].size(); ++j)
        {
            arr[i][j] = input[i][j];
        }
    }
    return arr;
}

// 辅助函数：释放二维数组
void free2DArray(int **arr, int size)
{
    for (int i = 0; i < size; ++i)
    {
        delete[] arr[i];
    }
    delete[] arr;
}

// Test1
TEST(MaxEventsTest, Test1)
{
    std::vector<std::vector<int>> input = {{1, 2}, {2, 3}, {3, 4}};
    int eventsSize = static_cast<int>(input.size());
    int *eventsColSize = new int[eventsSize];
    int **events = create2DArray(input, eventsColSize);

    int expected = 3;
    EXPECT_EQ(maxEvents(events, eventsSize, eventsColSize), expected);

    free2DArray(events, eventsSize);
    delete[] eventsColSize;
}

// Test2
TEST(MaxEventsTest, Test2)
{
    std::vector<std::vector<int>> input = {{1, 2}, {2, 3}, {3, 4}, {1, 2}};
    int eventsSize = static_cast<int>(input.size());
    int *eventsColSize = new int[eventsSize];
    int **events = create2DArray(input, eventsColSize);

    int expected = 4;
    EXPECT_EQ(maxEvents(events, eventsSize, eventsColSize), expected);

    free2DArray(events, eventsSize);
    delete[] eventsColSize;
}