Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "LinearSetTest.h"
#include <linear_set>
#include <algorithm>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LinearSetTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION( LinearSetTest );
void LinearSetTest::setUp() {
}
void LinearSetTest::tearDown() {
}
void LinearSetTest::test1() {
std::vector < int > data = { 1, 4, 3 };
std::linear_set < int > test1;
std::linear_set < int > test2 ( data.begin ( ), data.end ( ) );
CPPUNIT_ASSERT ( test1.size ( ) == 0 );
CPPUNIT_ASSERT ( test1.empty ( ) );
CPPUNIT_ASSERT ( test2.size ( ) == 3 );
test1.insert ( 1 );
CPPUNIT_ASSERT ( test1.size ( ) == 1 );
CPPUNIT_ASSERT ( ! test1.empty ( ) );
for ( int elem : test1 ) {
CPPUNIT_ASSERT ( elem == 1 );
}
test1.clear ( );
CPPUNIT_ASSERT ( test1.empty ( ) );
std::linear_set < int >::iterator iter = test1.insert ( data [0] ).first;
CPPUNIT_ASSERT ( iter == test1.begin ( ) );
iter = test1.insert ( data [1] ).first;
CPPUNIT_ASSERT ( iter == test1.begin ( ) + 1 );
iter = test1.insert ( data [2] ).first;
CPPUNIT_ASSERT ( iter == test1.begin ( ) + 1 );
CPPUNIT_ASSERT ( test1 == test2 );
CPPUNIT_ASSERT ( ! test1.insert ( data [0] ).second );
iter = test1.insert ( data [0] ).first;
CPPUNIT_ASSERT ( iter == test1.begin ( ) );
test1.insert ( { 2, 3 } );
CPPUNIT_ASSERT ( test1.size ( ) == 4 );
std::vector < int > ref = { 1, 2, 3, 4 };
std::vector < int > copy ( test1.begin ( ), test1.end ( ) );
CPPUNIT_ASSERT ( ref == copy );
ref = { 4, 3, 2, 1 };
copy = std::vector < int > ( test1.rbegin ( ), test1.rend ( ) );
CPPUNIT_ASSERT ( ref == copy );
}
void LinearSetTest::test2() {
std::linear_set<int> first = {1};
std::linear_set<int> second = {1, 2, 3};
std::linear_set<int> firstMinusSecond;
std::linear_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 LinearSetTest::test3() {
int moves;
int copies;
std::linear_set<LinearSetTest::Moveable> set;
set.insert ( LinearSetTest::Moveable(moves, copies) );
std::linear_set<LinearSetTest::Moveable> set2;
for(Moveable moveable : std::make_moveable_set(set)) {
set2.insert(std::move(moveable));
}
CPPUNIT_ASSERT(copies == 0);
}