-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-and-replace-pattern-test.cpp
70 lines (51 loc) · 1.8 KB
/
find-and-replace-pattern-test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
#include <exception>
#include <gtest/gtest.h>
#include "find-and-replace-pattern.cpp"
TEST(FindAndReplacePattern, Test_abc_deq_mee_aqq_dkd_ccc__abb) {
vector<string> words({"abc", "deq", "mee", "aqq", "dkd", "ccc"});
string pattern("abb");
vector<string> expected_sv({"mee", "aqq"});
vector<string> actual_sv = Solution().findAndReplacePattern(words, pattern);
sort(actual_sv.begin(), actual_sv.end());
sort(expected_sv.begin(), expected_sv.end());
EXPECT_EQ(actual_sv, expected_sv);
}
TEST(FindAndReplacePattern, Test_boo_boo__see) {
vector<string> words({"boo", "boo", "bar"});
string pattern("see");
vector<string> expected_sv({"boo", "boo"});
vector<string> actual_sv = Solution().findAndReplacePattern(words, pattern);
sort(actual_sv.begin(), actual_sv.end());
sort(expected_sv.begin(), expected_sv.end());
EXPECT_EQ(actual_sv, expected_sv);
}
TEST(FindAndReplacePattern, Test_t_k_g_n_k__v) {
vector<string> words({"t", "k", "g", "n", "k"});
string pattern("v");
vector<string> expected_sv(words);
vector<string> actual_sv = Solution().findAndReplacePattern(words, pattern);
sort(actual_sv.begin(), actual_sv.end());
sort(expected_sv.begin(), expected_sv.end());
EXPECT_EQ(actual_sv, expected_sv);
}
TEST(FindAndReplacePattern, Test_abc__d) {
exception_ptr e = nullptr;
try {
vector<string> words({"abc"});
string pattern("d");
vector<string> expected_sv(words);
vector<string> actual_sv = Solution().findAndReplacePattern(words, pattern);
sort(actual_sv.begin(), actual_sv.end());
sort(expected_sv.begin(), expected_sv.end());
EXPECT_EQ(actual_sv, expected_sv);
} catch (...) {
e = current_exception();
}
EXPECT_FALSE(e == nullptr);
}