3 #ifndef CDSTEST_HDR_LAZY_H
4 #define CDSTEST_HDR_LAZY_H
6 #include "cppunit/cppunit_proxy.h"
7 #include <cds/container/details/lazy_list_base.h>
10 namespace cc = cds::container;
11 namespace co = cds::container::opt;
13 class UnorderedLazyListTestHeader: public CppUnitMini::TestCase
17 int nEnsureExistsCall;
40 item(int key, int val)
61 bool operator ()(const T& v1, const T& v2 ) const
63 return v1.key() < v2.key();
67 bool operator ()(const T& v1, const Q& v2 ) const
73 bool operator ()(const Q& v1, const T& v2 ) const
81 int operator ()(const T& v1, const T& v2 ) const
83 if ( v1.key() < v2.key() )
85 return v1.key() > v2.key() ? 1 : 0;
89 int operator ()(const T& v1, const Q& v2 ) const
93 return v1.key() > v2 ? 1 : 0;
97 int operator ()(const Q& v1, const T& v2 ) const
101 return v1 > v2.key() ? 1 : 0;
105 template <typename T>
107 int operator ()(const T& v1, const T& v2 ) const
109 return v1.key() == v2.key();
112 template <typename Q>
113 int operator ()(const T& v1, const Q& v2 ) const
115 return v1.key() == v2;
118 template <typename Q>
119 int operator ()(const Q& v1, const T& v2 ) const
121 return v1 == v2.key();
126 template <class UnordList>
129 typedef UnordList list;
130 typedef typename list::value_type value_type;
131 typedef std::pair<typename list::iterator, bool> ensure_result;
133 typename list::iterator it;
136 CPPUNIT_ASSERT( l.empty() );
137 CPPUNIT_ASSERT( l.insert(50) != l.end() );
138 CPPUNIT_ASSERT( !l.empty() );
140 ensure_result eres = l.ensure( item(100, 33) );
141 CPPUNIT_ASSERT( eres.second );
142 CPPUNIT_ASSERT( eres.first != l.end() );
143 CPPUNIT_ASSERT( l.insert( item(150) ) != l.end() );
145 CPPUNIT_ASSERT( l.insert(100) == l.end() );
146 eres = l.ensure( item(50, 33) );
147 CPPUNIT_ASSERT( !eres.second );
148 CPPUNIT_ASSERT( eres.first->nVal == eres.first->nKey * 2 );
149 eres.first->nVal = 63;
152 CPPUNIT_ASSERT( it == l.end() );
155 CPPUNIT_ASSERT( it != l.end() );
156 CPPUNIT_ASSERT( it->nKey == 50 );
157 CPPUNIT_ASSERT( it->nVal == 63 );
160 CPPUNIT_ASSERT( it != l.end() );
161 CPPUNIT_ASSERT( it->nKey == 100 );
162 CPPUNIT_ASSERT( it->nVal == 33 );
164 it = l.find_with( 150, equal_to<value_type>() );
165 CPPUNIT_ASSERT( it != l.end() );
166 CPPUNIT_ASSERT( it->nKey == 150 );
167 CPPUNIT_ASSERT( it->nVal == it->nKey * 2 );
169 CPPUNIT_ASSERT( !l.empty() );
171 CPPUNIT_ASSERT( l.empty() );
174 CPPUNIT_ASSERT( l.emplace( 501 ) != l.end());
175 CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
176 CPPUNIT_ASSERT( l.emplace( item( 1001 )) != l.end());
178 // insert failed - such key exists
179 CPPUNIT_ASSERT( l.emplace( 501, 2 ) == l.end());
180 CPPUNIT_ASSERT( l.emplace( 251, 10) == l.end());
183 CPPUNIT_ASSERT( it != l.end() );
184 CPPUNIT_ASSERT( it->nKey == 501 );
185 CPPUNIT_ASSERT( it->nVal == 501 * 2 );
188 CPPUNIT_ASSERT( it != l.end() );
189 CPPUNIT_ASSERT( it->nKey == 1001 );
190 CPPUNIT_ASSERT( it->nVal == 1001 * 2 );
193 typename UnordList::iterator it( l.begin() );
194 typename UnordList::const_iterator cit( l.cbegin() );
195 CPPUNIT_CHECK( it == cit );
196 CPPUNIT_CHECK( it != l.end() );
197 CPPUNIT_CHECK( it != l.cend() );
198 CPPUNIT_CHECK( cit != l.end() );
199 CPPUNIT_CHECK( cit != l.cend() );
201 CPPUNIT_CHECK( it != cit );
202 CPPUNIT_CHECK( it != l.end() );
203 CPPUNIT_CHECK( it != l.cend() );
204 CPPUNIT_CHECK( cit != l.end() );
205 CPPUNIT_CHECK( cit != l.cend() );
207 CPPUNIT_CHECK( it == cit );
208 CPPUNIT_CHECK( it != l.end() );
209 CPPUNIT_CHECK( it != l.cend() );
210 CPPUNIT_CHECK( cit != l.end() );
211 CPPUNIT_CHECK( cit != l.cend() );
216 CPPUNIT_ASSERT( l.empty() );
221 void NOGC_equal_to();
223 void NOGC_equal_to_mix();
226 CPPUNIT_TEST_SUITE(UnorderedLazyListTestHeader)
227 CPPUNIT_TEST(NOGC_cmp)
228 CPPUNIT_TEST(NOGC_less)
229 CPPUNIT_TEST(NOGC_equal_to)
230 CPPUNIT_TEST(NOGC_cmpmix)
231 CPPUNIT_TEST(NOGC_equal_to_mix)
232 CPPUNIT_TEST(NOGC_ic)
233 CPPUNIT_TEST_SUITE_END()
236 } // namespace unordlist
238 #endif // #ifndef CDSTEST_HDR_LAZY_H