tests.cpp 4.6 KB

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