1900
This commit is contained in:
11
include/solution/1900.h
Normal file
11
include/solution/1900.h
Normal 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
6
src/1900.c
Normal 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
34
tests/test_1900.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user