tests.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. {
  34. artis::common::context::Context<artis::common::DoubleTime> context(0, 100);
  35. artis::common::RootCoordinator<
  36. DoubleTime,
  37. artis::pdevs::Coordinator<
  38. DoubleTime,
  39. RootGraphManager>
  40. > rc(context, "root");
  41. artis::common::Trace<DoubleTime>::trace().clear();
  42. rc.run(context);
  43. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  44. filter_model_name("a1").
  45. filter_function_type(artis::common::FunctionType::START).size() == 1);
  46. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  47. filter_model_name("b1").
  48. filter_function_type(artis::common::FunctionType::START).size() == 1);
  49. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  50. filter_model_name("a2").
  51. filter_function_type(artis::common::FunctionType::START).size() == 1);
  52. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  53. filter_model_name("b2").
  54. filter_function_type(artis::common::FunctionType::START).size() == 1);
  55. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  56. filter_model_name("a1").
  57. filter_function_type(artis::common::FunctionType::DELTA_EXT).size() == 0);
  58. for (double t = 0; t <= 100; t = t + 3) {
  59. REQUIRE(artis::common::Trace<
  60. DoubleTime > ::trace().elements().
  61. filter_model_name("a1").filter_time(t).
  62. filter_level_type(artis::common::LevelType::USER).
  63. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  64. REQUIRE(artis::common::Trace<
  65. DoubleTime > ::trace().elements().
  66. filter_model_name("a1").filter_time(t).
  67. filter_function_type(artis::common::FunctionType::DELTA_INT).size() == 1);
  68. if (t == 0) {
  69. REQUIRE(artis::common::Trace<
  70. DoubleTime > ::trace().elements().
  71. filter_model_name("a1").filter_time(t).
  72. filter_function_type(artis::common::FunctionType::TA).size() == 2);
  73. } else {
  74. REQUIRE(artis::common::Trace<
  75. DoubleTime > ::trace().elements().
  76. filter_model_name("a1").filter_time(t).
  77. filter_function_type(artis::common::FunctionType::TA).size() == 1);
  78. }
  79. }
  80. for (double t = 0; t <= 100; t = t + 3) {
  81. REQUIRE(artis::common::Trace<
  82. DoubleTime > ::trace().elements().
  83. filter_model_name("b1").filter_time(t).
  84. filter_level_type(artis::common::LevelType::USER).
  85. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  86. REQUIRE(artis::common::Trace<
  87. DoubleTime > ::trace().elements().
  88. filter_model_name("b1").filter_time(t).
  89. filter_function_type(artis::common::FunctionType::DELTA_INT).size() == 1);
  90. REQUIRE(artis::common::Trace<
  91. DoubleTime > ::trace().elements().
  92. filter_model_name("b1").filter_time(t).
  93. filter_function_type(artis::common::FunctionType::TA).size() == 2);
  94. REQUIRE(artis::common::Trace<
  95. DoubleTime > ::trace().elements().
  96. filter_model_name("b1").filter_time(t).
  97. filter_function_type(artis::common::FunctionType::DELTA_EXT).size() == 1);
  98. }
  99. for (unsigned int t = 0; t <= 100; t += 2) {
  100. REQUIRE(artis::common::Trace<
  101. DoubleTime > ::trace().elements().
  102. filter_model_name("a2").filter_time(t).
  103. filter_level_type(artis::common::LevelType::USER).
  104. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  105. REQUIRE(artis::common::Trace<
  106. DoubleTime > ::trace().elements().
  107. filter_model_name("a2").filter_time(t).
  108. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  109. }
  110. REQUIRE(artis::common::Trace<
  111. DoubleTime > ::trace().elements().
  112. filter_model_name("a2").filter_time(0).
  113. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  114. 0).get_comment()
  115. == "x = { ( 0 , a2 , 0 ) }");
  116. REQUIRE(artis::common::Trace<
  117. DoubleTime > ::trace().elements().
  118. filter_model_name("a2").filter_time(2).
  119. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  120. 0).get_comment()
  121. == "x = { }");
  122. REQUIRE(artis::common::Trace<
  123. DoubleTime > ::trace().elements().
  124. filter_model_name("a2").filter_time(4).
  125. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  126. 0).get_comment()
  127. == "x = { ( 0 , a2 , 2 ) }");
  128. REQUIRE(artis::common::Trace<
  129. DoubleTime > ::trace().elements().
  130. filter_model_name("a2").filter_time(6).
  131. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  132. 0).get_comment()
  133. == "x = { }");
  134. REQUIRE(artis::common::Trace<
  135. DoubleTime > ::trace().elements().
  136. filter_model_name("a2").filter_time(8).
  137. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  138. 0).get_comment()
  139. == "x = { ( 0 , a2 , 3 ) }");
  140. REQUIRE(artis::common::Trace<
  141. DoubleTime > ::trace().elements().
  142. filter_model_name("a2").filter_time(10).
  143. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  144. 0).get_comment()
  145. == "x = { ( 0 , a2 , 4 ) }");
  146. REQUIRE(artis::common::Trace<
  147. DoubleTime > ::trace().elements().
  148. filter_model_name("a2").filter_time(12).
  149. filter_function_type(artis::common::FunctionType::TRANSITION).at(
  150. 0).get_comment()
  151. == "x = { }");
  152. for (unsigned int t = 0; t <= 100; t += 2) {
  153. REQUIRE(artis::common::Trace<
  154. DoubleTime > ::trace().elements().
  155. filter_model_name("b2").filter_time(t).
  156. filter_level_type(artis::common::LevelType::USER).
  157. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  158. REQUIRE(artis::common::Trace<
  159. DoubleTime > ::trace().elements().
  160. filter_model_name("b2").filter_time(t).
  161. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  162. }
  163. }