|
| 1 | +import unittest |
| 2 | +from cost import Solution |
| 3 | + |
| 4 | +class TestMinCostClimbingStairs(unittest.TestCase): |
| 5 | + def setUp(self): |
| 6 | + self.s = Solution() |
| 7 | + |
| 8 | + def test_example_1(self): |
| 9 | + cost = [10, 15, 20] |
| 10 | + expected = 15 |
| 11 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 12 | + |
| 13 | + def test_example_2(self): |
| 14 | + cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1] |
| 15 | + expected = 6 |
| 16 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 17 | + |
| 18 | + def test_two_elements_take_cheapest(self): |
| 19 | + cost = [5, 3] |
| 20 | + expected = 3 |
| 21 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 22 | + |
| 23 | + def test_two_elements_equal(self): |
| 24 | + cost = [7, 7] |
| 25 | + expected = 7 |
| 26 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 27 | + |
| 28 | + def test_increasing_costs(self): |
| 29 | + cost = [1, 2, 3, 4, 5] |
| 30 | + # Best: 2 + 4 = 6 |
| 31 | + expected = 6 |
| 32 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 33 | + |
| 34 | + def test_decreasing_costs(self): |
| 35 | + cost = [10, 8, 6, 4, 2] |
| 36 | + # Best: start 1 → skip → 3 → skip → top = 8 + 4 = 12 |
| 37 | + expected = 12 |
| 38 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 39 | + |
| 40 | + def test_zero_costs(self): |
| 41 | + cost = [0, 0, 0, 0] |
| 42 | + expected = 0 |
| 43 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 44 | + |
| 45 | + def test_large_values(self): |
| 46 | + cost = [999] * 20 |
| 47 | + # Always just pick any consistent route: all same → 999 * ceil(n/2) |
| 48 | + expected = 999 * 10 |
| 49 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 50 | + |
| 51 | + def test_single_step_zero_then_big(self): |
| 52 | + cost = [0, 100, 0, 100, 0] |
| 53 | + expected = 0 |
| 54 | + self.assertEqual(self.s.minCostClimbingStairs(cost), expected) |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + unittest.main() |
0 commit comments