tests.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_type(artis::common::START).size() == 1);
  46. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  47. filter_model_name("b1").
  48. filter_type(artis::common::START).size() == 1);
  49. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  50. filter_model_name("a2").
  51. filter_type(artis::common::START).size() == 1);
  52. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  53. filter_model_name("b2").
  54. filter_type(artis::common::START).size() == 1);
  55. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  56. filter_model_name("a1").
  57. filter_type(artis::common::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_type(artis::common::LAMBDA).size() == 1);
  63. REQUIRE(artis::common::Trace<
  64. DoubleTime > ::trace().elements().
  65. filter_model_name("a1").filter_time(t).
  66. filter_type(artis::common::DELTA_INT).size() == 1);
  67. REQUIRE(artis::common::Trace<
  68. DoubleTime > ::trace().elements().
  69. filter_model_name("a1").filter_time(t).
  70. filter_type(artis::common::TA).size() == 1);
  71. }
  72. for (double t = 0; t <= 100; t = t + 3) {
  73. REQUIRE(artis::common::Trace<
  74. DoubleTime > ::trace().elements().
  75. filter_model_name("b1").filter_time(t).
  76. filter_type(artis::common::LAMBDA).size() == 1);
  77. REQUIRE(artis::common::Trace<
  78. DoubleTime > ::trace().elements().
  79. filter_model_name("b1").filter_time(t).
  80. filter_type(artis::common::DELTA_INT).size() == 1);
  81. if (t == 0) {
  82. REQUIRE(artis::common::Trace<
  83. DoubleTime > ::trace().elements().
  84. filter_model_name("b1").filter_time(t).
  85. filter_type(artis::common::TA).size() == 1);
  86. } else {
  87. REQUIRE(artis::common::Trace<
  88. DoubleTime > ::trace().elements().
  89. filter_model_name("b1").filter_time(t).
  90. filter_type(artis::common::TA).size() == 2);
  91. }
  92. REQUIRE(artis::common::Trace<
  93. DoubleTime > ::trace().elements().
  94. filter_model_name("b1").filter_time(t).
  95. filter_type(artis::common::DELTA_EXT).size() == 1);
  96. }
  97. for (unsigned int t = 0; t <= 100; t += 2) {
  98. REQUIRE(artis::common::Trace<
  99. DoubleTime > ::trace().elements().
  100. filter_model_name("a2").filter_time(t).
  101. filter_type(artis::common::LAMBDA).size() == 1);
  102. REQUIRE(artis::common::Trace<
  103. DoubleTime > ::trace().elements().
  104. filter_model_name("a2").filter_time(t).
  105. filter_type(artis::common::DELTA_INT).size() == 1);
  106. }
  107. REQUIRE(artis::common::Trace<
  108. DoubleTime > ::trace().elements().
  109. filter_model_name("a2").filter_time(0).
  110. filter_type(artis::common::DELTA_INT).at(0).get_comment()
  111. == "x = { ( 0 , a2 , 0 ) }");
  112. REQUIRE(artis::common::Trace<
  113. DoubleTime > ::trace().elements().
  114. filter_model_name("a2").filter_time(2).
  115. filter_type(artis::common::DELTA_INT).at(0).get_comment()
  116. == "x = { }");
  117. REQUIRE(artis::common::Trace<
  118. DoubleTime > ::trace().elements().
  119. filter_model_name("a2").filter_time(4).
  120. filter_type(artis::common::DELTA_INT).at(0).get_comment()
  121. == "x = { ( 0 , a2 , 2 ) }");
  122. REQUIRE(artis::common::Trace<
  123. DoubleTime > ::trace().elements().
  124. filter_model_name("a2").filter_time(6).
  125. filter_type(artis::common::DELTA_INT).at(0).get_comment()
  126. == "x = { ( 0 , a2 , 2 ) }");
  127. REQUIRE(artis::common::Trace<
  128. DoubleTime > ::trace().elements().
  129. filter_model_name("a2").filter_time(8).
  130. filter_type(artis::common::DELTA_INT).at(0).get_comment()
  131. == "x = { ( 0 , a2 , 3 ) }");
  132. for (unsigned int t = 0; t <= 100; t += 2) {
  133. REQUIRE(artis::common::Trace<
  134. DoubleTime > ::trace().elements().
  135. filter_model_name("b2").filter_time(t).
  136. filter_type(artis::common::LAMBDA).size() == 1);
  137. REQUIRE(artis::common::Trace<
  138. DoubleTime > ::trace().elements().
  139. filter_model_name("b2").filter_time(t).
  140. filter_type(artis::common::DELTA_INT).size() == 1);
  141. }
  142. }