Updated recursive template sequence diagram test case

This commit is contained in:
Bartek Kryza
2022-12-10 11:24:00 +01:00
parent 8e3a7ed436
commit 80e94c2e32
2 changed files with 26 additions and 17 deletions

View File

@@ -6,15 +6,22 @@ namespace t20018 {
template <int N> struct Factorial { template <int N> struct Factorial {
static const int value = N * Factorial<N - 1>::value; static const int value = N * Factorial<N - 1>::value;
static void print() { Factorial<N - 1>::print(); } static void print(int answer) { Factorial<N - 1>::print(answer); }
}; };
template <> struct Factorial<0> { template <> struct Factorial<0> {
static const int value = 1; 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 <typename T, int N = T::value> struct Answer {
static void print() { T::print(N); }
};
void tmain() { Answer<Factorial<5>>::print(); }
} }
} }

View File

@@ -35,22 +35,24 @@ TEST_CASE("t20018", "[test-case][sequence]")
REQUIRE_THAT(puml, EndsWith("@enduml\n")); REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist // Check if all calls exist
REQUIRE_THAT( REQUIRE_THAT(puml,
puml, HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print()__")); HasCall(_A("tmain()"), _A("Answer<Factorial<5>,120>"), "__print()__"));
REQUIRE_THAT(puml,
HasCall(_A("Answer<Factorial<5>,120>"), _A("Factorial<5>"),
"__print(int)__"));
REQUIRE_THAT(puml,
HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__"));
REQUIRE_THAT(puml, REQUIRE_THAT(puml,
!HasCallWithResponse( !HasCallWithResponse(
_A("Factorial<5>"), _A("Factorial<4>"), "__print()__")); _A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__"));
REQUIRE_THAT( REQUIRE_THAT(puml,
puml, HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print()__")); HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print(int)__"));
REQUIRE_THAT( REQUIRE_THAT(puml,
puml, HasCall(_A("Factorial<3>"), _A("Factorial<2>"), "__print()__")); HasCall(_A("Factorial<3>"), _A("Factorial<2>"), "__print(int)__"));
REQUIRE_THAT( REQUIRE_THAT(puml,
puml, HasCall(_A("Factorial<2>"), _A("Factorial<1>"), "__print()__")); HasCall(_A("Factorial<2>"), _A("Factorial<1>"), "__print(int)__"));
REQUIRE_THAT( REQUIRE_THAT(puml,
puml, HasCall(_A("Factorial<1>"), _A("Factorial<0>"), "__print()__")); HasCall(_A("Factorial<1>"), _A("Factorial<0>"), "__print(int)__"));
// REQUIRE_THAT(puml, HasCall("A", "log_result"));
// REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3"));
save_puml( save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml); "./" + config.output_directory() + "/" + diagram->name + ".puml", puml);