Explorar o código

Extended StateMachine class

- added "setName" method
- extended tests for StateMachine class
Patrick-Laptop %!s(int64=4) %!d(string=hai) anos
pai
achega
8a50a52d74

+ 8 - 1
source/logic/StateMachine.cpp

@@ -3,12 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-16
+ * Changed:         2020-09-17
  *
  * */
 
 #include "StateMachine.hpp"
 
+#include <utility>
+
 ls_std::StateMachine::StateMachine(std::string _name) :
 Class("StateMachine"),
 name(std::move(_name))
@@ -59,6 +61,11 @@ bool ls_std::StateMachine::proceed() {
   return condition;
 }
 
+void ls_std::StateMachine::setName(std::string _name)
+{
+  this->name = std::move(_name);
+}
+
 bool ls_std::StateMachine::setStartState(const ls_std::StateId&_id) {
   bool exists = this->_hasState(_id);
 

+ 2 - 1
source/logic/StateMachine.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-16
+ * Changed:         2020-09-17
  *
  * */
 
@@ -32,6 +32,7 @@ namespace ls_std {
       std::unordered_map<StateId, std::shared_ptr<State>> getStates();
       bool hasState(const StateId& _id);
       bool proceed();
+      void setName(std::string _name);
       bool setStartState(const StateId& _id);
 
     private:

+ 10 - 1
test/cases/logic/StateMachineTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-09
- * Changed:         2020-09-16
+ * Changed:         2020-09-17
  *
  * */
 
@@ -161,6 +161,15 @@ namespace {
     ASSERT_STREQ("E", stateMachine.getCurrentState()->getId().c_str());
   }
 
+  TEST_F(StateMachineTest, setName)
+  {
+    ls_std::StateMachine stateMachine {"test_machine"};
+    ASSERT_STREQ("test_machine", stateMachine.getName().c_str());
+
+    stateMachine.setName("bla");
+    ASSERT_STREQ("bla", stateMachine.getName().c_str());
+  }
+
   TEST_F(StateMachineTest, setStartState)
   {
     ls_std::StateMachine stateMachine {"test_machine"};