Files
leetcode/tests/test_326.cpp
2025-07-17 20:55:46 +08:00

34 lines
826 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/326.h>
class IsPowerOfThreeTest : public ::testing::Test
{
protected:
void AssertIsPowerOfThree(int input, bool expected)
{
EXPECT_EQ(isPowerOfThree(input), expected);
}
};
// 示例测试用例
TEST_F(IsPowerOfThreeTest, ExampleTrueCases)
{
AssertIsPowerOfThree(27, true);
AssertIsPowerOfThree(9, true);
AssertIsPowerOfThree(1, true); // 3^0 = 1
AssertIsPowerOfThree(3, true);
}
TEST_F(IsPowerOfThreeTest, ExampleFalseCases)
{
AssertIsPowerOfThree(0, false);
AssertIsPowerOfThree(45, false);
AssertIsPowerOfThree(-3, false);
AssertIsPowerOfThree(10, false);
}
TEST_F(IsPowerOfThreeTest, EdgeCases)
{
AssertIsPowerOfThree(INT_MIN, false);
AssertIsPowerOfThree(INT_MAX, false); // INT_MAX = 2^31 - 1不是3的幂
}