From 98b0294f80cc4670a655565a2453da6650e80282 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Sat, 12 Jul 2025 21:47:01 +0800 Subject: [PATCH] 1900 --- include/solution/1900.h | 11 +++++++++++ src/1900.c | 6 ++++++ tests/test_1900.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 include/solution/1900.h create mode 100644 src/1900.c create mode 100644 tests/test_1900.cpp diff --git a/include/solution/1900.h b/include/solution/1900.h new file mode 100644 index 0000000..f775201 --- /dev/null +++ b/include/solution/1900.h @@ -0,0 +1,11 @@ +#ifndef INC_1900_H +#define INC_1900_H +#ifdef __cplusplus +extern "C" +{ +#endif + int *earliestAndLatest(int n, int firstPlayer, int secondPlayer, int *returnSize); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/src/1900.c b/src/1900.c new file mode 100644 index 0000000..4a96a29 --- /dev/null +++ b/src/1900.c @@ -0,0 +1,6 @@ +#include + +int *earliestAndLatest(int n, int firstPlayer, int secondPlayer, int *returnSize) +{ + return 0; +} \ No newline at end of file diff --git a/tests/test_1900.cpp b/tests/test_1900.cpp new file mode 100644 index 0000000..b09b59d --- /dev/null +++ b/tests/test_1900.cpp @@ -0,0 +1,34 @@ +#include +#include + +class EarliestAndLatestTest : public ::testing::Test +{ + protected: + void AssertResult(int *result, int resultSize, const std::vector &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 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 expected = {1, 1}; + AssertResult(result, returnSize, expected); +} \ No newline at end of file