-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo-sum.cpp
More file actions
51 lines (41 loc) · 1.26 KB
/
two-sum.cpp
File metadata and controls
51 lines (41 loc) · 1.26 KB
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
48
49
50
51
#include "leetcode/problems/two-sum.h"
#include "gtest/gtest.h"
namespace leetcode {
namespace problem_1 {
class TwoSumTest : public ::testing::TestWithParam<string> {
protected:
void SetUp() override { solution.setStrategy(GetParam()); }
TwoSumSolution solution;
};
TEST_P(TwoSumTest, Example1) {
vector<int> nums = {2, 7, 11, 15};
int target = 9;
vector<int> expected = {0, 1};
vector<int> result = solution.twoSum(nums, target);
sort(result.begin(), result.end());
sort(expected.begin(), expected.end());
EXPECT_EQ(expected, result);
}
TEST_P(TwoSumTest, Example2) {
vector<int> nums = {3, 2, 4};
int target = 6;
vector<int> expected = {1, 2};
vector<int> result = solution.twoSum(nums, target);
sort(result.begin(), result.end());
sort(expected.begin(), expected.end());
EXPECT_EQ(expected, result);
}
TEST_P(TwoSumTest, Example3) {
vector<int> nums = {3, 3};
int target = 6;
vector<int> expected = {0, 1};
vector<int> result = solution.twoSum(nums, target);
sort(result.begin(), result.end());
sort(expected.begin(), expected.end());
EXPECT_EQ(expected, result);
}
INSTANTIATE_TEST_SUITE_P(
LeetCode, TwoSumTest,
::testing::ValuesIn(TwoSumSolution().getStrategyNames()));
} // namespace problem_1
} // namespace leetcode