tests.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @file tests/dtss/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/dtss/graph_manager.hpp>
  26. #include <tests/dtss/models.hpp>
  27. #include <artis-star/common/RootCoordinator.hpp>
  28. #include <artis-star/kernel/dtss/Policy.hpp>
  29. #define CATCH_CONFIG_MAIN
  30. #include <tests/catch.hpp>
  31. using namespace artis::tests::dtss;
  32. using namespace artis::common;
  33. TEST_CASE("dtss/only_one", "run")
  34. {
  35. artis::common::context::Context<artis::common::DoubleTime> context(0, 10);
  36. artis::dtss::Parameters<DoubleTime> parameters = {1};
  37. artis::common::RootCoordinator<
  38. DoubleTime, artis::dtss::Coordinator<
  39. DoubleTime,
  40. artis::dtss::LastBagPolicy,
  41. OnlyOneGraphManager,
  42. artis::dtss::Parameters<DoubleTime>,
  43. artis::common::NoParameters>
  44. > rc(context, "root", parameters, artis::common::NoParameters());
  45. artis::common::Trace<DoubleTime>::trace().clear();
  46. rc.run(context);
  47. REQUIRE(artis::common::Trace<DoubleTime>::trace().elements().
  48. filter_model_name("a").
  49. filter_function_type(artis::common::FunctionType::START).size() == 1);
  50. for (double t = 0; t <= 10; ++t) {
  51. REQUIRE(artis::common::Trace<
  52. DoubleTime > ::trace().elements().
  53. filter_model_name("a").filter_time(t).
  54. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  55. REQUIRE(artis::common::Trace<
  56. DoubleTime > ::trace().elements().
  57. filter_model_name("a").filter_time(t).
  58. filter_level_type(artis::common::LevelType::USER).
  59. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  60. }
  61. }
  62. TEST_CASE("dtss/two", "run")
  63. {
  64. artis::common::context::Context<artis::common::DoubleTime> context(0, 10);
  65. artis::dtss::Parameters<DoubleTime> parameters = {1};
  66. artis::common::RootCoordinator<
  67. DoubleTime, artis::dtss::Coordinator<
  68. DoubleTime,
  69. artis::dtss::LastBagPolicy,
  70. TwoGraphManager,
  71. artis::dtss::Parameters<DoubleTime> >
  72. > rc(context, "root", parameters, artis::common::NoParameters());
  73. artis::common::Trace<DoubleTime>::trace().clear();
  74. rc.run(context);
  75. REQUIRE(artis::common::Trace<
  76. DoubleTime > ::trace().elements().
  77. filter_model_name("a").
  78. filter_function_type(artis::common::FunctionType::START).size() == 1);
  79. for (unsigned int t = 0; t <= 10; ++t) {
  80. REQUIRE(artis::common::Trace<
  81. DoubleTime > ::trace().elements().
  82. filter_model_name("a").filter_time(t).
  83. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  84. REQUIRE(artis::common::Trace<
  85. DoubleTime > ::trace().elements().
  86. filter_model_name("a").filter_time(t).
  87. filter_level_type(artis::common::LevelType::USER).
  88. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  89. }
  90. REQUIRE(artis::common::Trace<
  91. DoubleTime > ::trace().elements().
  92. filter_model_name("b").
  93. filter_function_type(artis::common::FunctionType::START).size() == 1);
  94. for (unsigned int t = 0; t <= 10; ++t) {
  95. REQUIRE(artis::common::Trace<
  96. DoubleTime > ::trace().elements().
  97. filter_model_name("b").filter_time(t).
  98. filter_function_type(artis::common::FunctionType::TRANSITION).size() == 1);
  99. REQUIRE(artis::common::Trace<
  100. DoubleTime > ::trace().elements().
  101. filter_model_name("b").filter_time(t).
  102. filter_level_type(artis::common::LevelType::USER).
  103. filter_function_type(artis::common::FunctionType::LAMBDA).size() == 1);
  104. }
  105. }