From 63431b6824c3ecabff7ec6d4cb17102fbe10ec91 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 24 Apr 2023 14:33:45 +0200 Subject: [PATCH] u01: Add test case for very short loop This actually worked, but it is nice to have it verified nonetheless. --- u01/tests.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/u01/tests.cpp b/u01/tests.cpp index 650dcf1..d262b5e 100644 --- a/u01/tests.cpp +++ b/u01/tests.cpp @@ -178,6 +178,30 @@ TEST_CASE("Cycle detection (iterative)") { delete n; } +TEST_CASE("Very short cycle detection") { + node *n = new node("foo"); + n->add_child(n); + + std::stringstream output; + output << n->print_recursive(); + + REQUIRE(output.str() == "foo [↝ foo]\n"); + + delete n; +} + +TEST_CASE("Very short cycle detection (iterative)") { + node *n = new node("foo"); + n->add_child(n); + + std::stringstream output; + output << n->print_iterative(); + + REQUIRE(output.str() == "foo [↝ foo]\n"); + + delete n; +} + TEST_CASE("Equivalence of iterative and recursive print") { node *n = new node(); REQUIRE(n->print_recursive() == n->print_iterative());