-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path122.cpp
47 lines (42 loc) · 944 Bytes
/
122.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cassert>
#include <climits>
#include <gtest/gtest.h>
#include <vector>
using namespace std;
class Solution {
public:
int maxProfit(vector<int> &prices)
{
int profit = 0;
for (int i = 1; i < prices.size(); i++) {
if (prices[i] > prices[i - 1]) {
profit += prices[i] - prices[i - 1];
}
}
return profit;
}
};
class Testing : public testing::Test {
public:
Solution solution;
void SetUp() {}
void TearDown() {}
};
TEST_F(Testing, Case1)
{
vector<int> prices = {7, 1, 5, 3, 6, 4};
int result = 7;
EXPECT_EQ(solution.maxProfit(prices), result);
}
TEST_F(Testing, Case2)
{
vector<int> prices = {1, 2, 3, 4, 5};
int result = 4;
EXPECT_EQ(solution.maxProfit(prices), result);
}
TEST_F(Testing, Case3)
{
vector<int> prices = {7, 6, 4, 3, 1};
int result = 0;
EXPECT_EQ(solution.maxProfit(prices), result);
}