StateTest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2020-10-29
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <memory>
  11. #include <ls_std/ls_std.hpp>
  12. namespace {
  13. class StateTest : public ::testing::Test {
  14. protected:
  15. StateTest() = default;
  16. ~StateTest() override = default;
  17. void SetUp() override {}
  18. void TearDown() override {}
  19. };
  20. TEST_F(StateTest, addStateConnection)
  21. {
  22. ls_std::State stateA {"A"};
  23. ls_std::State stateB {"B"};
  24. ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
  25. }
  26. TEST_F(StateTest, addStateConnectionNegative)
  27. {
  28. ls_std::State stateA {"A"};
  29. ls_std::State stateB {"B"};
  30. ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
  31. ASSERT_FALSE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
  32. ASSERT_FALSE(stateA.addStateConnection("XX", nullptr));
  33. }
  34. TEST_F(StateTest, addStateConnectionV2)
  35. {
  36. ls_std::State stateA {"A"};
  37. ls_std::State stateB {"B"};
  38. ASSERT_TRUE(stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AB", stateB.getId())));
  39. }
  40. TEST_F(StateTest, addStateConnectionV2Negative)
  41. {
  42. ls_std::State stateA {"A"};
  43. ASSERT_FALSE(stateA.addStateConnection(nullptr));
  44. }
  45. TEST_F(StateTest, clearConnections)
  46. {
  47. ls_std::State stateA {"A"};
  48. stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AB", "B"));
  49. stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AC", "C"));
  50. ASSERT_EQ(2, stateA.getConnectedStates().size());
  51. stateA.clearConnections();
  52. ASSERT_EQ(0, stateA.getConnectedStates().size());
  53. ASSERT_TRUE(stateA.getConnectedStates().empty());
  54. }
  55. TEST_F(StateTest, getConnectedStates)
  56. {
  57. ls_std::State stateA {"A"};
  58. ls_std::State stateB {"B"};
  59. ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
  60. ASSERT_FALSE(stateA.getConnectedStates().empty());
  61. ASSERT_EQ(1, stateA.getConnectedStates().size());
  62. }
  63. TEST_F(StateTest, getConnectedStatesNegative)
  64. {
  65. ls_std::State stateA {"A"};
  66. ASSERT_TRUE(stateA.getConnectedStates().empty());
  67. ASSERT_EQ(0, stateA.getConnectedStates().size());
  68. }
  69. TEST_F(StateTest, getId)
  70. {
  71. ls_std::State stateA {"A"};
  72. ASSERT_STREQ("A", stateA.getId().c_str());
  73. }
  74. TEST_F(StateTest, setId)
  75. {
  76. ls_std::State stateA {"A"};
  77. ASSERT_STREQ("A", stateA.getId().c_str());
  78. stateA.setId("B");
  79. ASSERT_STREQ("B", stateA.getId().c_str());
  80. }
  81. TEST_F(StateTest, hasConnection)
  82. {
  83. ls_std::State stateA {"A"};
  84. ls_std::State stateB {"B"};
  85. ls_std::State stateC {"C"};
  86. ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
  87. ASSERT_TRUE(stateA.hasConnection("AB"));
  88. ASSERT_TRUE(stateA.addStateConnection("AC", std::make_shared<ls_std::State>(stateC)));
  89. ASSERT_TRUE(stateA.hasConnection("AC"));
  90. }
  91. TEST_F(StateTest, hasConnectionNegative)
  92. {
  93. ls_std::State stateA {"A"};
  94. ASSERT_FALSE(stateA.hasConnection("AB"));
  95. ASSERT_FALSE(stateA.hasConnection("AC"));
  96. }
  97. }