From c1061c8a262d4ce8c042de3294b7857bd10dafc3 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Fri, 7 Oct 2016 23:58:45 +0200 Subject: [PATCH] Add Motti Lanzkron's fourth test case. 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. --- test_graph.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test_graph.cpp b/test_graph.cpp index 57e6753..9b55d62 100644 --- a/test_graph.cpp +++ b/test_graph.cpp @@ -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); @@ -153,5 +171,8 @@ int main() { bool passed3 = TestCase3(); cout << passed3 << endl; + bool passed4 = TestCase4(); + cout << passed4 << endl; + return 0; }