//
// Created by gint on 2025/7/11.
//
#include <solution/3169.h>

#include <gtest/gtest.h>
#include <vector>

// 工具函数：创建二维数组
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(CountDaysTest, Test1)
{
    int days = 10;
    std::vector<std::vector<int>> input = {{5, 7}, {1, 3}, {9, 10}};
    int meetingsSize = static_cast<int>(input.size());
    int *meetingsColSize = new int[meetingsSize];
    int **meetings = create2DArray(input, meetingsColSize);

    int expected = 2;
    EXPECT_EQ(countDays(days, meetings, meetingsSize, meetingsColSize), expected);

    free2DArray(meetings, meetingsSize);
    delete[] meetingsColSize;
}

// Test2
TEST(CountDaysTest, Test2)
{
    int days = 5;
    std::vector<std::vector<int>> input = {{2, 4}, {1, 3}};
    int meetingsSize = static_cast<int>(input.size());
    int *meetingsColSize = new int[meetingsSize];
    int **meetings = create2DArray(input, meetingsColSize);

    int expected = 1;
    EXPECT_EQ(countDays(days, meetings, meetingsSize, meetingsColSize), expected);

    free2DArray(meetings, meetingsSize);
    delete[] meetingsColSize;
}

// Test3
TEST(CountDaysTest, Test3)
{
    int days = 6;
    std::vector<std::vector<int>> input = {{1, 6}};
    int meetingsSize = static_cast<int>(input.size());
    int *meetingsColSize = new int[meetingsSize];
    int **meetings = create2DArray(input, meetingsColSize);

    int expected = 0;
    EXPECT_EQ(countDays(days, meetings, meetingsSize, meetingsColSize), expected);

    free2DArray(meetings, meetingsSize);
    delete[] meetingsColSize;
}

TEST(CountDaysTest, Test4)
{
    int days = 8;
    std::vector<std::vector<int>> input = {{3, 4}, {4, 8}, {2, 5}, {3, 8}};
    int meetingsSize = static_cast<int>(input.size());
    int *meetingsColSize = new int[meetingsSize];
    int **meetings = create2DArray(input, meetingsColSize);

    int expected = 1;
    EXPECT_EQ(countDays(days, meetings, meetingsSize, meetingsColSize), expected);

    free2DArray(meetings, meetingsSize);
    delete[] meetingsColSize;
}
