tests.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * @file tests/mixed/tests.cpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #include <tests/mixed/graph_manager.hpp>
  26. #include <tests/mixed/models.hpp>
  27. #include <artis-star/common/RootCoordinator.hpp>
  28. #define CATCH_CONFIG_MAIN
  29. #include <tests/catch.hpp>
  30. using namespace artis::tests::mixed;
  31. using namespace artis::common;
  32. TEST_CASE("mixed/hierachical", "run") {
  33. artis::common::context::Context<artis::common::DoubleTime> context(0, 100);
  34. artis::common::RootCoordinator<
  35. DoubleTime,
  36. artis::pdevs::Coordinator<
  37. DoubleTime,
  38. RootGraphManager>
  39. > rc(context, "root");
  40. artis::common::Trace<DoubleTime>::trace().clear();
  41. rc.run(context);
  42. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  43. filter_model_name("a1").
  44. filter_function_type(artis::common::FunctionType::START).size() == 1);
  45. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  46. filter_model_name("b1").
  47. filter_function_type(artis::common::FunctionType::START).size() == 1);
  48. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  49. filter_model_name("a2").
  50. filter_function_type(artis::common::FunctionType::START).size() == 1);
  51. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  52. filter_model_name("b2").
  53. filter_function_type(artis::common::FunctionType::START).size() == 1);
  54. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  55. filter_model_name("a1").
  56. filter_function_type(artis::common::FunctionType::DELTA_EXT).size() == 0);
  57. for (double t = 0; t <= 100; t = t + 3) {
  58. REQUIRE(artis::common::Trace<
  59. DoubleTime > ::trace().elements().
  60. filter_model_name("a1").filter_time(t).
  61. filter_level_type(artis::common::LevelType::USER).
  62. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  63. REQUIRE(artis::common::Trace<
  64. DoubleTime > ::trace().elements().
  65. filter_model_name("a1").filter_time(t).
  66. filter_function_type(artis::common::FunctionType::DELTA_INT).size() == 1);
  67. if (t == 0) {
  68. REQUIRE(artis::common::Trace<
  69. DoubleTime > ::trace().elements().
  70. filter_model_name("a1").filter_time(t).
  71. filter_function_type(artis::common::FunctionType::TA).size() == 2);
  72. } else {
  73. REQUIRE(artis::common::Trace<
  74. DoubleTime > ::trace().elements().
  75. filter_model_name("a1").filter_time(t).
  76. filter_function_type(artis::common::FunctionType::TA).size() == 1);
  77. }
  78. }
  79. for (double t = 0; t <= 100; t = t + 3) {
  80. REQUIRE(artis::common::Trace<
  81. DoubleTime > ::trace().elements().
  82. filter_model_name("b1").filter_time(t).
  83. filter_level_type(artis::common::LevelType::USER).
  84. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  85. REQUIRE(artis::common::Trace<
  86. DoubleTime > ::trace().elements().
  87. filter_model_name("b1").filter_time(t).
  88. filter_function_type(artis::common::FunctionType::DELTA_INT).size() == 1);
  89. REQUIRE(artis::common::Trace<
  90. DoubleTime > ::trace().elements().
  91. filter_model_name("b1").filter_time(t).
  92. filter_function_type(artis::common::FunctionType::TA).size() == 2);
  93. REQUIRE(artis::common::Trace<
  94. DoubleTime > ::trace().elements().
  95. filter_model_name("b1").filter_time(t).
  96. filter_function_type(artis::common::FunctionType::DELTA_EXT).size() == 1);
  97. }
  98. for (unsigned int t = 0; t <= 100; t += 2) {
  99. REQUIRE(artis::common::Trace<
  100. DoubleTime > ::trace().elements().
  101. filter_model_name("a2").filter_time(t).
  102. filter_level_type(artis::common::LevelType::USER).
  103. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  104. REQUIRE(artis::common::Trace<
  105. DoubleTime > ::trace().elements().
  106. filter_model_name("a2").filter_time(t).
  107. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  108. }
  109. REQUIRE(artis::common::Trace<
  110. DoubleTime > ::trace().elements().
  111. filter_model_name("a2").filter_time(0).
  112. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  113. 0).get_comment()
  114. == "x = { ( 0 , a2 , 0 ) }");
  115. REQUIRE(artis::common::Trace<
  116. DoubleTime > ::trace().elements().
  117. filter_model_name("a2").filter_time(2).
  118. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  119. 0).get_comment()
  120. == "x = { }");
  121. REQUIRE(artis::common::Trace<
  122. DoubleTime > ::trace().elements().
  123. filter_model_name("a2").filter_time(4).
  124. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  125. 0).get_comment()
  126. == "x = { ( 0 , a2 , 2 ) }");
  127. REQUIRE(artis::common::Trace<
  128. DoubleTime > ::trace().elements().
  129. filter_model_name("a2").filter_time(6).
  130. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  131. 0).get_comment()
  132. == "x = { }");
  133. REQUIRE(artis::common::Trace<
  134. DoubleTime > ::trace().elements().
  135. filter_model_name("a2").filter_time(8).
  136. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  137. 0).get_comment()
  138. == "x = { ( 0 , a2 , 3 ) }");
  139. REQUIRE(artis::common::Trace<
  140. DoubleTime > ::trace().elements().
  141. filter_model_name("a2").filter_time(10).
  142. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  143. 0).get_comment()
  144. == "x = { ( 0 , a2 , 4 ) }");
  145. REQUIRE(artis::common::Trace<
  146. DoubleTime > ::trace().elements().
  147. filter_model_name("a2").filter_time(12).
  148. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  149. 0).get_comment()
  150. == "x = { }");
  151. for (unsigned int t = 0; t <= 100; t += 2) {
  152. REQUIRE(artis::common::Trace<
  153. DoubleTime > ::trace().elements().
  154. filter_model_name("b2").filter_time(t).
  155. filter_level_type(artis::common::LevelType::USER).
  156. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  157. REQUIRE(artis::common::Trace<
  158. DoubleTime > ::trace().elements().
  159. filter_model_name("b2").filter_time(t).
  160. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  161. }
  162. }