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 <gtest/gtest.h>
32 #include <cds/container/fcstack.h>
38 class FCStack : public ::testing::Test
41 template <class Stack>
44 typedef typename Stack::value_type value_type;
48 ASSERT_TRUE( stack.empty() );
49 ASSERT_EQ( stack.size(), 0 );
51 ASSERT_TRUE( stack.push( 1 ) );
52 ASSERT_TRUE( !stack.empty() );
53 ASSERT_EQ( stack.size(), 1 );
54 ASSERT_TRUE( stack.push( 2 ) );
55 ASSERT_TRUE( !stack.empty() );
56 ASSERT_EQ( stack.size(), 2 );
57 ASSERT_TRUE( stack.push( 3 ) );
58 ASSERT_TRUE( !stack.empty() );
59 ASSERT_EQ( stack.size(), 3 );
61 ASSERT_TRUE( stack.pop( v ) );
63 ASSERT_TRUE( !stack.empty() );
64 ASSERT_EQ( stack.size(), 2 );
65 ASSERT_TRUE( stack.pop( v ) );
67 ASSERT_TRUE( !stack.empty() );
68 ASSERT_EQ( stack.size(), 1 );
69 ASSERT_TRUE( stack.pop( v ) );
71 ASSERT_TRUE( stack.empty() );
72 ASSERT_EQ( stack.size(), 0 );
74 ASSERT_TRUE( !stack.pop( v ) );
76 ASSERT_TRUE( stack.empty() );
77 ASSERT_EQ( stack.size(), 0 );
79 ASSERT_TRUE( stack.push( 10 ) );
80 ASSERT_TRUE( stack.push( 20 ) );
81 ASSERT_TRUE( stack.push( 30 ) );
82 ASSERT_TRUE( !stack.empty() );
83 ASSERT_EQ( stack.size(), 3 );
85 while ( stack.pop( v ) );
87 ASSERT_TRUE( stack.empty() );
88 ASSERT_EQ( stack.size(), 0 );
92 TEST_F( FCStack, default_stack )
94 typedef cds::container::FCStack< unsigned int > stack_type;
98 TEST_F( FCStack, deque_based )
100 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int>>> stack_type;
104 TEST_F( FCStack, deque_elimination )
106 struct stack_traits : public
107 cds::container::fcstack::make_traits <
108 cds::opt::enable_elimination < true >
111 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int>>, stack_traits > stack_type;
115 TEST_F( FCStack, vector_based )
117 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::vector<unsigned int>>> stack_type;
121 TEST_F( FCStack, vector_elimination )
123 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::vector<unsigned int>>,
124 cds::container::fcstack::make_traits<
125 cds::opt::enable_elimination< true >
131 TEST_F( FCStack, list_based )
133 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::list<unsigned int>>> stack_type;
137 TEST_F( FCStack, list_elimination )
139 typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::list<unsigned int>>,
140 cds::container::fcstack::make_traits<
141 cds::opt::enable_elimination< true >