-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-nodes-and-return-forest-test.cpp
63 lines (49 loc) · 1.35 KB
/
delete-nodes-and-return-forest-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
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <vector>
#include <gtest/gtest.h>
// clang-format off
#include "util/Forest.cpp"
// clang-format on
#include "delete-nodes-and-return-forest.cpp"
using namespace std;
class DeleteNodesAndReturnForest : public ::testing::Test {
public:
DeleteNodesAndReturnForest()
: root(nullptr), expected_size(0), actual_size(0) {}
vector<int> to_delete;
TreeNode *root;
vector<TreeNode *> output;
string input;
unordered_set<string> expected_uss;
unordered_set<string> actual_uss;
Solution soln;
size_t expected_size;
size_t actual_size;
void mSetUp() {
// needs to be called from within test case
root = TreeNode_from_string(input);
}
void doTest() {
output = soln.delNodes(root, to_delete);
actual_size = output.size();
EXPECT_EQ(actual_size, expected_size);
vector<string> vs_output = Forest_to_string(output);
for (auto &s : vs_output) {
actual_uss.insert(s);
}
EXPECT_EQ(actual_uss, expected_uss);
}
virtual void TearDown() override { Forest_cleanup(output); }
};
TEST_F(DeleteNodesAndReturnForest, Test_1_2_3_4_5_6_7__3_5) {
input = "[1,2,3,4,5,6,7]";
to_delete = vector<int>{{3, 5}};
expected_size = 3;
expected_uss = unordered_set<string>{{"[1,2,null,4]", "[6]", "[7]"}};
mSetUp();
doTest();
}