This commit is contained in:
2025-07-12 21:47:01 +08:00
parent 58a56e3926
commit 98b0294f80
3 changed files with 51 additions and 0 deletions

11
include/solution/1900.h Normal file
View File

@@ -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

6
src/1900.c Normal file
View File

@@ -0,0 +1,6 @@
#include <solution/1900.h>
int *earliestAndLatest(int n, int firstPlayer, int secondPlayer, int *returnSize)
{
return 0;
}

34
tests/test_1900.cpp Normal file
View File

@@ -0,0 +1,34 @@
#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);
}