746
This commit is contained in:
47
tests/test_746.cpp
Normal file
47
tests/test_746.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <solution/746.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
// Tests for minCostClimbingStairs (LeetCode 746)
|
||||
class MinCostClimbingStairsTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void AssertMinCost(const std::vector<int> &input, int expected)
|
||||
{
|
||||
int *cost = new int[input.size()];
|
||||
std::copy(input.begin(), input.end(), cost);
|
||||
|
||||
int result = minCostClimbingStairs(cost, (int)input.size());
|
||||
ASSERT_EQ(result, expected);
|
||||
|
||||
delete[] cost;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(MinCostClimbingStairsTest, Example1)
|
||||
{
|
||||
// cost = [10,15,20] -> expected 15
|
||||
AssertMinCost({10, 15, 20}, 15);
|
||||
}
|
||||
|
||||
TEST_F(MinCostClimbingStairsTest, Example2)
|
||||
{
|
||||
// cost = [1,100,1,1,1,100,1,1,100,1] -> expected 6
|
||||
AssertMinCost({1, 100, 1, 1, 1, 100, 1, 1, 100, 1}, 6);
|
||||
}
|
||||
|
||||
TEST_F(MinCostClimbingStairsTest, TwoSteps)
|
||||
{
|
||||
// Two steps: choose cheaper one
|
||||
AssertMinCost({5, 3}, 3);
|
||||
}
|
||||
|
||||
TEST_F(MinCostClimbingStairsTest, ZeroCost)
|
||||
{
|
||||
AssertMinCost({0, 0, 0}, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user