Changeset View
Changeset View
Standalone View
Standalone View
src/test/rwcollection_tests.cpp
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "reverse_iterator.h" | |||||
#include "rwcollection.h" | #include "rwcollection.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <boost/range/adaptor/reversed.hpp> | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <set> | #include <set> | ||||
#include <vector> | #include <vector> | ||||
BOOST_AUTO_TEST_SUITE(rwcollection_tests); | BOOST_AUTO_TEST_SUITE(rwcollection_tests); | ||||
BOOST_AUTO_TEST_CASE(vector) { | BOOST_AUTO_TEST_CASE(vector) { | ||||
Show All 13 Lines | RWCollection<std::vector<int>> rwvector; | ||||
int e = 0; | int e = 0; | ||||
for (int &i : w) { | for (int &i : w) { | ||||
BOOST_CHECK_EQUAL(i, e++); | BOOST_CHECK_EQUAL(i, e++); | ||||
i *= 2; | i *= 2; | ||||
} | } | ||||
e = 0; | e = 0; | ||||
for (int &i : boost::adaptors::reverse(w)) { | for (int &i : reverse_iterate(w)) { | ||||
BOOST_CHECK_EQUAL(i, 198 - 2 * e); | BOOST_CHECK_EQUAL(i, 198 - 2 * e); | ||||
i = e++; | i = e++; | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
auto r = rwvector.getReadView(); | auto r = rwvector.getReadView(); | ||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
BOOST_CHECK_EQUAL(r[i], 99 - i); | BOOST_CHECK_EQUAL(r[i], 99 - i); | ||||
} | } | ||||
int e = 0; | int e = 0; | ||||
for (const int &i : r) { | for (const int &i : r) { | ||||
BOOST_CHECK_EQUAL(i, 99 - (e++)); | BOOST_CHECK_EQUAL(i, 99 - (e++)); | ||||
} | } | ||||
e = 0; | e = 0; | ||||
for (const int &i : boost::adaptors::reverse(r)) { | for (const int &i : reverse_iterate(r)) { | ||||
BOOST_CHECK_EQUAL(i, e++); | BOOST_CHECK_EQUAL(i, e++); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(set) { | BOOST_AUTO_TEST_CASE(set) { | ||||
RWCollection<std::set<int>> rwset; | RWCollection<std::set<int>> rwset; | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |