// This file is generated by mkfile.py
// Date: 2026-03-09

#include <fstream>
#include <gtest/gtest.h>
#include <solution/219.h>

int *loadArrayFromFile(const std::string &path, int *len)
{
    std::ifstream file(path);
    std::string s;

    if (!file.is_open())
        return NULL;

    std::getline(file, s);

    *len = 1;
    for (char c : s)
        if (c == ',')
            (*len)++;

    int *arr = new int[*len];

    int index = 0;
    int num = 0;
    bool reading = false;

    for (char c : s)
    {
        if (isdigit(c))
        {
            num = num * 10 + (c - '0');
            reading = true;
        }
        else
        {
            if (reading)
            {
                arr[index++] = num;
                num = 0;
                reading = false;
            }
        }
    }

    return arr;
}

// 示例 1
TEST(ContainsNearbyDuplicateTest, Example1)
{
    int nums[] = {1, 2, 3, 1};
    bool result = containsNearbyDuplicate(nums, 4, 3);
    EXPECT_TRUE(result);
}

// 示例 2
TEST(ContainsNearbyDuplicateTest, Example2)
{
    int nums[] = {1, 0, 1, 1};
    bool result = containsNearbyDuplicate(nums, 4, 1);
    EXPECT_TRUE(result);
}

// 示例 3
TEST(ContainsNearbyDuplicateTest, Example3)
{
    int nums[] = {1, 2, 3, 1, 2, 3};
    bool result = containsNearbyDuplicate(nums, 6, 2);
    EXPECT_FALSE(result);
}

TEST(ContainsNearbyDuplicateTest, Example4)
{
    int nums[] = {1, 5, 1, 0};
    bool result = containsNearbyDuplicate(nums, 4, 2);
    EXPECT_TRUE(result);
}

TEST(ContainsNearbyDuplicateTest, Example5)
{
    int nums[] = {0, 1, 2, 3, 4, 0, 0, 7, 8, 9, 10, 11, 12, 0};
    bool result = containsNearbyDuplicate(nums, 14, 1);
    EXPECT_TRUE(result);
}

TEST(ContainsNearbyDuplicateTest, Example6)
{
    int len;
    auto arr = loadArrayFromFile("../../file/test_219_6", &len);
    ASSERT_TRUE(arr);
    bool result = containsNearbyDuplicate(arr, len, 35000);
    EXPECT_FALSE(result);
    delete[] arr;
}

TEST(ContainsNearbyDuplicateTest, Example7)
{
    int len;
    auto arr = loadArrayFromFile("../../file/test_219_7", &len);
    ASSERT_TRUE(arr);
    bool result = containsNearbyDuplicate(arr, len, 99999);
    EXPECT_TRUE(result);
    delete[] arr;
}