diff --git a/include/core/state_block/state_composite.h b/include/core/state_block/state_composite.h index c7a125ac0d96b1d1b0799ab9e983bccf76bf36db..a58121fef5abc9ff6e2acd7b9315e69b3ccb5859 100644 --- a/include/core/state_block/state_composite.h +++ b/include/core/state_block/state_composite.h @@ -25,6 +25,9 @@ typedef std::string StateStructure; typedef std::unordered_map < char, StateBlockPtr > StateBlockMap; typedef StateBlockMap::const_iterator StateBlockMapCIter; +bool structcmp(const StateStructure& s1, const StateStructure& s2); + + class VectorComposite : public std::unordered_map < char, Eigen::VectorXd > { public: diff --git a/src/state_block/state_composite.cpp b/src/state_block/state_composite.cpp index 0f4efab6f1f093d8f1425d0855a453c6370f1c93..3b4367c0840998d123c56214d0fabb15a9c979e6 100644 --- a/src/state_block/state_composite.cpp +++ b/src/state_block/state_composite.cpp @@ -6,6 +6,22 @@ namespace wolf{ +////// STATE STRUCTURE ////////// + +bool structcmp(const StateStructure& s1, const StateStructure& s2) +{ + if (s1.size() != s2.size()) return false; + + std::set<char> s1_chars, s2_chars; + + for (const auto &c : s1) + s1_chars.emplace(c); + for (const auto &c : s2) + s2_chars.emplace(c); + + return s1_chars == s2_chars; +} + ////// VECTOR COMPOSITE ////////// VectorComposite::VectorComposite(const StateStructure& _structure, const std::list<int>& _sizes) diff --git a/test/gtest_state_composite.cpp b/test/gtest_state_composite.cpp index f4bcea67bd4e51af793e026f1496f2591fcfe98a..d075886db3a186f8716fd687979a1f758d0b77dc 100644 --- a/test/gtest_state_composite.cpp +++ b/test/gtest_state_composite.cpp @@ -13,6 +13,19 @@ using namespace wolf; using namespace std; +TEST(StateStructure, operator_equal) +{ + StateStructure POV("POV"), PVO("PVO"), PO("PO"), POVW("POVW"); + + ASSERT_TRUE ( structcmp(POV , PVO ) ); + ASSERT_FALSE( structcmp(POV , PO ) ); + ASSERT_FALSE( structcmp(PO , POV ) ); + ASSERT_FALSE( structcmp(PO , POVW) ); + ASSERT_FALSE( structcmp(POVW , PO ) ); + + ASSERT_TRUE ( structcmp(POVW , "PVOW" ) ); + ASSERT_TRUE ( structcmp(POVW , "WPOV" ) ); +} class StateBlockCompositeInit : public testing::Test {