2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2017 ScyllaDB Ltd.
23 #define BOOST_TEST_MODULE core
25 #include <boost/test/included/unit_test.hpp>
28 #include <seastar/core/circular_buffer_fixed_capacity.hh>
30 #include <boost/range/algorithm/sort.hpp>
31 #include <boost/range/algorithm/equal.hpp>
32 #include <boost/range/algorithm/reverse.hpp>
34 using namespace seastar
;
36 using cb16_t
= circular_buffer_fixed_capacity
<int, 16>;
39 BOOST_AUTO_TEST_CASE(test_edge_cases
) {
41 BOOST_REQUIRE(cb
.begin() == cb
.end());
42 cb
.push_front(3); // underflows indexes
43 BOOST_REQUIRE_EQUAL(cb
[0], 3);
44 BOOST_REQUIRE(cb
.begin() < cb
.end());
46 BOOST_REQUIRE_EQUAL(cb
.size(), 2u);
47 BOOST_REQUIRE_EQUAL(cb
[0], 3);
48 BOOST_REQUIRE_EQUAL(cb
[1], 4);
50 BOOST_REQUIRE_EQUAL(cb
.back(), 3);
53 BOOST_REQUIRE_EQUAL(cb
.back(), 1);
56 using deque
= std::deque
<int>;
58 BOOST_AUTO_TEST_CASE(test_random_walk
) {
59 auto rand
= std::default_random_engine();
60 auto op_gen
= std::uniform_int_distribution
<unsigned>(0, 6);
63 for (auto i
= 0; i
!= 1000000; ++i
) {
64 auto op
= op_gen(rand
);
84 BOOST_REQUIRE_EQUAL(n
, m
);
93 BOOST_REQUIRE_EQUAL(n
, m
);
104 auto u
= std::uniform_int_distribution
<size_t>(0, d
.size() - 1);
108 BOOST_REQUIRE_EQUAL(m
, n
);
121 BOOST_REQUIRE_EQUAL(c
.size(), d
.size());
122 BOOST_REQUIRE(boost::equal(c
, d
));