-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-duplicate-subtrees-test.cpp
52 lines (40 loc) · 1.03 KB
/
find-duplicate-subtrees-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
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <unordered_set>
#include <gtest/gtest.h>
#include "util/TreeNode.cpp"
#include "find-duplicate-subtrees.cpp"
class FindDuplicateSubtrees : public ::testing::Test {
public:
FindDuplicateSubtrees() : root(nullptr) {}
TreeNode *root;
vector<TreeNode *> output;
string input;
unordered_set<string> expected_uss;
unordered_set<string> actual_uss;
Solution soln;
void mSetUp() {
// needs to be called from within test case
root = TreeNode_from_string(input);
}
void doTest() {
output = soln.findDuplicateSubtrees(root);
for (auto &o : output) {
actual_uss.insert(TreeNode_to_string(o));
}
EXPECT_EQ(actual_uss, expected_uss);
}
virtual void TearDown() override { TreeNode_cleanup(root); }
};
TEST_F(FindDuplicateSubtrees, Test_1_2_3_4_null_2_4_null_null_4) {
input = "[1,2,3,4,null,2,4,null,null,4]";
expected_uss = unordered_set<string>({
"[2,4]",
"[4]",
});
mSetUp();
doTest();
}