StateTest.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2020-09-05
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <memory>
  11. #include "../../../source/logic/State.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(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(std::make_shared<ls_std::State>(stateB)));
  31. ASSERT_FALSE(stateA.addStateConnection(std::make_shared<ls_std::State>(stateB)));
  32. ASSERT_FALSE(stateA.addStateConnection(nullptr));
  33. }
  34. TEST_F(StateTest, getConnectedStates)
  35. {
  36. ls_std::State stateA {"A"};
  37. ls_std::State stateB {"B"};
  38. ASSERT_TRUE(stateA.addStateConnection(std::make_shared<ls_std::State>(stateB)));
  39. ASSERT_FALSE(stateA.getConnectedStates().empty());
  40. ASSERT_EQ(1, stateA.getConnectedStates().size());
  41. }
  42. TEST_F(StateTest, getConnectedStatesNegative)
  43. {
  44. ls_std::State stateA {"A"};
  45. ASSERT_TRUE(stateA.getConnectedStates().empty());
  46. ASSERT_EQ(0, stateA.getConnectedStates().size());
  47. }
  48. TEST_F(StateTest, getId)
  49. {
  50. ls_std::State stateA {"A"};
  51. ASSERT_STREQ("A", stateA.getId().c_str());
  52. }
  53. TEST_F(StateTest, isAccessible)
  54. {
  55. ls_std::State stateA {"A"};
  56. ASSERT_FALSE(stateA.isAccessible());
  57. }
  58. TEST_F(StateTest, removeStateConnection)
  59. {
  60. ls_std::State stateA {"A"};
  61. ls_std::State stateB {"B"};
  62. ASSERT_TRUE(stateA.addStateConnection(std::make_shared<ls_std::State>(stateB)));
  63. ASSERT_FALSE(stateA.getConnectedStates().empty());
  64. ASSERT_EQ(1, stateA.getConnectedStates().size());
  65. stateA.removeStateConnection("B");
  66. ASSERT_TRUE(stateA.getConnectedStates().empty());
  67. ASSERT_EQ(0, stateA.getConnectedStates().size());
  68. }
  69. TEST_F(StateTest, updateAccessCondition)
  70. {
  71. ls_std::State stateA {"A"};
  72. ASSERT_FALSE(stateA.isAccessible());
  73. stateA.updateAccessCondition(true);
  74. ASSERT_TRUE(stateA.isAccessible());
  75. }
  76. }