#include "SetTest.h" #include <set> #include <algorithm> CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetTest, "bits" ); CPPUNIT_TEST_SUITE_REGISTRATION( SetTest ); void SetTest::setUp() { } void SetTest::tearDown() { } void SetTest::test1() { int first[] = {5,10,15,20,25}; int second[] = {50,40,30,20,10}; std::vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 std::vector<int>::iterator it; std::sort (first,first+5); // 5 10 15 20 25 std::sort (second,second+5); // 10 20 30 40 50 it=std::set_difference (first, first+5, second, second+5, v.begin()); v.resize(it-v.begin()); CPPUNIT_ASSERT_EQUAL(5, v[0]); CPPUNIT_ASSERT_EQUAL(15, v[1]); CPPUNIT_ASSERT_EQUAL(25, v[2]); } void SetTest::test2() { std::set<int> first = {1}; std::set<int> second = {1, 2, 3}; std::set<int> firstMinusSecond; std::set<int> secondMinusFirst; std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), (size_t) 0u); CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), (size_t) 2u); } void SetTest::test3() { int moves; int copies; std::set<SetTest::Moveable> set; set.insert ( SetTest::Moveable(moves, copies) ); std::set<SetTest::Moveable> set2; for(Moveable moveable : std::make_moveable_set(set)) { set2.insert(std::move(moveable)); } CPPUNIT_ASSERT(copies == 0); }