You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
6.9 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/models/sparse/StandardRewardModel.h"
  4. #include "src/settings/SettingMemento.h"
  5. #include "src/parser/PrismParser.h"
  6. #include "src/builder/ExplicitModelBuilder.h"
  7. #include "src/storage/jani/Model.h"
  8. #include "src/settings/modules/IOSettings.h"
  9. TEST(ExplicitJaniModelBuilderTest, Dtmc) {
  10. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  11. storm::jani::Model janiModel = program.toJani();
  12. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  13. EXPECT_EQ(13ul, model->getNumberOfStates());
  14. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  15. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  16. janiModel = program.toJani();
  17. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  18. EXPECT_EQ(677ul, model->getNumberOfStates());
  19. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  20. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  21. janiModel = program.toJani();
  22. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  23. EXPECT_EQ(8607ul, model->getNumberOfStates());
  24. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  25. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  26. janiModel = program.toJani();
  27. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  28. EXPECT_EQ(273ul, model->getNumberOfStates());
  29. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  30. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
  31. janiModel = program.toJani();
  32. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  33. EXPECT_EQ(1728ul, model->getNumberOfStates());
  34. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  35. }
  36. TEST(ExplicitJaniModelBuilderTest, Ctmc) {
  37. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  38. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableIOSettings().overridePrismCompatibilityMode(true);
  39. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  40. storm::jani::Model janiModel = program.toJani();
  41. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  42. EXPECT_EQ(276ul, model->getNumberOfStates());
  43. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  44. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  45. janiModel = program.toJani();
  46. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  47. EXPECT_EQ(3478ul, model->getNumberOfStates());
  48. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  49. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  50. janiModel = program.toJani();
  51. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  52. EXPECT_EQ(12ul, model->getNumberOfStates());
  53. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  54. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  55. janiModel = program.toJani();
  56. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  57. EXPECT_EQ(810ul, model->getNumberOfStates());
  58. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  59. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  60. janiModel = program.toJani();
  61. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  62. EXPECT_EQ(66ul, model->getNumberOfStates());
  63. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  64. }
  65. TEST(ExplicitJaniModelBuilderTest, Mdp) {
  66. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  67. storm::jani::Model janiModel = program.toJani();
  68. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  69. EXPECT_EQ(169ul, model->getNumberOfStates());
  70. EXPECT_EQ(436ul, model->getNumberOfTransitions());
  71. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  72. janiModel = program.toJani();
  73. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  74. EXPECT_EQ(364ul, model->getNumberOfStates());
  75. EXPECT_EQ(654ul, model->getNumberOfTransitions());
  76. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  77. janiModel = program.toJani();
  78. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  79. EXPECT_EQ(272ul, model->getNumberOfStates());
  80. EXPECT_EQ(492ul, model->getNumberOfTransitions());
  81. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  82. janiModel = program.toJani();
  83. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  84. EXPECT_EQ(1038ul, model->getNumberOfStates());
  85. EXPECT_EQ(1282ul, model->getNumberOfTransitions());
  86. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  87. janiModel = program.toJani();
  88. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  89. EXPECT_EQ(4093ul, model->getNumberOfStates());
  90. EXPECT_EQ(5585ul, model->getNumberOfTransitions());
  91. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  92. janiModel = program.toJani();
  93. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  94. EXPECT_EQ(37ul, model->getNumberOfStates());
  95. EXPECT_EQ(59ul, model->getNumberOfTransitions());
  96. }
  97. TEST(ExplicitJaniModelBuilderTest, FailComposition) {
  98. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition.nm");
  99. storm::jani::Model janiModel = program.toJani();
  100. ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(janiModel).build(), storm::exceptions::WrongFormatException);
  101. }
  102. TEST(ExplicitJaniModelBuilderTest, IllegalSynchronizingWrites) {
  103. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2-illegalSynchronizingWrite.nm");
  104. storm::jani::Model janiModel = program.toJani();
  105. ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(janiModel).build(), storm::exceptions::WrongFormatException);
  106. }