Improved SkipListSet unit tests
[libcds.git] / test / unit / set / split_michael_nogc.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
29 */
30
31 #include "test_set_nogc.h"
32
33 #include <cds/container/michael_list_nogc.h>
34 #include <cds/container/split_list_set_nogc.h>
35
36 namespace {
37     namespace cc = cds::container;
38     typedef cds::gc::nogc gc_type;
39
40     class SplitListMichaelSet_NoGC : public cds_test::container_set_nogc
41     {
42     protected:
43         typedef cds_test::container_set_nogc base_class;
44
45         //void SetUp()
46         //{}
47
48         //void TearDown()
49         //{}
50     };
51
52     TEST_F( SplitListMichaelSet_NoGC, compare )
53     {
54         typedef cc::SplitListSet< gc_type, int_item, 
55             typename cc::split_list::make_traits<
56                 cc::split_list::ordered_list< cc::michael_list_tag >
57                 , cds::opt::hash< hash_int >
58                 , cc::split_list::ordered_list_traits< 
59                     typename cc::michael_list::make_traits<
60                         cds::opt::compare< cmp >
61                     >::type
62                 >
63             >::type
64         > set_type;
65
66         set_type s( kSize, 2 );
67         test( s );
68     }
69
70     TEST_F( SplitListMichaelSet_NoGC, less )
71     {
72         typedef cc::SplitListSet< gc_type, int_item, 
73             typename cc::split_list::make_traits<
74                 cc::split_list::ordered_list< cc::michael_list_tag >
75                 , cds::opt::hash< hash_int >
76                 , cc::split_list::ordered_list_traits< 
77                     typename cc::michael_list::make_traits<
78                         cds::opt::less< less >
79                     >::type
80                 >
81             >::type
82         > set_type;
83
84         set_type s( kSize, 2 );
85         test( s );
86     }
87
88     TEST_F( SplitListMichaelSet_NoGC, cmpmix )
89     {
90         typedef cc::SplitListSet< gc_type, int_item, 
91             typename cc::split_list::make_traits<
92                 cc::split_list::ordered_list< cc::michael_list_tag >
93                 , cds::opt::hash< hash_int >
94                 , cc::split_list::ordered_list_traits< 
95                     typename cc::michael_list::make_traits<
96                         cds::opt::less< less >
97                         , cds::opt::compare< cmp >
98                     >::type
99                 >
100             >::type
101         > set_type;
102
103         set_type s( kSize, 3 );
104         test( s );
105     }
106
107     TEST_F( SplitListMichaelSet_NoGC, item_counting )
108     {
109         struct set_traits: public cc::split_list::traits
110         {
111             typedef cc::michael_list_tag ordered_list;
112             typedef hash_int hash;
113             typedef cds::atomicity::item_counter item_counter;
114
115             struct ordered_list_traits: public cc::michael_list::traits
116             {
117                 typedef cmp compare;
118                 typedef base_class::less less;
119                 typedef cds::backoff::empty back_off;
120             };
121         };
122         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
123
124         set_type s( kSize, 4 );
125         test( s );
126     }
127
128     TEST_F( SplitListMichaelSet_NoGC, stat )
129     {
130         struct set_traits: public cc::split_list::traits
131         {
132             typedef cc::michael_list_tag ordered_list;
133             typedef hash_int hash;
134             typedef cds::atomicity::item_counter item_counter;
135             typedef cc::split_list::stat<> stat;
136
137             struct ordered_list_traits: public cc::michael_list::traits
138             {
139                 typedef base_class::less less;
140                 typedef cds::opt::v::sequential_consistent memory_model;
141             };
142         };
143         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
144
145         set_type s( kSize, 5 );
146         test( s );
147     }
148
149     TEST_F( SplitListMichaelSet_NoGC, back_off )
150     {
151         struct set_traits: public cc::split_list::traits
152         {
153             typedef cc::michael_list_tag ordered_list;
154             typedef hash_int hash;
155             typedef cds::atomicity::item_counter item_counter;
156             typedef cds::backoff::yield back_off;
157             typedef cds::opt::v::sequential_consistent memory_model;
158
159             struct ordered_list_traits: public cc::michael_list::traits
160             {
161                 typedef cmp compare;
162                 typedef cds::backoff::pause back_off;
163             };
164         };
165         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
166
167         set_type s( kSize, 2 );
168         test( s );
169     }
170
171     struct set_static_traits: public cc::split_list::traits
172     {
173         static bool const dynamic_bucket_table = false;
174     };
175
176     TEST_F( SplitListMichaelSet_NoGC, static_bucket_table )
177     {
178         struct set_traits: public set_static_traits
179         {
180             typedef cc::michael_list_tag ordered_list;
181             typedef hash_int hash;
182             typedef cds::atomicity::item_counter item_counter;
183
184             struct ordered_list_traits: public cc::michael_list::traits
185             {
186                 typedef cmp compare;
187                 typedef cds::backoff::pause back_off;
188             };
189         };
190         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
191
192         set_type s( kSize, 4 );
193         test( s );
194     }
195
196
197 } // namespace