Skip to content

Commit

Permalink
Add Motti Lanzkron's fourth test case.
Browse files Browse the repository at this point in the history
From the comments to Herb's original post.
This test case ensures that the solution doesn't over-deallocate.

Credit goes entirely to Motti, of course.
  • Loading branch information
lballabio committed Oct 7, 2016
1 parent cd844e5 commit c1061c8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ bool TestCase3() {
return Counter::count() == 4;
}

bool TestCase4() {
MyGraph g;
{
auto a = MyGraph::MakeNode();
g.SetRoot(a);
auto b = MyGraph::MakeNode();
a->AddChild(b);
auto c = MyGraph::MakeNode();
b->AddChild(c);
auto d = MyGraph::MakeNode();
b->AddChild(d);
d->AddChild(b);
d->RemoveChild(b);
}
g.ShrinkToFit();
return Counter::count() == 4;
}

int main() {
cout.setf(ios::boolalpha);

Expand All @@ -153,5 +171,8 @@ int main() {
bool passed3 = TestCase3();
cout << passed3 << endl;

bool passed4 = TestCase4();
cout << passed4 << endl;

return 0;
}

0 comments on commit c1061c8

Please sign in to comment.