From 80e94c2e3205bd2454676adf2dd432977ca93213 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sat, 10 Dec 2022 11:24:00 +0100 Subject: [PATCH] Updated recursive template sequence diagram test case --- tests/t20018/t20018.cc | 13 ++++++++++--- tests/t20018/test_case.h | 30 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/t20018/t20018.cc b/tests/t20018/t20018.cc index 6d36524c..d2f7a7d2 100644 --- a/tests/t20018/t20018.cc +++ b/tests/t20018/t20018.cc @@ -6,15 +6,22 @@ namespace t20018 { template struct Factorial { static const int value = N * Factorial::value; - static void print() { Factorial::print(); } + static void print(int answer) { Factorial::print(answer); } }; template <> struct Factorial<0> { static const int value = 1; - static void print() { std::cout << "Hello world\n"; } + static void print(int answer) + { + std::cout << "The answer is " << answer << "\n"; + } }; -void tmain() { Factorial<5>::print(); } +template struct Answer { + static void print() { T::print(N); } +}; + +void tmain() { Answer>::print(); } } } \ No newline at end of file diff --git a/tests/t20018/test_case.h b/tests/t20018/test_case.h index 18734c5d..22e4522a 100644 --- a/tests/t20018/test_case.h +++ b/tests/t20018/test_case.h @@ -35,22 +35,24 @@ TEST_CASE("t20018", "[test-case][sequence]") REQUIRE_THAT(puml, EndsWith("@enduml\n")); // Check if all calls exist - REQUIRE_THAT( - puml, HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print()__")); + REQUIRE_THAT(puml, + HasCall(_A("tmain()"), _A("Answer,120>"), "__print()__")); + REQUIRE_THAT(puml, + HasCall(_A("Answer,120>"), _A("Factorial<5>"), + "__print(int)__")); + REQUIRE_THAT(puml, + HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__")); REQUIRE_THAT(puml, !HasCallWithResponse( - _A("Factorial<5>"), _A("Factorial<4>"), "__print()__")); - REQUIRE_THAT( - puml, HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print()__")); - REQUIRE_THAT( - puml, HasCall(_A("Factorial<3>"), _A("Factorial<2>"), "__print()__")); - REQUIRE_THAT( - puml, HasCall(_A("Factorial<2>"), _A("Factorial<1>"), "__print()__")); - REQUIRE_THAT( - puml, HasCall(_A("Factorial<1>"), _A("Factorial<0>"), "__print()__")); - - // REQUIRE_THAT(puml, HasCall("A", "log_result")); - // REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3")); + _A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__")); + REQUIRE_THAT(puml, + HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print(int)__")); + REQUIRE_THAT(puml, + HasCall(_A("Factorial<3>"), _A("Factorial<2>"), "__print(int)__")); + REQUIRE_THAT(puml, + HasCall(_A("Factorial<2>"), _A("Factorial<1>"), "__print(int)__")); + REQUIRE_THAT(puml, + HasCall(_A("Factorial<1>"), _A("Factorial<0>"), "__print(int)__")); save_puml( "./" + config.output_directory() + "/" + diagram->name + ".puml", puml);