Files
leetcode/tests/test_303.cpp
2025-07-14 20:57:04 +08:00

38 lines
830 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <gtest/gtest.h>
#include <solution/303.h>
class NumArrayTest : public ::testing::Test
{
protected:
NumArray *numArray = nullptr;
void SetUp() override
{
int init[] = {-2, 0, 3, -5, 2, -1};
numArray = numArrayCreate(init, sizeof(init) / sizeof(int));
ASSERT_NE(numArray, nullptr); // 确保初始化成功
}
void TearDown() override
{
numArrayFree(numArray);
}
};
// 示例测试sumRange(0, 2) == 1
TEST_F(NumArrayTest, SumRange_0_2)
{
EXPECT_EQ(numArraySumRange(numArray, 0, 2), 1);
}
// 示例测试sumRange(2, 5) == -1
TEST_F(NumArrayTest, SumRange_2_5)
{
EXPECT_EQ(numArraySumRange(numArray, 2, 5), -1);
}
// 示例测试sumRange(0, 5) == -3
TEST_F(NumArrayTest, SumRange_0_5)
{
EXPECT_EQ(numArraySumRange(numArray, 0, 5), -3);
}