mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Merge branch 'master' into development
This commit is contained in:
commit
66bb92c328
1
fnv_1.h
1
fnv_1.h
@ -5,7 +5,6 @@ The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
|
||||
88
imap.h
88
imap.h
@ -433,16 +433,6 @@ namespace etl
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
imap& operator = (const imap& rhs)
|
||||
{
|
||||
assign(rhs.cbegin(), rhs.cend());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the beginning of the map.
|
||||
//*************************************************************************
|
||||
@ -779,7 +769,7 @@ namespace etl
|
||||
///\param position The position that would precede the value to insert.
|
||||
///\param value The value to insert.
|
||||
//*********************************************************************
|
||||
iterator insert(iterator position, const value_type& value)
|
||||
iterator insert(iterator, const value_type& value)
|
||||
{
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
@ -790,7 +780,7 @@ namespace etl
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(find_node(root_node, position.p_node), node);
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -811,7 +801,7 @@ namespace etl
|
||||
///\param position The position that would precede the value to insert.
|
||||
///\param value The value to insert.
|
||||
//*********************************************************************
|
||||
iterator insert(const_iterator position, const value_type& value)
|
||||
iterator insert(const_iterator, const value_type& value)
|
||||
{
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
@ -822,7 +812,7 @@ namespace etl
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(find_node(root_node, position.p_node), node);
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1151,7 +1141,7 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
// Return root node if nothing or duplicate was found
|
||||
// Return root node if nothing was found
|
||||
return root_node;
|
||||
}
|
||||
|
||||
@ -1324,36 +1314,6 @@ namespace etl
|
||||
return lower_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is not considered to go before the key provided
|
||||
//*************************************************************************
|
||||
const Node& find_lower_node(const Node* position, const key_value_parameter_t& key) const
|
||||
{
|
||||
// Something at this position? keep going
|
||||
const Node* lower_node = position;
|
||||
while (lower_node)
|
||||
{
|
||||
// Downcast lower node to Data_Node reference for key comparisons
|
||||
const Data_Node& data_node = imap::data_cast(*lower_node);
|
||||
// Compare the key value to the current lower node key value
|
||||
if (node_comp(key, data_node))
|
||||
{
|
||||
lower_node = lower_node->children[kLeft];
|
||||
}
|
||||
else if (node_comp(data_node, key))
|
||||
{
|
||||
lower_node = lower_node->children[kRight];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the lower_node position found
|
||||
return lower_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is considered to go after the key provided
|
||||
//*************************************************************************
|
||||
@ -1392,44 +1352,6 @@ namespace etl
|
||||
return upper_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is considered to go after the key provided
|
||||
//*************************************************************************
|
||||
const Node* find_upper_node(const Node* position, const key_value_parameter_t& key) const
|
||||
{
|
||||
// Keep track of parent of last upper node
|
||||
const Node* upper_node = nullptr;
|
||||
// Start with position provided
|
||||
const Node* node = position;
|
||||
while (node)
|
||||
{
|
||||
// Downcast position to Data_Node reference for key comparisons
|
||||
const Data_Node& data_node = imap::data_cast(*node);
|
||||
// Compare the key value to the current upper node key value
|
||||
if (node_comp(key, data_node))
|
||||
{
|
||||
upper_node = node;
|
||||
node = node->children[kLeft];
|
||||
}
|
||||
else if (node_comp(data_node, key))
|
||||
{
|
||||
node = node->children[kRight];
|
||||
}
|
||||
else if (node->children[kRight])
|
||||
{
|
||||
upper_node = find_limit_node(node->children[kRight], kLeft);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the upper node position found (might be nullptr)
|
||||
return upper_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Insert a node.
|
||||
//*************************************************************************
|
||||
|
||||
1830
imultimap.h
Normal file
1830
imultimap.h
Normal file
File diff suppressed because it is too large
Load Diff
1813
imultiset.h
Normal file
1813
imultiset.h
Normal file
File diff suppressed because it is too large
Load Diff
220
ipriority_queue.h
Normal file
220
ipriority_queue.h
Normal file
@ -0,0 +1,220 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2015 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_IPRIORITY_QUEUE__
|
||||
#define __ETL_IPRIORITY_QUEUE__
|
||||
#define __ETL_IN_IPRIORITY_QUEUE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "priority_queue_base.h"
|
||||
#include "type_traits.h"
|
||||
#include "parameter_type.h"
|
||||
|
||||
#ifndef ETL_THROW_EXCEPTIONS
|
||||
#include "error_handler.h"
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
///\ingroup queue
|
||||
///\brief This is the base for all priority queues that contain a particular type.
|
||||
///\details Normally a reference to this type will be taken from a derived queue.
|
||||
/// The TContainer specified must provide the front, push_back, pop_back, and
|
||||
/// assign methods to work correctly with priority_queue.
|
||||
///\code
|
||||
/// etl::priority_queue<int, 10> myPriorityQueue;
|
||||
/// etl::ipriority_queue<int>& iQueue = myPriorityQueue;
|
||||
///\endcode
|
||||
/// \warning This priority queue cannot be used for concurrent access from
|
||||
/// multiple threads.
|
||||
/// \tparam T The type of value that the queue holds.
|
||||
/// \tparam TContainer to hold the T queue values
|
||||
/// \tparam TCompare to use in comparing T values
|
||||
//***************************************************************************
|
||||
template <typename T, typename TContainer, typename TCompare>
|
||||
class ipriority_queue : public priority_queue_base
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type; ///< The type stored in the queue.
|
||||
typedef TContainer container_type; ///< The container type used for priority queue.
|
||||
typedef T& reference; ///< A reference to the type used in the queue.
|
||||
typedef const T& const_reference; ///< A const reference to the type used in the queue.
|
||||
typedef priority_queue_base::size_type size_type; ///< The type used for determining the size of the queue.
|
||||
typedef typename std::iterator_traits<typename TContainer::iterator>::difference_type difference_type;
|
||||
|
||||
private:
|
||||
|
||||
typedef typename parameter_type<T>::type parameter_t;
|
||||
|
||||
public:
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a reference to the highest priority value in the priority queue.<br>
|
||||
/// \return A reference to the highest priority value in the priority queue.
|
||||
//*************************************************************************
|
||||
reference top()
|
||||
{
|
||||
return container.front();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a const reference to the highest priority value in the priority queue.<br>
|
||||
/// \return A const reference to the highest priority value in the priority queue.
|
||||
//*************************************************************************
|
||||
const_reference top() const
|
||||
{
|
||||
return container.front();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Adds a value to the queue.
|
||||
/// If ETL_THROW_EXCEPTIONS is defined, throws an etl::priority_queue_full
|
||||
/// is the priority queue is already full, otherwise does nothing if full.
|
||||
///\param value The value to push to the queue.
|
||||
//*************************************************************************
|
||||
void push(parameter_t value)
|
||||
{
|
||||
if (!full())
|
||||
{
|
||||
// Put element at end
|
||||
container.push_back(value);
|
||||
// Pre-increment size
|
||||
++current_size;
|
||||
// Make elements in container into heap
|
||||
std::push_heap(container.begin(), container.end(), TCompare());
|
||||
}
|
||||
else
|
||||
#ifdef ETL_THROW_EXCEPTIONS
|
||||
{
|
||||
throw priority_queue_full();
|
||||
}
|
||||
#else
|
||||
{
|
||||
error_handler::error(priority_queue_full());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Clears the queue to the empty state.
|
||||
//*************************************************************************
|
||||
void clear()
|
||||
{
|
||||
container.clear();
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Assigns values to the priority queue.
|
||||
/// If ETL_THROW_EXCEPTIONS is defined, emits priority_queue_full if
|
||||
/// priority queue does not have enough free space.
|
||||
/// If ETL_THROW_EXCEPTIONS is defined, emits priority_iterator if the
|
||||
/// iterators are reversed.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*********************************************************************
|
||||
template <typename TIterator>
|
||||
void assign(TIterator first, TIterator last)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
difference_type count = std::distance(first, last);
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
#ifdef ETL_THROW_EXCEPTIONS
|
||||
throw priority_queue_iterator();
|
||||
#else
|
||||
error_handler::error(priority_queue_iterator());
|
||||
#endif
|
||||
}
|
||||
|
||||
if (static_cast<size_t>(count) > MAX_SIZE)
|
||||
{
|
||||
#ifdef ETL_THROW_EXCEPTIONS
|
||||
throw priority_queue_full();
|
||||
#else
|
||||
error_handler::error(priority_queue_full());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
clear();
|
||||
container.assign(first, last);
|
||||
std::make_heap(container.begin(), container.end(), TCompare());
|
||||
current_size = container.size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Removes the oldest value from the back of the priority queue.
|
||||
/// Does nothing if the priority queue is already empty.
|
||||
//*************************************************************************
|
||||
void pop()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
// Move largest element to end
|
||||
std::pop_heap(container.begin(), container.end(), TCompare());
|
||||
// Actually remove largest element at end
|
||||
container.pop_back();
|
||||
// Decrement size
|
||||
--current_size;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//*************************************************************************
|
||||
/// Make this a clone of the supplied priority queue
|
||||
//*************************************************************************
|
||||
void clone(const ipriority_queue& other)
|
||||
{
|
||||
assign(other.container.cbegin(), other.container.cend());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// The constructor that is called from derived classes.
|
||||
//*************************************************************************
|
||||
ipriority_queue(size_type max_size)
|
||||
: priority_queue_base(max_size)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// The container specified at instantiation of the priority_queue
|
||||
TContainer container;
|
||||
};
|
||||
}
|
||||
|
||||
#undef __ETL_IN_IPRIORITY_QUEUE_H__
|
||||
#endif
|
||||
2
iqueue.h
2
iqueue.h
@ -63,7 +63,7 @@ namespace etl
|
||||
typedef T& reference; ///< A reference to the type used in the queue.
|
||||
typedef const T& const_reference; ///< A const reference to the type used in the queue.
|
||||
typedef T* pointer; ///< A pointer to the type used in the queue.
|
||||
typedef const T* const_pointer; ///< A const pointer to the type used in the qu
|
||||
typedef const T* const_pointer; ///< A const pointer to the type used in the queue.
|
||||
typedef queue_base::size_type size_type; ///< The type used for determining the size of the queue.
|
||||
|
||||
private:
|
||||
|
||||
87
iset.h
87
iset.h
@ -4,6 +4,7 @@
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
@ -134,7 +135,7 @@ namespace etl
|
||||
value_type value;
|
||||
};
|
||||
|
||||
/// Defines the key parameter type
|
||||
/// Defines the key value parameter type
|
||||
typedef typename parameter_type<T>::type key_value_parameter_t;
|
||||
|
||||
//*************************************************************************
|
||||
@ -299,9 +300,9 @@ namespace etl
|
||||
};
|
||||
friend iterator;
|
||||
|
||||
////*************************************************************************
|
||||
///// const_iterator
|
||||
////*************************************************************************
|
||||
//*************************************************************************
|
||||
/// const_iterator
|
||||
//*************************************************************************
|
||||
class const_iterator : public std::iterator<std::bidirectional_iterator_tag, const value_type>
|
||||
{
|
||||
public:
|
||||
@ -695,7 +696,7 @@ namespace etl
|
||||
///\param position The position that would precede the value to insert.
|
||||
///\param value The value to insert.
|
||||
//*********************************************************************
|
||||
iterator insert(iterator position, value_type& value)
|
||||
iterator insert(iterator, value_type& value)
|
||||
{
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
@ -706,7 +707,7 @@ namespace etl
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(find_node(root_node, position.p_node), node);
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -727,7 +728,7 @@ namespace etl
|
||||
///\param position The position that would precede the value to insert.
|
||||
///\param value The value to insert.
|
||||
//*********************************************************************
|
||||
iterator insert(const_iterator position, value_type& value)
|
||||
iterator insert(const_iterator, value_type& value)
|
||||
{
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
@ -738,7 +739,7 @@ namespace etl
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(find_node(root_node, position.p_node), node);
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1067,7 +1068,7 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
// Return root node if nothing or duplicate was found
|
||||
// Return root node if nothing was found
|
||||
return root_node;
|
||||
}
|
||||
|
||||
@ -1240,36 +1241,6 @@ namespace etl
|
||||
return lower_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is not considered to go before the key provided
|
||||
//*************************************************************************
|
||||
const Node& find_lower_node(const Node* position, const key_value_parameter_t& key) const
|
||||
{
|
||||
// Something at this position? keep going
|
||||
const Node* lower_node = position;
|
||||
while (lower_node)
|
||||
{
|
||||
// Downcast lower node to Data_Node reference for key comparisons
|
||||
const Data_Node& data_node = iset::data_cast(*lower_node);
|
||||
// Compare the key value to the current lower node key value
|
||||
if (node_comp(key, data_node))
|
||||
{
|
||||
lower_node = lower_node->children[kLeft];
|
||||
}
|
||||
else if (node_comp(data_node, key))
|
||||
{
|
||||
lower_node = lower_node->children[kRight];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the lower_node position found
|
||||
return lower_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is considered to go after the key provided
|
||||
//*************************************************************************
|
||||
@ -1308,44 +1279,6 @@ namespace etl
|
||||
return upper_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Find the node whose key is considered to go after the key provided
|
||||
//*************************************************************************
|
||||
const Node* find_upper_node(const Node* position, const key_value_parameter_t& key) const
|
||||
{
|
||||
// Keep track of parent of last upper node
|
||||
const Node* upper_node = nullptr;
|
||||
// Start with position provided
|
||||
const Node* node = position;
|
||||
while (node)
|
||||
{
|
||||
// Downcast position to Data_Node reference for key comparisons
|
||||
const Data_Node& data_node = iset::data_cast(*node);
|
||||
// Compare the key value to the current upper node key value
|
||||
if (node_comp(key, data_node))
|
||||
{
|
||||
upper_node = node;
|
||||
node = node->children[kLeft];
|
||||
}
|
||||
else if (node_comp(data_node, key))
|
||||
{
|
||||
node = node->children[kRight];
|
||||
}
|
||||
else if (node->children[kRight])
|
||||
{
|
||||
upper_node = find_limit_node(node->children[kRight], kLeft);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the upper node position found (might be nullptr)
|
||||
return upper_node;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Insert a node.
|
||||
//*************************************************************************
|
||||
|
||||
@ -27,8 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_IN_IMAP_H__
|
||||
#error This header is a private element of etl::map & etl::imap
|
||||
#if !defined(__ETL_IN_IMAP_H__) && !defined(__ETL_IN_IMULTIMAP_H__)
|
||||
#error This header is a private element of etl::map, etl::multimap & etl::imap, etl::imultimap
|
||||
#endif
|
||||
|
||||
#ifndef __ETL_MAP_BASE__
|
||||
|
||||
110
multimap.h
Normal file
110
multimap.h
Normal file
@ -0,0 +1,110 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_MULTIMAP__
|
||||
#define __ETL_MULTIMAP__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
|
||||
#include "imultimap.h"
|
||||
#include "container.h"
|
||||
#include "pool.h"
|
||||
|
||||
//*****************************************************************************
|
||||
/// A multimap with the capacity defined at compile time.
|
||||
///\ingroup containers
|
||||
//*****************************************************************************
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//*************************************************************************
|
||||
/// A templated multimap implementation that uses a fixed size buffer.
|
||||
//*************************************************************************
|
||||
template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = std::less<TKey>>
|
||||
class multimap : public imultimap<TKey, TValue, TCompare>
|
||||
{
|
||||
public:
|
||||
|
||||
static const size_t MAX_SIZE = MAX_SIZE_;
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
multimap()
|
||||
: imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
//*************************************************************************
|
||||
explicit multimap(const multimap& other)
|
||||
: imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imultimap<TKey, TValue, TCompare>::assign(other.cbegin(), other.cend());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
multimap(TIterator first, TIterator last)
|
||||
: imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imultimap<TKey, TValue, TCompare>::insert(first, last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
multimap& operator = (const multimap& rhs)
|
||||
{
|
||||
// Skip if doing self assignment
|
||||
if (this != &rhs)
|
||||
{
|
||||
imultimap<TKey, TValue, TCompare>::assign(rhs.cbegin(), rhs.cend());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// The pool of data nodes used for the multimap.
|
||||
pool<typename imultimap<TKey, TValue, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
110
multiset.h
Normal file
110
multiset.h
Normal file
@ -0,0 +1,110 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_MULTISET__
|
||||
#define __ETL_MULTISET__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
|
||||
#include "imultiset.h"
|
||||
#include "container.h"
|
||||
#include "pool.h"
|
||||
|
||||
//*****************************************************************************
|
||||
/// A multiset with the capacity defined at compile time.
|
||||
///\ingroup containers
|
||||
//*****************************************************************************
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//*************************************************************************
|
||||
/// A templated multiset implementation that uses a fixed size buffer.
|
||||
//*************************************************************************
|
||||
template <typename T, const size_t MAX_SIZE_, typename TCompare = std::less<TKey>>
|
||||
class multiset : public imultiset<T, TCompare>
|
||||
{
|
||||
public:
|
||||
|
||||
static const size_t MAX_SIZE = MAX_SIZE_;
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
multiset()
|
||||
: imultiset<T, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
//*************************************************************************
|
||||
explicit multiset(const multiset& other)
|
||||
: imultiset<T, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imultiset<T, TCompare>::assign(other.cbegin(), other.cend());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
multiset(TIterator first, TIterator last)
|
||||
: imultiset<T, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imultiset<T, TCompare>::insert(first, last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
multiset& operator = (const multiset& rhs)
|
||||
{
|
||||
// Skip if doing self assignment
|
||||
if (this != &rhs)
|
||||
{
|
||||
imultiset<T, TCompare>::assign(rhs.cbegin(), rhs.cend());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// The pool of data nodes used for the multiset.
|
||||
pool<typename imultiset<T, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
114
priority_queue.h
Normal file
114
priority_queue.h
Normal file
@ -0,0 +1,114 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2015 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PRIORITY_QUEUE__
|
||||
#define __ETL_PRIORITY_QUEUE__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <functional>
|
||||
|
||||
#include "ipriority_queue.h"
|
||||
#include "container.h"
|
||||
#include "vector.h"
|
||||
|
||||
//*****************************************************************************
|
||||
///\defgroup queue queue
|
||||
/// A priority queue with the capacity defined at compile time,
|
||||
/// written in the STL style.
|
||||
///\ingroup containers
|
||||
//*****************************************************************************
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
///\ingroup queue
|
||||
/// A fixed capacity queue.
|
||||
/// This queue does not support concurrent access by different threads.
|
||||
/// \tparam T The type this queue should support.
|
||||
/// \tparam SIZE The maximum capacity of the queue.
|
||||
//***************************************************************************
|
||||
template <typename T, const size_t SIZE, typename TContainer = etl::vector<T, SIZE>, typename TCompare = std::less<typename TContainer::value_type> >
|
||||
class priority_queue : public ipriority_queue<T, TContainer, TCompare>
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
priority_queue()
|
||||
: ipriority_queue<T, TContainer, TCompare>(SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor
|
||||
//*************************************************************************
|
||||
priority_queue(const priority_queue& rhs)
|
||||
: ipriority_queue<T, TContainer, TCompare>(SIZE)
|
||||
{
|
||||
ipriority_queue<T, TContainer, TCompare>::clone(rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
priority_queue(TIterator first, TIterator last)
|
||||
: ipriority_queue<T, TContainer, TCompare>(SIZE)
|
||||
{
|
||||
ipriority_queue<T, TContainer, TCompare>::assign(first, last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Destructor.
|
||||
//*************************************************************************
|
||||
~priority_queue()
|
||||
{
|
||||
ipriority_queue<T, TContainer, TCompare>::clear();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
priority_queue& operator = (const priority_queue& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
ipriority_queue<T, TContainer, TCompare>::clone(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
154
priority_queue_base.h
Normal file
154
priority_queue_base.h
Normal file
@ -0,0 +1,154 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2015 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_IN_IPRIORITY_QUEUE_H__
|
||||
#error This header is a private element of etl::priority_queue & etl::ipriority_queue
|
||||
#endif
|
||||
|
||||
#ifndef __ETL_PRIORITY_QUEUE_BASE__
|
||||
#define __ETL_PRIORITY_QUEUE_BASE__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// The base class for priority_queue exceptions.
|
||||
///\ingroup queue
|
||||
//***************************************************************************
|
||||
class priority_queue_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
priority_queue_exception(const char* what)
|
||||
: exception(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The exception thrown when the queue is full.
|
||||
///\ingroup queue
|
||||
//***************************************************************************
|
||||
class priority_queue_full : public priority_queue_exception
|
||||
{
|
||||
public:
|
||||
|
||||
priority_queue_full()
|
||||
: priority_queue_exception("priority_queue: full")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The priority queue iterator exception on reversed iterators
|
||||
///\ingroup queue
|
||||
//***************************************************************************
|
||||
class priority_queue_iterator : public priority_queue_exception
|
||||
{
|
||||
public:
|
||||
|
||||
priority_queue_iterator()
|
||||
: priority_queue_exception("priority_queue: iterator error")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The base class for all priority queues.
|
||||
///\ingroup queue
|
||||
//***************************************************************************
|
||||
class priority_queue_base
|
||||
{
|
||||
public:
|
||||
|
||||
typedef size_t size_type; ///< The type used for determining the size of queue.
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the current number of items in the priority queue.
|
||||
//*************************************************************************
|
||||
size_type size() const
|
||||
{
|
||||
return current_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the maximum number of items that can be queued.
|
||||
//*************************************************************************
|
||||
size_type max_size() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the priority queue is empty.
|
||||
/// \return <b>true</b> if the queue is empty, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return current_size == 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the priority queue is full.
|
||||
/// \return <b>true</b> if the priority queue is full, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
bool full() const
|
||||
{
|
||||
return current_size == MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the remaining capacity.
|
||||
///\return The remaining capacity.
|
||||
//*************************************************************************
|
||||
size_t available() const
|
||||
{
|
||||
return max_size() - size();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//*************************************************************************
|
||||
/// The constructor that is called from derived classes.
|
||||
//*************************************************************************
|
||||
priority_queue_base(size_type max_size)
|
||||
: current_size(0),
|
||||
MAX_SIZE(max_size)
|
||||
{
|
||||
}
|
||||
|
||||
size_type current_size; ///< The number of items in the priority queue.
|
||||
const size_type MAX_SIZE; ///< The maximum number of items in the priority queue.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
2
queue.h
2
queue.h
@ -99,7 +99,7 @@ namespace etl
|
||||
|
||||
private:
|
||||
|
||||
/// The unititialised buffer of T used in the stack.
|
||||
/// The uninitialised buffer of T used in the stack.
|
||||
typename etl::aligned_storage<sizeof(T), etl::alignment_of<T>::value>::type buffer[SIZE];
|
||||
};
|
||||
}
|
||||
|
||||
1
set.h
1
set.h
@ -4,6 +4,7 @@
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
@ -26,8 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_IN_ISET_H__
|
||||
#error This header is a private element of etl::set & etl::iset
|
||||
#if !defined(__ETL_IN_ISET_H__) && !defined(__ETL_IN_IMULTISET_H__)
|
||||
#error This header is a private element of etl::set, etl::multiset & etl::iset, etl::imultiset
|
||||
#endif
|
||||
|
||||
#ifndef __ETL_SET_BASE__
|
||||
|
||||
@ -35,8 +35,6 @@ SOFTWARE.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../map.h"
|
||||
|
||||
static const size_t SIZE = 10;
|
||||
@ -478,7 +476,6 @@ namespace
|
||||
CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::map_full);
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_equal_range)
|
||||
{
|
||||
|
||||
949
test/test_multimap.cpp
Normal file
949
test/test_multimap.cpp
Normal file
@ -0,0 +1,949 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include "../multimap.h"
|
||||
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
#define TEST_GREATER_THAN
|
||||
#ifdef TEST_GREATER_THAN
|
||||
typedef etl::multimap<std::string, int, SIZE, std::greater<std::string> > Data;
|
||||
typedef std::multimap<std::string, int, std::greater<std::string> > Compare_Data;
|
||||
#else
|
||||
typedef etl::multimap<std::string, int, SIZE, std::less<std::string> > Data;
|
||||
typedef std::multimap<std::string, int, std::less<std::string> > Compare_Data;
|
||||
#endif
|
||||
|
||||
typedef Data::iterator Data_iterator;
|
||||
typedef Data::const_iterator Data_const_iterator;
|
||||
typedef Compare_Data::iterator Compare_Data_iterator;
|
||||
typedef Compare_Data::const_iterator Compare_Data_const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_multimap)
|
||||
{
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
bool Check_Equal(T1 begin1, T1 end1, T2 begin2)
|
||||
{
|
||||
while (begin1 != end1)
|
||||
{
|
||||
if ((begin1->first != begin2->first) || (begin1->second != begin2->second))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++begin1;
|
||||
++begin2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
{
|
||||
// Multimaps of predefined data from which to constuct multimaps used in
|
||||
// each test
|
||||
std::multimap<std::string, int> initial_data;
|
||||
std::multimap<std::string, int> excess_data;
|
||||
std::multimap<std::string, int> different_data;
|
||||
std::multimap<std::string, int> random_data;
|
||||
|
||||
SetupFixture()
|
||||
{
|
||||
// Create a map of initial data
|
||||
initial_data.insert(std::pair<std::string, int>("0", 0));
|
||||
initial_data.insert(std::pair<std::string, int>("0", 1));
|
||||
initial_data.insert(std::pair<std::string, int>("1", 2));
|
||||
initial_data.insert(std::pair<std::string, int>("1", 3));
|
||||
initial_data.insert(std::pair<std::string, int>("1", 4));
|
||||
initial_data.insert(std::pair<std::string, int>("2", 5));
|
||||
initial_data.insert(std::pair<std::string, int>("2", 8));
|
||||
initial_data.insert(std::pair<std::string, int>("2", 7));
|
||||
initial_data.insert(std::pair<std::string, int>("3", 6));
|
||||
initial_data.insert(std::pair<std::string, int>("4", 9));
|
||||
|
||||
// Create a multimap of excess data
|
||||
excess_data.insert(std::pair<std::string, int>("0", 0));
|
||||
excess_data.insert(std::pair<std::string, int>("1", 1));
|
||||
excess_data.insert(std::pair<std::string, int>("2", 2));
|
||||
excess_data.insert(std::pair<std::string, int>("2", 3));
|
||||
excess_data.insert(std::pair<std::string, int>("3", 6));
|
||||
excess_data.insert(std::pair<std::string, int>("3", 5));
|
||||
excess_data.insert(std::pair<std::string, int>("3", 4));
|
||||
excess_data.insert(std::pair<std::string, int>("4", 7));
|
||||
excess_data.insert(std::pair<std::string, int>("5", 8));
|
||||
excess_data.insert(std::pair<std::string, int>("6", 9));
|
||||
excess_data.insert(std::pair<std::string, int>("10", 10));
|
||||
|
||||
// Create a multimap of different data
|
||||
different_data.insert(std::pair<std::string, int>("10", 10));
|
||||
different_data.insert(std::pair<std::string, int>("11", 11));
|
||||
different_data.insert(std::pair<std::string, int>("12", 12));
|
||||
different_data.insert(std::pair<std::string, int>("13", 13));
|
||||
different_data.insert(std::pair<std::string, int>("14", 14));
|
||||
different_data.insert(std::pair<std::string, int>("15", 15));
|
||||
different_data.insert(std::pair<std::string, int>("16", 16));
|
||||
different_data.insert(std::pair<std::string, int>("17", 17));
|
||||
different_data.insert(std::pair<std::string, int>("18", 18));
|
||||
different_data.insert(std::pair<std::string, int>("19", 19));
|
||||
|
||||
// Create a multimap of random data
|
||||
random_data.insert(std::pair<std::string, int>("3", 6));
|
||||
random_data.insert(std::pair<std::string, int>("3", 5));
|
||||
random_data.insert(std::pair<std::string, int>("0", 0));
|
||||
random_data.insert(std::pair<std::string, int>("5", 8));
|
||||
random_data.insert(std::pair<std::string, int>("6", 9));
|
||||
random_data.insert(std::pair<std::string, int>("2", 2));
|
||||
random_data.insert(std::pair<std::string, int>("0", 1));
|
||||
random_data.insert(std::pair<std::string, int>("2", 3));
|
||||
random_data.insert(std::pair<std::string, int>("4", 7));
|
||||
random_data.insert(std::pair<std::string, int>("3", 4));
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK_EQUAL(data.capacity(), SIZE);
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
CHECK(data.size() == SIZE);
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assignment)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
Data otherData;
|
||||
|
||||
otherData = data;
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
otherData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_begin)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
const Data constData(data);
|
||||
|
||||
CHECK_EQUAL(data.begin(), std::begin(data));
|
||||
CHECK_EQUAL(constData.begin(), std::begin(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_end)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
const Data constData(data);
|
||||
|
||||
CHECK_EQUAL(data.end(), std::end(data));
|
||||
CHECK_EQUAL(constData.end(), std::end(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_empty)
|
||||
{
|
||||
Data data;
|
||||
data.insert(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(data.full());
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_full)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK(!data.full());
|
||||
CHECK(data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assign_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data;
|
||||
|
||||
data.assign(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result =
|
||||
data.insert(Data::value_type(std::string("2"), 1));
|
||||
Compare_Data::iterator compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("2"), 1));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
data_result = data.insert(Data::value_type(std::string("1"), 1));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("1"), 1));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
data_result = data.insert(Data::value_type(std::string("2"), 2));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("2"), 2));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
data_result = data.insert(Data::value_type(std::string("3"), 3));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("3"), 3));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
// Adding this next 2 will trigger a 3 node rotate RL on insert
|
||||
data_result = data.insert(Data::value_type(std::string("2"), 3));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("2"), 3));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
// Adding this next 4 will trigger a 2 node rotate left on insert
|
||||
data_result = data.insert(Data::value_type(std::string("4"), 4));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("4"), 4));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
data_result = data.insert(Data::value_type(std::string("0"), 0));
|
||||
compare_result = compare_data.insert(std::make_pair(std::string("0"), 0));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
// Check that elements in map are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_hint_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result =
|
||||
data.insert(Data::value_type(std::string("0"), 0));
|
||||
Compare_Data::iterator compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("0"), 0));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
// Check that elements in map are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
data.insert(data_result, std::make_pair(std::string("1"), 1));
|
||||
compare_data.insert(compare_result, std::make_pair(std::string("1"), 1));
|
||||
|
||||
isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_const_hint_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result =
|
||||
data.insert(Data::value_type(std::string("2"), 0));
|
||||
Compare_Data::iterator compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("2"), 0));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(compare_result->first, data_result->first);
|
||||
CHECK_EQUAL(compare_result->second, data_result->second);
|
||||
|
||||
// Check that elements in map are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
data.insert(Data::const_iterator(data_result),
|
||||
std::make_pair(std::string("1"), 1));
|
||||
compare_data.insert(Compare_Data::const_iterator(compare_result),
|
||||
std::make_pair(std::string("1"), 1));
|
||||
|
||||
isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_value_excess)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_THROW(data.insert(std::make_pair(std::string("10"), 10)), etl::map_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
data.insert(initial_data.begin(), initial_data.end());
|
||||
compare_data.insert(initial_data.begin(), initial_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range_random)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
data.insert(random_data.begin(), random_data.end());
|
||||
compare_data.insert(random_data.begin(), random_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range_excess)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::map_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_equal_range)
|
||||
{
|
||||
Compare_Data compare_data(random_data.begin(), random_data.end());
|
||||
Data data(random_data.begin(), random_data.end());
|
||||
|
||||
// Test a number not available
|
||||
std::pair<Data::iterator, Data::iterator> data_result =
|
||||
data.equal_range("1");
|
||||
std::pair<Compare_Data::iterator, Compare_Data::iterator> compare_result =
|
||||
compare_data.equal_range("1");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_result.first->first, data_result.first->first);
|
||||
CHECK_EQUAL(compare_result.first->second, data_result.first->second);
|
||||
CHECK_EQUAL(compare_result.second->first, data_result.second->first);
|
||||
CHECK_EQUAL(compare_result.second->second, data_result.second->second);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_equal_range)
|
||||
{
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
// Test a number with several of the same key
|
||||
std::pair<Data::const_iterator, Data::const_iterator> data_result =
|
||||
data.equal_range("2");
|
||||
std::pair<Compare_Data::const_iterator, Compare_Data::const_iterator> compare_result =
|
||||
compare_data.equal_range("2");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_result.first->first, data_result.first->first);
|
||||
CHECK_EQUAL(compare_result.first->second, data_result.first->second);
|
||||
CHECK_EQUAL(compare_result.second->first, data_result.second->first);
|
||||
CHECK_EQUAL(compare_result.second->second, data_result.second->second);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_value)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
size_t compare_count = compare_data.erase("2");
|
||||
size_t data_count = data.erase("2");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
// Erase another value
|
||||
compare_count = compare_data.erase("1");
|
||||
data_count = data.erase("1");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
// Erase another value
|
||||
compare_count = compare_data.erase("3");
|
||||
data_count = data.erase("3");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_single)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.begin();
|
||||
Data::iterator i_data = data.begin();
|
||||
|
||||
compare_data.erase(i_compare);
|
||||
data.erase(i_data);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_erase_single)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.cbegin();
|
||||
Data::const_iterator i_data = data.cbegin();
|
||||
|
||||
std::advance(i_compare, 8);
|
||||
std::advance(i_data, 8);
|
||||
|
||||
Compare_Data::const_iterator i_compare1 = compare_data.erase(i_compare);
|
||||
Data::const_iterator i_data1 = data.erase(i_data);
|
||||
|
||||
CHECK_EQUAL(i_compare1->second, i_data1->second);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_range)
|
||||
{
|
||||
Compare_Data compare_data(random_data.begin(), random_data.end());
|
||||
Data data(random_data.begin(), random_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.begin();
|
||||
Data::iterator i_data = data.begin();
|
||||
|
||||
Compare_Data::iterator i_compare_end = compare_data.begin();
|
||||
Data::iterator i_data_end = data.begin();
|
||||
|
||||
std::advance(i_compare, 1);
|
||||
std::advance(i_data, 1);
|
||||
|
||||
std::advance(i_compare_end, 4);
|
||||
std::advance(i_data_end, 4);
|
||||
|
||||
compare_data.erase(i_compare, i_compare_end);
|
||||
data.erase(i_data, i_data_end);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_erase_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
compare_data.erase(compare_data.cbegin(), compare_data.cend());
|
||||
data.erase(data.cbegin(), data.cend());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_clear)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
data.clear();
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_count)
|
||||
{
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_EQUAL(compare_data.count("."), data.count("."));
|
||||
CHECK_EQUAL(compare_data.count("0"), data.count("0"));
|
||||
CHECK_EQUAL(compare_data.count("1"), data.count("1"));
|
||||
CHECK_EQUAL(compare_data.count("2"), data.count("2"));
|
||||
CHECK_EQUAL(compare_data.count("3"), data.count("3"));
|
||||
CHECK_EQUAL(compare_data.count("4"), data.count("4"));
|
||||
CHECK_EQUAL(compare_data.count("A"), data.count("A"));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.cbegin(),
|
||||
data.cend(),
|
||||
compare_data.cbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_reverse_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.rbegin(),
|
||||
data.rend(),
|
||||
compare_data.rbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.crbegin(),
|
||||
data.crend(),
|
||||
compare_data.crbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_find)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::iterator i_data = data.find("0");
|
||||
Compare_Data::iterator i_compare = compare_data.find("0");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("1");
|
||||
i_compare = compare_data.find("1");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("2");
|
||||
i_compare = compare_data.find("2");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("3");
|
||||
i_compare = compare_data.find("3");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find(".");
|
||||
i_compare = compare_data.find(".");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.find("A");
|
||||
i_compare = compare_data.find("A");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_find_const)
|
||||
{
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::const_iterator i_data = data.find("0");
|
||||
Compare_Data::const_iterator i_compare = compare_data.find("0");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("1");
|
||||
i_compare = compare_data.find("1");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("2");
|
||||
i_compare = compare_data.find("2");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find("3");
|
||||
i_compare = compare_data.find("3");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(i_compare->first, i_data->first);
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.find(".");
|
||||
i_compare = compare_data.find(".");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.find("A");
|
||||
i_compare = compare_data.find("A");
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_equal)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(initial1 == initial2);
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(!(initial1 == different));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_not_equal)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(!(initial1 != initial2));
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(initial1 != different);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_lower_bound)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.lower_bound("2");
|
||||
Data::iterator i_data = data.lower_bound("2");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.lower_bound(".");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(".");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound("A");
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
#else
|
||||
i_compare = compare_data.lower_bound(".");
|
||||
i_data = data.lower_bound(".");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_compare = compare_data.lower_bound("A");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_lower_bound_const)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.lower_bound("4");
|
||||
Data::const_iterator i_data = data.lower_bound("4");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.lower_bound(".");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(".");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound("A");
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
#else
|
||||
i_compare = compare_data.lower_bound(".");
|
||||
i_data = data.lower_bound(".");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_compare = compare_data.lower_bound("A");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_upper_bound)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.upper_bound("1");
|
||||
Data::iterator i_data = data.upper_bound("1");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.upper_bound(".");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(".");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound("A");
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
#else
|
||||
i_compare = compare_data.upper_bound(".");
|
||||
i_data = data.upper_bound(".");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_compare = compare_data.upper_bound("A");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_upper_bound_const)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.upper_bound("3");
|
||||
Data::const_iterator i_data = data.upper_bound("3");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.upper_bound(".");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(".");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound("A");
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
#else
|
||||
i_compare = compare_data.upper_bound(".");
|
||||
i_data = data.upper_bound(".");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_compare = compare_data.upper_bound("A");
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
912
test/test_multiset.cpp
Normal file
912
test/test_multiset.cpp
Normal file
@ -0,0 +1,912 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include <set>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include "../multiset.h"
|
||||
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
#define TEST_GREATER_THAN
|
||||
#ifdef TEST_GREATER_THAN
|
||||
typedef etl::multiset<int, SIZE, std::greater<int> > Data;
|
||||
typedef std::multiset<int, std::greater<int> > Compare_Data;
|
||||
#else
|
||||
typedef etl::multiset<int, SIZE, std::less<int> > Data;
|
||||
typedef std::multiset<int, std::less<int> > Compare_Data;
|
||||
#endif
|
||||
|
||||
typedef Data::iterator Data_iterator;
|
||||
typedef Data::const_iterator Data_const_iterator;
|
||||
typedef Compare_Data::iterator Compare_Data_iterator;
|
||||
typedef Compare_Data::const_iterator Compare_Data_const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_multiset)
|
||||
{
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
bool Check_Equal(T1 begin1, T1 end1, T2 begin2)
|
||||
{
|
||||
while (begin1 != end1)
|
||||
{
|
||||
if (*begin1 != *begin2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++begin1;
|
||||
++begin2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
{
|
||||
// Multisets of predefined data from which to constuct multisets used in
|
||||
// each test
|
||||
std::multiset<int> initial_data;
|
||||
std::multiset<int> excess_data;
|
||||
std::multiset<int> different_data;
|
||||
std::multiset<int> random_data;
|
||||
|
||||
SetupFixture()
|
||||
{
|
||||
// Create a multiset of initial data
|
||||
initial_data.insert(0);
|
||||
initial_data.insert(0);
|
||||
initial_data.insert(1);
|
||||
initial_data.insert(1);
|
||||
initial_data.insert(1);
|
||||
initial_data.insert(2);
|
||||
initial_data.insert(2);
|
||||
initial_data.insert(2);
|
||||
initial_data.insert(3);
|
||||
initial_data.insert(4);
|
||||
|
||||
// Create a multiset of excess data
|
||||
excess_data.insert(0);
|
||||
excess_data.insert(1);
|
||||
excess_data.insert(2);
|
||||
excess_data.insert(2);
|
||||
excess_data.insert(3);
|
||||
excess_data.insert(3);
|
||||
excess_data.insert(3);
|
||||
excess_data.insert(4);
|
||||
excess_data.insert(5);
|
||||
excess_data.insert(6);
|
||||
excess_data.insert(10);
|
||||
|
||||
// Create a multiset of different data
|
||||
different_data.insert(10);
|
||||
different_data.insert(11);
|
||||
different_data.insert(12);
|
||||
different_data.insert(13);
|
||||
different_data.insert(14);
|
||||
different_data.insert(15);
|
||||
different_data.insert(16);
|
||||
different_data.insert(17);
|
||||
different_data.insert(18);
|
||||
different_data.insert(19);
|
||||
|
||||
// Create a multiset of random data
|
||||
random_data.insert(3);
|
||||
random_data.insert(3);
|
||||
random_data.insert(0);
|
||||
random_data.insert(5);
|
||||
random_data.insert(6);
|
||||
random_data.insert(2);
|
||||
random_data.insert(0);
|
||||
random_data.insert(2);
|
||||
random_data.insert(4);
|
||||
random_data.insert(3);
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK_EQUAL(data.capacity(), SIZE);
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
CHECK(data.size() == SIZE);
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assignment)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
Data otherData;
|
||||
|
||||
otherData = data;
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
otherData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_begin)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
const Data constData(data);
|
||||
|
||||
CHECK_EQUAL(data.begin(), std::begin(data));
|
||||
CHECK_EQUAL(constData.begin(), std::begin(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_end)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
const Data constData(data);
|
||||
|
||||
CHECK_EQUAL(data.end(), std::end(data));
|
||||
CHECK_EQUAL(constData.end(), std::end(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_empty)
|
||||
{
|
||||
Data data;
|
||||
data.insert(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(data.full());
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_full)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK(!data.full());
|
||||
CHECK(data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assign_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data;
|
||||
|
||||
data.assign(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result = data.insert(2);
|
||||
Compare_Data::iterator compare_result = compare_data.insert(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
data_result = data.insert(1);
|
||||
compare_result = compare_data.insert(1);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
data_result = data.insert(2);
|
||||
compare_result = compare_data.insert(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
data_result = data.insert(3);
|
||||
compare_result = compare_data.insert(3);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
// Adding this next 2 will trigger a 3 node rotate RL on insert
|
||||
data_result = data.insert(2);
|
||||
compare_result = compare_data.insert(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
// Adding this next 4 will trigger a 2 node rotate left on insert
|
||||
data_result = data.insert(4);
|
||||
compare_result = compare_data.insert(4);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
data_result = data.insert(0);
|
||||
compare_result = compare_data.insert(0);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
// Check that elements in multiset are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_hint_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result = data.insert(0);
|
||||
Compare_Data::iterator compare_result = compare_data.insert(0);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
// Check that elements in multiset are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
data.insert(data_result, 1);
|
||||
compare_data.insert(compare_result, 1);
|
||||
|
||||
isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_const_hint_value)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
Data::iterator data_result = data.insert(2);
|
||||
Compare_Data::iterator compare_result = compare_data.insert(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*compare_result, *data_result);
|
||||
|
||||
// Check that elements in multiset are the same
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
data.insert(Data::const_iterator(data_result), 1);
|
||||
compare_data.insert(Compare_Data::const_iterator(compare_result), 1);
|
||||
|
||||
isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_value_excess)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_THROW(data.insert(10), etl::set_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
data.insert(initial_data.begin(), initial_data.end());
|
||||
compare_data.insert(initial_data.begin(), initial_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range_random)
|
||||
{
|
||||
Compare_Data compare_data;
|
||||
Data data;
|
||||
|
||||
data.insert(random_data.begin(), random_data.end());
|
||||
compare_data.insert(random_data.begin(), random_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_insert_range_excess)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::set_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_equal_range)
|
||||
{
|
||||
Compare_Data compare_data(random_data.begin(), random_data.end());
|
||||
Data data(random_data.begin(), random_data.end());
|
||||
|
||||
// Test a number not available
|
||||
std::pair<Data::iterator, Data::iterator> data_result =
|
||||
data.equal_range(1);
|
||||
std::pair<Compare_Data::iterator, Compare_Data::iterator> compare_result =
|
||||
compare_data.equal_range(1);
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(*compare_result.first, *data_result.first);
|
||||
CHECK_EQUAL(*compare_result.second, *data_result.second);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_equal_range)
|
||||
{
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
// Test a number with several of the same key
|
||||
std::pair<Data::const_iterator, Data::const_iterator> data_result =
|
||||
data.equal_range(2);
|
||||
std::pair<Compare_Data::const_iterator, Compare_Data::const_iterator> compare_result =
|
||||
compare_data.equal_range(2);
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(*compare_result.first, *data_result.first);
|
||||
CHECK_EQUAL(*compare_result.second, *data_result.second);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_value)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
size_t compare_count = compare_data.erase(2);
|
||||
size_t data_count = data.erase(2);
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
// Erase another value
|
||||
compare_count = compare_data.erase(1);
|
||||
data_count = data.erase(1);
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
// Erase another value
|
||||
compare_count = compare_data.erase(3);
|
||||
data_count = data.erase(3);
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(compare_count, data_count);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_single)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.begin();
|
||||
Data::iterator i_data = data.begin();
|
||||
|
||||
compare_data.erase(i_compare);
|
||||
data.erase(i_data);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_erase_single)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.cbegin();
|
||||
Data::const_iterator i_data = data.cbegin();
|
||||
|
||||
std::advance(i_compare, 8);
|
||||
std::advance(i_data, 8);
|
||||
|
||||
Compare_Data::const_iterator i_compare1 = compare_data.erase(i_compare);
|
||||
Data::const_iterator i_data1 = data.erase(i_data);
|
||||
|
||||
CHECK_EQUAL(*i_compare1, *i_data1);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_range)
|
||||
{
|
||||
Compare_Data compare_data(random_data.begin(), random_data.end());
|
||||
Data data(random_data.begin(), random_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.begin();
|
||||
Data::iterator i_data = data.begin();
|
||||
|
||||
Compare_Data::iterator i_compare_end = compare_data.begin();
|
||||
Data::iterator i_data_end = data.begin();
|
||||
|
||||
std::advance(i_compare, 1);
|
||||
std::advance(i_data, 1);
|
||||
|
||||
std::advance(i_compare_end, 4);
|
||||
std::advance(i_data_end, 4);
|
||||
|
||||
compare_data.erase(i_compare, i_compare_end);
|
||||
data.erase(i_data, i_data_end);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_erase_range)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
compare_data.erase(compare_data.cbegin(), compare_data.cend());
|
||||
data.erase(data.cbegin(), data.cend());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_clear)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
data.clear();
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_count)
|
||||
{
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_EQUAL(compare_data.count(-1), data.count(-1));
|
||||
CHECK_EQUAL(compare_data.count(0), data.count(0));
|
||||
CHECK_EQUAL(compare_data.count(1), data.count(1));
|
||||
CHECK_EQUAL(compare_data.count(2), data.count(2));
|
||||
CHECK_EQUAL(compare_data.count(3), data.count(3));
|
||||
CHECK_EQUAL(compare_data.count(4), data.count(4));
|
||||
CHECK_EQUAL(compare_data.count(99), data.count(99));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.cbegin(),
|
||||
data.cend(),
|
||||
compare_data.cbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_reverse_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.rbegin(),
|
||||
data.rend(),
|
||||
compare_data.rbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
bool isEqual = Check_Equal(data.crbegin(),
|
||||
data.crend(),
|
||||
compare_data.crbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_find)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::iterator i_data = data.find(0);
|
||||
Compare_Data::iterator i_compare = compare_data.find(0);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(1);
|
||||
i_compare = compare_data.find(1);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(2);
|
||||
i_compare = compare_data.find(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(3);
|
||||
i_compare = compare_data.find(3);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(-1);
|
||||
i_compare = compare_data.find(-1);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.find(99);
|
||||
i_compare = compare_data.find(99);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_find_const)
|
||||
{
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::const_iterator i_data = data.find(0);
|
||||
Compare_Data::const_iterator i_compare = compare_data.find(0);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(1);
|
||||
i_compare = compare_data.find(1);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(2);
|
||||
i_compare = compare_data.find(2);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(3);
|
||||
i_compare = compare_data.find(3);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_data = data.find(-1);
|
||||
i_compare = compare_data.find(-1);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.find(99);
|
||||
i_compare = compare_data.find(99);
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_equal)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(initial1 == initial2);
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(!(initial1 == different));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_not_equal)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(!(initial1 != initial2));
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(initial1 != different);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_lower_bound)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.lower_bound(2);
|
||||
Data::iterator i_data = data.lower_bound(2);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.lower_bound(-1);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(-1);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound(99);
|
||||
i_data = data.lower_bound(99);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
#else
|
||||
i_compare = compare_data.lower_bound(-1);
|
||||
i_data = data.lower_bound(-1);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound(99);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(99);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_lower_bound_const)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.lower_bound(4);
|
||||
Data::const_iterator i_data = data.lower_bound(4);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.lower_bound(-1);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(-1);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound(99);
|
||||
i_data = data.lower_bound(99);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
#else
|
||||
i_compare = compare_data.lower_bound(-1);
|
||||
i_data = data.lower_bound(-1);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_compare = compare_data.lower_bound(99);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.lower_bound(99);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_upper_bound)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator i_compare = compare_data.upper_bound(1);
|
||||
Data::iterator i_data = data.upper_bound(1);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.upper_bound(-1);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(-1);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound(99);
|
||||
i_data = data.upper_bound(99);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
#else
|
||||
i_compare = compare_data.upper_bound(-1);
|
||||
i_data = data.upper_bound(-1);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound(99);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(99);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_upper_bound_const)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator i_compare = compare_data.upper_bound(3);
|
||||
Data::const_iterator i_data = data.upper_bound(3);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
#ifdef TEST_GREATER_THAN
|
||||
i_compare = compare_data.upper_bound(-1);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(-1);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound(99);
|
||||
i_data = data.upper_bound(99);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
#else
|
||||
i_compare = compare_data.upper_bound(-1);
|
||||
i_data = data.upper_bound(-1);
|
||||
CHECK_EQUAL(*i_compare, *i_data);
|
||||
|
||||
i_compare = compare_data.upper_bound(99);
|
||||
CHECK_EQUAL(compare_data.end(), i_compare);
|
||||
|
||||
i_data = data.upper_bound(99);
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
353
test/test_priority_queue.cpp
Normal file
353
test/test_priority_queue.cpp
Normal file
@ -0,0 +1,353 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2015 jwellbelove, rlindeman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "../priority_queue.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_priority_queue)
|
||||
{
|
||||
static const size_t SIZE = 4;
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_default_constructor)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
CHECK_EQUAL(priority_queue.size(), size_t(0));
|
||||
CHECK_EQUAL(priority_queue.available(), SIZE);
|
||||
CHECK_EQUAL(priority_queue.max_size(), SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_copy_constructor)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(3);
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(4);
|
||||
priority_queue.push(2);
|
||||
|
||||
etl::priority_queue<int, SIZE> priority_queue2(priority_queue);
|
||||
|
||||
CHECK(priority_queue.size() == priority_queue2.size());
|
||||
|
||||
while (!priority_queue.empty())
|
||||
{
|
||||
CHECK_EQUAL(priority_queue.top(), priority_queue2.top());
|
||||
priority_queue.pop();
|
||||
priority_queue2.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_range)
|
||||
{
|
||||
int n[] = { 3, 4, 1, 2 };
|
||||
etl::priority_queue<int, SIZE> priority_queue(std::begin(n), std::end(n));
|
||||
std::priority_queue<int> compare_priority_queue(std::begin(n), std::end(n));
|
||||
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK(!priority_queue.empty());
|
||||
|
||||
while (!priority_queue.empty())
|
||||
{
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
compare_priority_queue.pop();
|
||||
priority_queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_size)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(2);
|
||||
priority_queue.push(3);
|
||||
|
||||
CHECK_EQUAL(3, priority_queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_clear)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(2);
|
||||
priority_queue.clear();
|
||||
CHECK_EQUAL(0, priority_queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assign_range)
|
||||
{
|
||||
int n[] = { 3, 4, 1, 2 };
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
std::priority_queue<int> compare_priority_queue(std::begin(n), std::end(n));
|
||||
|
||||
priority_queue.assign(std::begin(n), std::end(n));
|
||||
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK(!priority_queue.empty());
|
||||
|
||||
while (!priority_queue.empty())
|
||||
{
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
compare_priority_queue.pop();
|
||||
priority_queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_empty)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
CHECK(priority_queue.empty());
|
||||
|
||||
priority_queue.push(1);
|
||||
|
||||
CHECK(!priority_queue.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_full)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
CHECK(!priority_queue.full());
|
||||
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(2);
|
||||
priority_queue.push(3);
|
||||
priority_queue.push(4);
|
||||
|
||||
CHECK(priority_queue.full());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_top)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
std::priority_queue<int> compare_priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(3);
|
||||
compare_priority_queue.push(3);
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(2);
|
||||
compare_priority_queue.push(2);
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(4);
|
||||
compare_priority_queue.push(4);
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_top_const)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
const etl::priority_queue<int, SIZE>& constQueue = priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
CHECK_EQUAL(1, constQueue.top());
|
||||
priority_queue.push(3);
|
||||
CHECK_EQUAL(3, constQueue.top());
|
||||
priority_queue.push(2);
|
||||
CHECK_EQUAL(3, constQueue.top());
|
||||
priority_queue.push(4);
|
||||
CHECK_EQUAL(4, constQueue.top());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_push)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
std::priority_queue<int> compare_priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
|
||||
priority_queue.push(2);
|
||||
compare_priority_queue.push(2);
|
||||
|
||||
priority_queue.push(3);
|
||||
compare_priority_queue.push(3);
|
||||
|
||||
priority_queue.push(4);
|
||||
compare_priority_queue.push(4);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_push_excess)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
for (size_t i = 0; i < priority_queue.max_size(); ++i)
|
||||
{
|
||||
priority_queue.push(1);
|
||||
}
|
||||
|
||||
CHECK_THROW(priority_queue.push(1), etl::priority_queue_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
std::priority_queue<int> compare_priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
|
||||
priority_queue.push(3);
|
||||
compare_priority_queue.push(3);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(2);
|
||||
compare_priority_queue.push(2);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.push(1);
|
||||
compare_priority_queue.push(1);
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
CHECK_EQUAL(compare_priority_queue.top(), priority_queue.top());
|
||||
|
||||
priority_queue.pop();
|
||||
compare_priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
|
||||
// Go one beyond (which we handle without throwing)
|
||||
priority_queue.pop();
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assignment)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(4);
|
||||
priority_queue.push(3);
|
||||
priority_queue.push(2);
|
||||
|
||||
etl::priority_queue<int, SIZE> priority_queue2;
|
||||
|
||||
priority_queue2 = priority_queue;
|
||||
|
||||
CHECK(priority_queue.size() == priority_queue2.size());
|
||||
|
||||
while (!priority_queue.empty())
|
||||
{
|
||||
CHECK_EQUAL(priority_queue.top(), priority_queue2.top());
|
||||
priority_queue.pop();
|
||||
priority_queue2.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_self_assignment)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(2);
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(4);
|
||||
priority_queue.push(3);
|
||||
|
||||
priority_queue = priority_queue;
|
||||
|
||||
CHECK(priority_queue.max_size() == priority_queue.size());
|
||||
|
||||
CHECK_EQUAL(4, priority_queue.top());
|
||||
priority_queue.pop();
|
||||
|
||||
CHECK_EQUAL(3, priority_queue.top());
|
||||
priority_queue.pop();
|
||||
|
||||
CHECK_EQUAL(2, priority_queue.top());
|
||||
priority_queue.pop();
|
||||
|
||||
CHECK_EQUAL(1, priority_queue.top());
|
||||
priority_queue.pop();
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 jwellbelove, rlindeman
|
||||
|
||||
@ -53,25 +54,25 @@ typedef Compare_Data::iterator Compare_Data_iterator;
|
||||
typedef Compare_Data::const_iterator Compare_Data_const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it) << " " << (*it);
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it) << " " << (*it);
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it) << " " << (*it);
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -156,10 +156,13 @@
|
||||
<ClInclude Include="..\..\ilist.h" />
|
||||
<ClInclude Include="..\..\iflat_map.h" />
|
||||
<ClInclude Include="..\..\imap.h" />
|
||||
<ClInclude Include="..\..\imultimap.h" />
|
||||
<ClInclude Include="..\..\imultiset.h" />
|
||||
<ClInclude Include="..\..\instance_count.h" />
|
||||
<ClInclude Include="..\..\integral_limits.h" />
|
||||
<ClInclude Include="..\..\io_port.h" />
|
||||
<ClInclude Include="..\..\ipool.h" />
|
||||
<ClInclude Include="..\..\ipriority_queue.h" />
|
||||
<ClInclude Include="..\..\iqueue.h" />
|
||||
<ClInclude Include="..\..\iset.h" />
|
||||
<ClInclude Include="..\..\istack.h" />
|
||||
@ -174,6 +177,8 @@
|
||||
<ClInclude Include="..\..\flat_map_base.h" />
|
||||
<ClInclude Include="..\..\map.h" />
|
||||
<ClInclude Include="..\..\map_base.h" />
|
||||
<ClInclude Include="..\..\multimap.h" />
|
||||
<ClInclude Include="..\..\multiset.h" />
|
||||
<ClInclude Include="..\..\nullptr.h" />
|
||||
<ClInclude Include="..\..\numeric.h" />
|
||||
<ClInclude Include="..\..\observer.h" />
|
||||
@ -182,6 +187,8 @@
|
||||
<ClInclude Include="..\..\pool.h" />
|
||||
<ClInclude Include="..\..\pool_base.h" />
|
||||
<ClInclude Include="..\..\power.h" />
|
||||
<ClInclude Include="..\..\priority_queue.h" />
|
||||
<ClInclude Include="..\..\priority_queue_base.h" />
|
||||
<ClInclude Include="..\..\queue.h" />
|
||||
<ClInclude Include="..\..\queue_base.h" />
|
||||
<ClInclude Include="..\..\radix.h" />
|
||||
@ -268,12 +275,15 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_map.cpp" />
|
||||
<ClCompile Include="..\test_maths.cpp" />
|
||||
<ClCompile Include="..\test_multimap.cpp" />
|
||||
<ClCompile Include="..\test_multiset.cpp" />
|
||||
<ClCompile Include="..\test_numeric.cpp" />
|
||||
<ClCompile Include="..\test_observer.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_optional.cpp" />
|
||||
<ClCompile Include="..\test_pool.cpp" />
|
||||
<ClCompile Include="..\test_priority_queue.cpp" />
|
||||
<ClCompile Include="..\test_queue.cpp" />
|
||||
<ClCompile Include="..\test_set.cpp" />
|
||||
<ClCompile Include="..\test_smallest.cpp" />
|
||||
|
||||
@ -375,6 +375,27 @@
|
||||
<ClInclude Include="..\..\set_base.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\imultimap.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\multimap.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\imultiset.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\multiset.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\ipriority_queue.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\priority_queue.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\priority_queue_base.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\AssertException.cpp">
|
||||
@ -584,6 +605,15 @@
|
||||
<ClCompile Include="..\test_set.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_multimap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_multiset.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_priority_queue.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\Doxyfile">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user