From f22f23ff7eb8586863c2c547a70e9231d05383fa Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 21 Sep 2014 11:16:40 +0200 Subject: [PATCH] labelInSet test --- alib2data/test-src/label/LabelTest.cpp | 30 ++++++++++++++++++++++++++ alib2data/test-src/label/LabelTest.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/alib2data/test-src/label/LabelTest.cpp b/alib2data/test-src/label/LabelTest.cpp index ca5436e1d7..1c98b77cee 100644 --- a/alib2data/test-src/label/LabelTest.cpp +++ b/alib2data/test-src/label/LabelTest.cpp @@ -14,6 +14,7 @@ #include "label/LabelToXMLComposer.h" #include "factory/DataFactory.hpp" +#include <algorithm> #define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y))) @@ -145,3 +146,32 @@ void LabelTest::testOrder() { CPPUNIT_EXCLUSIVE_OR( s1 < c1, c1 < s1); } +void LabelTest::testInSet() { + { + std::set<std::string> set1 { "a", "b", "c" }; + std::set<std::string> set2 { "a" }; + std::set<std::string> set3; + + std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::insert_iterator<std::set<std::string>>(set3, set3.begin())); + for(const auto& item : set2) { + set1.erase(item); + } + + CPPUNIT_ASSERT(set1.size() == 2); + CPPUNIT_ASSERT(set3.size() == 2); + } + { + std::set<label::Label> set1 { label::labelFrom('a'), label::labelFrom('b'), label::labelFrom('c') }; + std::set<label::Label> set2 { label::labelFrom('a') }; + std::set<label::Label> set3; + + std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::insert_iterator<std::set<label::Label>>(set3, set3.begin())); + for(const auto& item : set2) { + set1.erase(item); + } + + CPPUNIT_ASSERT(set1.size() == 2); + CPPUNIT_ASSERT(set3.size() == 2); + } +} + diff --git a/alib2data/test-src/label/LabelTest.h b/alib2data/test-src/label/LabelTest.h index 23706a7e85..2068b43252 100644 --- a/alib2data/test-src/label/LabelTest.h +++ b/alib2data/test-src/label/LabelTest.h @@ -10,6 +10,7 @@ class LabelTest : public CppUnit::TestFixture CPPUNIT_TEST( testEqual ); CPPUNIT_TEST( testXMLParser ); CPPUNIT_TEST( testOrder ); + CPPUNIT_TEST( testInSet ); CPPUNIT_TEST_SUITE_END(); public: @@ -20,6 +21,7 @@ public: void testEqual(); void testXMLParser(); void testOrder(); + void testInSet(); }; #endif // LABEL_TEST_H_ -- GitLab