diff --git a/src/core/test/attribute-container-test-suite.cc b/src/core/test/attribute-container-test-suite.cc index 64b6194fa..d8a191ac7 100644 --- a/src/core/test/attribute-container-test-suite.cc +++ b/src/core/test/attribute-container-test-suite.cc @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -59,7 +58,7 @@ class AttributeContainerObject : public Object /** * Reverses the list of doubles. */ - void ReverseList(); + void ReverseDoubleList(); /** * \brief Get the type ID. @@ -67,6 +66,19 @@ class AttributeContainerObject : public Object */ static TypeId GetTypeId(); + /** + * Set the list of doubles to the given list + * + * \param doubleList the given list + */ + void SetDoubleList(const std::list& doubleList); + /** + * Get the list of doubles + * + * \return the list of doubles + */ + std::list GetDoubleList() const; + /** * Set the vector of ints to the given vector * @@ -80,15 +92,6 @@ class AttributeContainerObject : public Object */ std::vector GetIntVec() const; - /** - * \brief Stream insertion operator. - * - * \param [in] os The reference to the output stream. - * \param [in] obj The AttributeContainer object. - * \returns The reference to the output stream. - */ - friend std::ostream& operator<<(std::ostream& os, const AttributeContainerObject& obj); - private: std::list m_doublelist; //!< List of doubles. std::vector m_intvec; //!< Vector of ints. @@ -161,10 +164,21 @@ AttributeContainerObject::GetTypeId() } void -AttributeContainerObject::ReverseList() +AttributeContainerObject::ReverseDoubleList() { m_doublelist.reverse(); - std::reverse(m_intvec.begin(), m_intvec.end()); +} + +void +AttributeContainerObject::SetDoubleList(const std::list& doubleList) +{ + m_doublelist = doubleList; +} + +std::list +AttributeContainerObject::GetDoubleList() const +{ + return m_doublelist; } void @@ -179,23 +193,6 @@ AttributeContainerObject::GetIntVec() const return m_intvec; } -std::ostream& -operator<<(std::ostream& os, const AttributeContainerObject& obj) -{ - os << "AttributeContainerObject: "; - bool first = true; - for (auto d : obj.m_doublelist) - { - if (!first) - { - os << ", "; - } - os << d; - first = false; - } - return os; -} - /** * \ingroup attribute-tests * @@ -274,7 +271,7 @@ AttributeContainerTestCase::DoRun() auto ref = {"one", "two", "three"}; AttributeContainerValue ac(ref.begin(), ref.end()); - NS_TEST_ASSERT_MSG_EQ(3, ac.GetN(), "Container size mismatch"); + NS_TEST_ASSERT_MSG_EQ(ref.size(), ac.GetN(), "Container size mismatch"); auto aciter = ac.Begin(); for (auto v : ref) { @@ -289,7 +286,7 @@ AttributeContainerTestCase::DoRun() auto ref = {"one", "two", "three"}; AttributeContainerValue ac(ref); - NS_TEST_ASSERT_MSG_EQ(3, ac.GetN(), "Container size mismatch"); + NS_TEST_ASSERT_MSG_EQ(ref.size(), ac.GetN(), "Container size mismatch"); auto aciter = ac.Begin(); for (auto v : ref) { @@ -305,7 +302,7 @@ AttributeContainerTestCase::DoRun() std::map ref = {{"one", 1}, {"two", 2}, {"three", 3}}; AttributeContainerValue> ac(ref); - NS_TEST_ASSERT_MSG_EQ(3, ac.GetN(), "Container size mismatch"); + NS_TEST_ASSERT_MSG_EQ(ref.size(), ac.GetN(), "Container size mismatch"); auto aciter = ac.Begin(); for (const auto& v : ref) { @@ -443,29 +440,24 @@ AttributeContainerSetGetTestCase::DoRun() { Ptr obj = CreateObject(); { - std::ostringstream oss; - oss << *obj; - NS_TEST_ASSERT_MSG_EQ(oss.str(), - "AttributeContainerObject: ", - "DoubleList initialized incorrectly"); + auto doubleList = obj->GetDoubleList(); + NS_TEST_ASSERT_MSG_EQ(doubleList.empty(), true, "DoubleList initialized incorrectly"); } - std::list doubles = {1.1, 2.22, 3.333}; + const std::list doubles = {1.1, 2.22, 3.333}; obj->SetAttribute("DoubleList", AttributeContainerValue(doubles)); { - std::ostringstream oss; - oss << *obj; - NS_TEST_ASSERT_MSG_EQ(oss.str(), - "AttributeContainerObject: 1.1, 2.22, 3.333", + auto doubleList = obj->GetDoubleList(); + NS_TEST_ASSERT_MSG_EQ(std::equal(doubles.begin(), doubles.end(), doubleList.begin()), + true, "DoubleList incorrectly set"); } - obj->ReverseList(); + obj->ReverseDoubleList(); { - std::ostringstream oss; - oss << *obj; - NS_TEST_ASSERT_MSG_EQ(oss.str(), - "AttributeContainerObject: 3.333, 2.22, 1.1", + auto doubleList = obj->GetDoubleList(); + NS_TEST_ASSERT_MSG_EQ(std::equal(doubles.rbegin(), doubles.rend(), doubleList.begin()), + true, "DoubleList incorrectly reversed"); // NOTE: changing the return container here too! @@ -475,15 +467,12 @@ AttributeContainerSetGetTestCase::DoRun() AttributeContainerValue::result_type doublevec = value.Get(); NS_TEST_ASSERT_MSG_EQ(doubles.size(), doublevec.size(), "DoublesVec wrong size"); - auto iter = doubles.rbegin(); - for (auto d : doublevec) - { - NS_TEST_ASSERT_MSG_EQ(d, *iter, "Incorrect value in doublesvec"); - ++iter; - } + NS_TEST_ASSERT_MSG_EQ(std::equal(doubles.rbegin(), doubles.rend(), doublevec.begin()), + true, + "Incorrect value in doublesvec"); } - std::vector ints = {-1, 0, 1, 2, 3}; + const std::vector ints = {-1, 0, 1, 2, 3}; // NOTE: here the underlying attribute container type differs from the actual container obj->SetAttribute("IntegerVector", AttributeContainerValue(ints)); @@ -495,12 +484,10 @@ AttributeContainerSetGetTestCase::DoRun() AttributeContainerValue::result_type intlist = value.Get(); NS_TEST_ASSERT_MSG_EQ(ints.size(), intlist.size(), "Intvec wrong size"); - auto iter = ints.begin(); - for (auto d : intlist) - { - NS_TEST_ASSERT_MSG_EQ(d, *iter, "Incorrect value in intvec"); - ++iter; - } + + NS_TEST_ASSERT_MSG_EQ(std::equal(ints.begin(), ints.end(), intlist.begin()), + true, + "Incorrect value in intvec"); } std::string intVecPairString("0 1,2,3; 1 0; 2 0,1");