1 /*-------------------------------------------------------------------------
2  * drawElements C++ Base Library
3  * -----------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Utilities for STL containers.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "deSTLUtil.hpp"
25 
26 #include <map>
27 #include <set>
28 
29 using std::map;
30 using std::set;
31 
32 namespace de
33 {
34 
STLUtil_selfTest(void)35 void STLUtil_selfTest (void)
36 {
37 	{
38 		map<int, int> m;
39 		insert(m, 4, 5);
40 		DE_TEST_ASSERT(contains(m, 4));
41 		DE_TEST_ASSERT(lookup(m, 4) == 5);
42 		DE_TEST_ASSERT(*tryLookup(m, 4) == 5);
43 		DE_TEST_ASSERT(!contains(m, 3));
44 		DE_TEST_ASSERT(tryLookup(m, 3) == DE_NULL);
45 		DE_TEST_ASSERT(lookupDefault(m, 3, 7) == 7);
46 	}
47 
48 	{
49 		set<int> s1;
50 		s1.insert(2);
51 		s1.insert(3);
52 		DE_TEST_ASSERT(contains(s1, 2));
53 		DE_TEST_ASSERT(contains(s1, 3));
54 		DE_TEST_ASSERT(!contains(s1, 5));
55 
56 		set<int> s2;
57 		s2.insert(3);
58 		s2.insert(5);
59 		DE_TEST_ASSERT(!contains(s2, 2));
60 		DE_TEST_ASSERT(contains(s2, 3));
61 		DE_TEST_ASSERT(contains(s2, 5));
62 
63 		set<int> si = intersection(s1, s2);
64 		DE_TEST_ASSERT(!contains(si, 2));
65 		DE_TEST_ASSERT(contains(si, 3));
66 		DE_TEST_ASSERT(!contains(si, 5));
67 
68 		set<int> su = set_union(s1, s2);
69 		DE_TEST_ASSERT(contains(su, 2));
70 		DE_TEST_ASSERT(contains(su, 3));
71 		DE_TEST_ASSERT(contains(su, 5));
72 	}
73 }
74 
75 }
76