2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #include "cppunit/cppunit_proxy.h"
32 #include <cds/container/fcstack.h>
39 class TestFCStack: public CppUnitMini::TestCase
41 template <class Stack>
48 template <class Stack>
49 void test_with( Stack& stack)
51 typedef typename Stack::value_type value_type;
54 CPPUNIT_ASSERT( stack.empty() );
55 CPPUNIT_ASSERT( stack.size() == 0 );
57 CPPUNIT_ASSERT( stack.push(1));
58 CPPUNIT_ASSERT( !stack.empty() );
59 CPPUNIT_ASSERT( stack.size() == 1 );
60 CPPUNIT_ASSERT( stack.push(2));
61 CPPUNIT_ASSERT( !stack.empty() );
62 CPPUNIT_ASSERT( stack.size() == 2 );
63 CPPUNIT_ASSERT( stack.push(3));
64 CPPUNIT_ASSERT( !stack.empty() );
65 CPPUNIT_ASSERT( stack.size() == 3 );
67 CPPUNIT_ASSERT( stack.pop(v) );
68 CPPUNIT_ASSERT( v == 3 );
69 CPPUNIT_ASSERT( !stack.empty() );
70 CPPUNIT_ASSERT( stack.size() == 2 );
71 CPPUNIT_ASSERT( stack.pop(v) );
72 CPPUNIT_ASSERT( v == 2 );
73 CPPUNIT_ASSERT( !stack.empty() );
74 CPPUNIT_ASSERT( stack.size() == 1 );
75 CPPUNIT_ASSERT( stack.pop(v) );
76 CPPUNIT_ASSERT( v == 1 );
77 CPPUNIT_ASSERT( stack.empty() );
78 CPPUNIT_ASSERT( stack.size() == 0 );
80 CPPUNIT_ASSERT( !stack.pop(v) );
81 CPPUNIT_ASSERT( v == 1000 );
82 CPPUNIT_ASSERT( stack.empty() );
83 CPPUNIT_ASSERT( stack.size() == 0 );
85 CPPUNIT_ASSERT( stack.push(10));
86 CPPUNIT_ASSERT( stack.push(20));
87 CPPUNIT_ASSERT( stack.push(30));
88 CPPUNIT_ASSERT( !stack.empty());
89 CPPUNIT_ASSERT( stack.size() == 3 );
91 while ( stack.pop(v) );
93 CPPUNIT_ASSERT( stack.empty() );
94 CPPUNIT_ASSERT( stack.size() == 0 );
97 void FCStack_default();
99 void FCStack_deque_elimination();
100 void FCStack_vector();
101 void FCStack_vector_elimination();
103 void FCStack_list_elimination();
105 CPPUNIT_TEST_SUITE(TestFCStack);
106 CPPUNIT_TEST( FCStack_default )
107 CPPUNIT_TEST( FCStack_deque )
108 CPPUNIT_TEST( FCStack_deque_elimination )
109 CPPUNIT_TEST( FCStack_vector )
110 CPPUNIT_TEST( FCStack_vector_elimination )
111 CPPUNIT_TEST( FCStack_list )
112 CPPUNIT_TEST( FCStack_list_elimination )
113 CPPUNIT_TEST_SUITE_END();
116 void TestFCStack::FCStack_default()
118 typedef cds::container::FCStack< unsigned int > stack_type;
122 void TestFCStack::FCStack_deque()
124 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int> > > stack_type;
128 void TestFCStack::FCStack_deque_elimination()
130 struct stack_traits : public
131 cds::container::fcstack::make_traits <
132 cds::opt::enable_elimination < true >
135 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int> >, stack_traits > stack_type;
139 void TestFCStack::FCStack_vector()
141 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::vector<unsigned int> > > stack_type;
145 void TestFCStack::FCStack_vector_elimination()
147 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::vector<unsigned int> >,
148 cds::container::fcstack::make_traits<
149 cds::opt::enable_elimination< true >
155 void TestFCStack::FCStack_list()
157 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::list<unsigned int> > > stack_type;
161 void TestFCStack::FCStack_list_elimination()
163 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::list<unsigned int> >,
164 cds::container::fcstack::make_traits<
165 cds::opt::enable_elimination< true >
171 CPPUNIT_TEST_SUITE_REGISTRATION(stack::TestFCStack);