mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-19 02:16:55 +08:00
initial release of etl::map without balance
This commit is contained in:
parent
647f952b23
commit
5e67f1502a
110
map.h
Normal file
110
map.h
Normal file
@ -0,0 +1,110 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
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_MAP__
|
||||
#define __ETL_MAP__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
|
||||
#include "imap.h"
|
||||
#include "container.h"
|
||||
#include "pool.h"
|
||||
|
||||
//*****************************************************************************
|
||||
///\defgroup map map
|
||||
/// A map with the capacity defined at compile time.
|
||||
///\ingroup containers
|
||||
//*****************************************************************************
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//*************************************************************************
|
||||
/// A templated map implementation that uses a fixed size buffer.
|
||||
//*************************************************************************
|
||||
template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = std::less<TKey>>
|
||||
class map : public imap<TKey, TValue, TCompare>
|
||||
{
|
||||
public:
|
||||
|
||||
static const size_t MAX_SIZE = MAX_SIZE_;
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
map()
|
||||
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
//*************************************************************************
|
||||
explicit map(const map& other)
|
||||
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imap<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>
|
||||
map(TIterator first, TIterator last)
|
||||
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
|
||||
{
|
||||
imap<TKey, TValue, TCompare>::insert(first, last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
map& operator = (const map& rhs)
|
||||
{
|
||||
// Skip if doing self assignment
|
||||
if (this != &rhs)
|
||||
{
|
||||
imap<TKey, TValue, TCompare>::assign(rhs.cbegin(), rhs.cend());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// The pool of data nodes used for the map.
|
||||
pool<typename imap<TKey, TValue, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
174
map_base.h
Normal file
174
map_base.h
Normal file
@ -0,0 +1,174 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
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_IN_IMAP_H__
|
||||
#error This header is a private element of etl::map & etl::imap
|
||||
#endif
|
||||
|
||||
#ifndef __ETL_MAP_BASE__
|
||||
#define __ETL_MAP_BASE__
|
||||
|
||||
#include <stddef.h>
|
||||
#include "exception.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Exception for the map.
|
||||
///\ingroup map
|
||||
//***************************************************************************
|
||||
class map_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
map_exception(const char* what)
|
||||
: exception(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Full exception for the map.
|
||||
///\ingroup map
|
||||
//***************************************************************************
|
||||
class map_full : public map_exception
|
||||
{
|
||||
public:
|
||||
|
||||
map_full()
|
||||
: map_exception("map: full")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Map out of bounds exception.
|
||||
///\ingroup map
|
||||
//***************************************************************************
|
||||
class map_out_of_bounds : public map_exception
|
||||
{
|
||||
public:
|
||||
|
||||
map_out_of_bounds()
|
||||
: map_exception("map: out of bounds")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Iterator exception for the map.
|
||||
///\ingroup map
|
||||
//***************************************************************************
|
||||
class map_iterator : public map_exception
|
||||
{
|
||||
public:
|
||||
|
||||
map_iterator()
|
||||
: map_exception("map: iterator problem")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The base class for all maps.
|
||||
///\ingroup map
|
||||
//***************************************************************************
|
||||
class map_base
|
||||
{
|
||||
public:
|
||||
|
||||
typedef size_t size_type; ///< The type used for determining the size of map.
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the size of the map.
|
||||
//*************************************************************************
|
||||
size_type size() const
|
||||
{
|
||||
return current_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the map.
|
||||
//*************************************************************************
|
||||
size_type max_size() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the map is empty.
|
||||
//*************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return current_size == 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the map is full.
|
||||
//*************************************************************************
|
||||
bool full() const
|
||||
{
|
||||
return current_size == MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the capacity of the vector.
|
||||
///\return The capacity of the vector.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return 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.
|
||||
//*************************************************************************
|
||||
map_base(size_type max_size)
|
||||
: current_size(0)
|
||||
, MAX_SIZE(max_size)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
size_type current_size; ///< The number of the used nodes.
|
||||
const size_type MAX_SIZE; ///< The maximum size of the map.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -149,6 +149,7 @@
|
||||
<Unit filename="../../iforward_list.h" />
|
||||
<Unit filename="../../ilist.h" />
|
||||
<Unit filename="../../ilookup.h" />
|
||||
<Unit filename="../../imap.h" />
|
||||
<Unit filename="../../instance_count.h" />
|
||||
<Unit filename="../../integral_limits.h" />
|
||||
<Unit filename="../../iqueue.h" />
|
||||
@ -160,6 +161,8 @@
|
||||
<Unit filename="../../log.h" />
|
||||
<Unit filename="../../lookup.h" />
|
||||
<Unit filename="../../lookup_base.h" />
|
||||
<Unit filename="../../map.h" />
|
||||
<Unit filename="../../map_base.h" />
|
||||
<Unit filename="../../nullptr.h" />
|
||||
<Unit filename="../../numeric.h" />
|
||||
<Unit filename="../../observer.h" />
|
||||
@ -203,6 +206,7 @@
|
||||
<Unit filename="../test_largest.cpp" />
|
||||
<Unit filename="../test_list.cpp" />
|
||||
<Unit filename="../test_lookup.cpp" />
|
||||
<Unit filename="../test_map.cpp" />
|
||||
<Unit filename="../test_maths.cpp" />
|
||||
<Unit filename="../test_numeric.cpp" />
|
||||
<Unit filename="../test_observer.cpp" />
|
||||
|
||||
@ -340,6 +340,16 @@
|
||||
<list>
|
||||
<vector>
|
||||
|
||||
1421601674 source:u:\users\john\documents\programming\github\etl\test\test_map.cpp
|
||||
<UnitTest++/UnitTest++.h>
|
||||
"ExtraCheckMacros.h"
|
||||
"../map.h"
|
||||
"data.h"
|
||||
<algorithm>
|
||||
<array>
|
||||
<map>
|
||||
<vector>
|
||||
|
||||
1418906586 u:\users\john\documents\programming\github\etl\test\extracheckmacros.h
|
||||
<UnitTest++/HelperMacros.h>
|
||||
<UnitTest++/ExceptionMacros.h>
|
||||
@ -358,6 +368,12 @@
|
||||
"container.h"
|
||||
"pool.h"
|
||||
|
||||
1421601517 u:\users\john\documents\programming\github\etl\map.h
|
||||
<stddef.h>
|
||||
"imap.h"
|
||||
"container.h"
|
||||
"pool.h"
|
||||
|
||||
1421608839 u:\users\john\documents\programming\github\etl\ilist.h
|
||||
<iterator>
|
||||
<algorithm>
|
||||
@ -369,10 +385,25 @@
|
||||
"parameter_type.h"
|
||||
"pool.h"
|
||||
|
||||
1421608839 u:\users\john\documents\programming\github\etl\imap.h
|
||||
<iterator>
|
||||
<algorithm>
|
||||
<functional>
|
||||
<stddef.h>
|
||||
"nullptr.h"
|
||||
"map_base.h"
|
||||
"type_traits.h"
|
||||
"parameter_type.h"
|
||||
"pool.h"
|
||||
|
||||
1421068120 u:\users\john\documents\programming\github\etl\list_base.h
|
||||
<stddef.h>
|
||||
"exception.h"
|
||||
|
||||
1421068120 u:\users\john\documents\programming\github\etl\map_base.h
|
||||
<stddef.h>
|
||||
"exception.h"
|
||||
|
||||
1414930704 source:u:\users\john\documents\programming\github\etl\test\test_math.cpp
|
||||
<UnitTest++/UnitTest++.h>
|
||||
"../log.h"
|
||||
|
||||
@ -31,6 +31,11 @@
|
||||
<Cursor1 position="17660" topLine="539" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="..\..\imap.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="17660" topLine="539" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="..\..\ilookup.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="10573" topLine="244" />
|
||||
@ -96,6 +101,11 @@
|
||||
<Cursor1 position="5955" topLine="137" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="..\..\map.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="5955" topLine="137" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="..\..\endian.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="2235" topLine="37" />
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<file>$PROJ_DIR$\..\..\ideque.h</file>
|
||||
<file>$PROJ_DIR$\..\..\iforward_list.h</file>
|
||||
<file>$PROJ_DIR$\..\..\ilist.h</file>
|
||||
<file>$PROJ_DIR$\..\..\imap.h</file>
|
||||
<file>$PROJ_DIR$\..\..\ipool.h</file>
|
||||
<file>$PROJ_DIR$\..\..\integral_limits.h</file>
|
||||
<file>$PROJ_DIR$\..\..\iqueue.h</file>
|
||||
@ -52,6 +53,8 @@
|
||||
<file>$PROJ_DIR$\..\..\list.h</file>
|
||||
<file>$PROJ_DIR$\..\..\list_base.h</file>
|
||||
<file>$PROJ_DIR$\..\..\log.h</file>
|
||||
<file>$PROJ_DIR$\..\..\map.h</file>
|
||||
<file>$PROJ_DIR$\..\..\map_base.h</file>
|
||||
<file>$PROJ_DIR$\..\..\nullptr.h</file>
|
||||
<file>$PROJ_DIR$\..\..\observer.h</file>
|
||||
<file>$PROJ_DIR$\..\..\parameter_type.h</file>
|
||||
|
||||
@ -1994,6 +1994,9 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\ilist.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\imap.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\integral_limits.h</name>
|
||||
</file>
|
||||
@ -2018,6 +2021,12 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\list_base.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\map.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\map_base.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\log.h</name>
|
||||
</file>
|
||||
|
||||
@ -277,6 +277,9 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\ilist.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\imap.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\integral_limits.h</name>
|
||||
</file>
|
||||
@ -301,6 +304,12 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\list_base.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\map.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\map_base.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\log.h</name>
|
||||
</file>
|
||||
|
||||
@ -642,6 +642,19 @@
|
||||
<Focus>0</Focus>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\imap.h</PathWithFileName>
|
||||
<FilenameWithoutPath>imap.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\integral_limits.h</PathWithFileName>
|
||||
<FilenameWithoutPath>integral_limits.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
@ -649,7 +662,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -662,7 +675,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -675,7 +688,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -688,7 +701,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -701,7 +714,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileNumber>41</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -714,7 +727,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>41</FileNumber>
|
||||
<FileNumber>42</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -727,7 +740,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>42</FileNumber>
|
||||
<FileNumber>43</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -740,7 +753,33 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>43</FileNumber>
|
||||
<FileNumber>44</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\map.h</PathWithFileName>
|
||||
<FilenameWithoutPath>map.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>45</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\map_base.h</PathWithFileName>
|
||||
<FilenameWithoutPath>map_base.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>46</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -753,7 +792,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>44</FileNumber>
|
||||
<FileNumber>47</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -766,7 +805,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>45</FileNumber>
|
||||
<FileNumber>48</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -779,7 +818,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>46</FileNumber>
|
||||
<FileNumber>49</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -792,7 +831,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>47</FileNumber>
|
||||
<FileNumber>50</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -805,7 +844,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>48</FileNumber>
|
||||
<FileNumber>51</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -818,7 +857,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>49</FileNumber>
|
||||
<FileNumber>52</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -831,7 +870,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>50</FileNumber>
|
||||
<FileNumber>53</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -844,7 +883,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>51</FileNumber>
|
||||
<FileNumber>54</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -857,7 +896,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>52</FileNumber>
|
||||
<FileNumber>55</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -870,7 +909,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>53</FileNumber>
|
||||
<FileNumber>56</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -883,7 +922,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>54</FileNumber>
|
||||
<FileNumber>57</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -896,7 +935,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>55</FileNumber>
|
||||
<FileNumber>58</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -909,7 +948,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>56</FileNumber>
|
||||
<FileNumber>59</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -922,7 +961,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>57</FileNumber>
|
||||
<FileNumber>60</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -935,7 +974,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>58</FileNumber>
|
||||
<FileNumber>61</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -948,7 +987,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>59</FileNumber>
|
||||
<FileNumber>62</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -961,7 +1000,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>60</FileNumber>
|
||||
<FileNumber>63</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -974,7 +1013,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>61</FileNumber>
|
||||
<FileNumber>64</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -987,7 +1026,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>62</FileNumber>
|
||||
<FileNumber>65</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1000,7 +1039,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>63</FileNumber>
|
||||
<FileNumber>66</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1013,7 +1052,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>64</FileNumber>
|
||||
<FileNumber>67</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1026,7 +1065,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>65</FileNumber>
|
||||
<FileNumber>68</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1039,7 +1078,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>66</FileNumber>
|
||||
<FileNumber>69</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
|
||||
@ -588,6 +588,11 @@
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\ilist.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>imap.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\imap.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>integral_limits.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
@ -628,6 +633,16 @@
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\list_base.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>map.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\map.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>map_base.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\map_base.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>log.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
|
||||
786
test/test_map.cpp
Normal file
786
test/test_map.cpp
Normal file
@ -0,0 +1,786 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
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 <vector>
|
||||
|
||||
#include <iostream> // FIXME: remove with cout
|
||||
|
||||
#include "../map.h"
|
||||
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
//typedef etl::map<std::string, int, SIZE, std::greater<std::string> > Data;
|
||||
//typedef std::map<std::string, int, std::greater<std::string> > Compare_Data;
|
||||
typedef etl::map<std::string, int, SIZE, std::less<std::string> > Data;
|
||||
typedef std::map<std::string, int, std::less<std::string> > Compare_Data;
|
||||
typedef Data::iterator Data_iterator;
|
||||
typedef Data::const_iterator Data_const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_map)
|
||||
{
|
||||
std::vector<Data::value_type> initial_data;
|
||||
std::vector<Data::value_type> excess_data;
|
||||
std::vector<Data::value_type> different_data;
|
||||
|
||||
//*************************************************************************
|
||||
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
|
||||
{
|
||||
SetupFixture()
|
||||
{
|
||||
Data::value_type n[] =
|
||||
{
|
||||
{ std::string("0"), 0 },
|
||||
{ std::string("1"), 1 },
|
||||
{ std::string("2"), 2 },
|
||||
{ std::string("3"), 3 },
|
||||
{ std::string("4"), 4 },
|
||||
{ std::string("5"), 5 },
|
||||
{ std::string("6"), 6 },
|
||||
{ std::string("7"), 7 },
|
||||
{ std::string("8"), 8 },
|
||||
{ std::string("9"), 9 },
|
||||
};
|
||||
|
||||
Data::value_type n2[] =
|
||||
{
|
||||
{ std::string("0"), 0 },
|
||||
{ std::string("1"), 1 },
|
||||
{ std::string("2"), 2 },
|
||||
{ std::string("3"), 3 },
|
||||
{ std::string("4"), 4 },
|
||||
{ std::string("5"), 5 },
|
||||
{ std::string("6"), 6 },
|
||||
{ std::string("7"), 7 },
|
||||
{ std::string("8"), 8 },
|
||||
{ std::string("9"), 9 },
|
||||
{ std::string("10"), 10 },
|
||||
};
|
||||
|
||||
Data::value_type n3[] =
|
||||
{
|
||||
{ std::string("10"), 10 },
|
||||
{ std::string("11"), 11 },
|
||||
{ std::string("12"), 12 },
|
||||
{ std::string("13"), 13 },
|
||||
{ std::string("14"), 14 },
|
||||
{ std::string("15"), 15 },
|
||||
{ std::string("16"), 16 },
|
||||
{ std::string("17"), 17 },
|
||||
{ std::string("18"), 18 },
|
||||
{ std::string("19"), 19 },
|
||||
};
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
excess_data.assign(std::begin(n2), std::end(n2));
|
||||
different_data.assign(std::begin(n3), std::end(n3));
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
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_index)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(compare_data.begin(), compare_data.end());
|
||||
|
||||
CHECK_EQUAL(data["0"], compare_data["0"]);
|
||||
CHECK_EQUAL(data["1"], compare_data["1"]);
|
||||
CHECK_EQUAL(data["2"], compare_data["2"]);
|
||||
CHECK_EQUAL(data["3"], compare_data["3"]);
|
||||
CHECK_EQUAL(data["4"], compare_data["4"]);
|
||||
CHECK_EQUAL(data["5"], compare_data["5"]);
|
||||
CHECK_EQUAL(data["6"], compare_data["6"]);
|
||||
CHECK_EQUAL(data["7"], compare_data["7"]);
|
||||
CHECK_EQUAL(data["8"], compare_data["8"]);
|
||||
CHECK_EQUAL(data["9"], compare_data["9"]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_at)
|
||||
{
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_EQUAL(data.at("0"), compare_data.at("0"));
|
||||
CHECK_EQUAL(data.at("1"), compare_data.at("1"));
|
||||
CHECK_EQUAL(data.at("2"), compare_data.at("2"));
|
||||
CHECK_EQUAL(data.at("3"), compare_data.at("3"));
|
||||
CHECK_EQUAL(data.at("4"), compare_data.at("4"));
|
||||
CHECK_EQUAL(data.at("5"), compare_data.at("5"));
|
||||
CHECK_EQUAL(data.at("6"), compare_data.at("6"));
|
||||
CHECK_EQUAL(data.at("7"), compare_data.at("7"));
|
||||
CHECK_EQUAL(data.at("8"), compare_data.at("8"));
|
||||
CHECK_EQUAL(data.at("9"), compare_data.at("9"));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_at_const)
|
||||
{
|
||||
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK_EQUAL(data.at("0"), compare_data.at("0"));
|
||||
CHECK_EQUAL(data.at("1"), compare_data.at("1"));
|
||||
CHECK_EQUAL(data.at("2"), compare_data.at("2"));
|
||||
CHECK_EQUAL(data.at("3"), compare_data.at("3"));
|
||||
CHECK_EQUAL(data.at("4"), compare_data.at("4"));
|
||||
CHECK_EQUAL(data.at("5"), compare_data.at("5"));
|
||||
CHECK_EQUAL(data.at("6"), compare_data.at("6"));
|
||||
CHECK_EQUAL(data.at("7"), compare_data.at("7"));
|
||||
CHECK_EQUAL(data.at("8"), compare_data.at("8"));
|
||||
CHECK_EQUAL(data.at("9"), compare_data.at("9"));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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;
|
||||
|
||||
std::pair<Data::iterator, bool> data_result =
|
||||
data.insert(Data::value_type(std::string("0"), 0));
|
||||
std::pair<Compare_Data::iterator, bool> compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("0"), 0));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.second, compare_result.second);
|
||||
|
||||
// Try adding a duplicate (should return iterator pointing to duplicate)
|
||||
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(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.second, compare_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(std::make_pair(std::string("2"), 2));
|
||||
compare_data.insert(std::make_pair(std::string("2"), 2));
|
||||
|
||||
isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
data.insert(std::make_pair(std::string("1"), 1));
|
||||
compare_data.insert(std::make_pair(std::string("1"), 1));
|
||||
|
||||
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;
|
||||
|
||||
std::pair<Data::iterator, bool> data_result =
|
||||
data.insert(Data::value_type(std::string("2"), 2));
|
||||
std::pair<Compare_Data::iterator, bool> compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("2"), 2));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.second, compare_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.first, std::make_pair(std::string("1"), 1));
|
||||
compare_data.insert(compare_result.first, 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;
|
||||
|
||||
std::pair<Data::iterator, bool> data_result =
|
||||
data.insert(Data::value_type(std::string("2"), 2));
|
||||
std::pair<Compare_Data::iterator, bool> compare_result =
|
||||
compare_data.insert(std::make_pair(std::string("2"), 2));
|
||||
|
||||
// Check that both return successful return results
|
||||
CHECK_EQUAL(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.second, compare_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.first),
|
||||
std::make_pair(std::string("1"), 1));
|
||||
compare_data.insert(Compare_Data::const_iterator(compare_result.first),
|
||||
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_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(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
std::pair<Data::iterator, Data::iterator> data_result =
|
||||
data.equal_range("2");
|
||||
std::pair<Compare_Data::iterator, Compare_Data::iterator> compare_result =
|
||||
compare_data.equal_range("2");
|
||||
|
||||
// Check that both return the same return results
|
||||
CHECK_EQUAL(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.first->second, compare_result.first->second);
|
||||
CHECK_EQUAL(data_result.second->first, compare_result.second->first);
|
||||
CHECK_EQUAL(data_result.second->second, compare_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());
|
||||
|
||||
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(data_result.first->first, compare_result.first->first);
|
||||
CHECK_EQUAL(data_result.first->second, compare_result.first->second);
|
||||
CHECK_EQUAL(data_result.second->first, compare_result.second->first);
|
||||
CHECK_EQUAL(data_result.second->second, compare_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());
|
||||
|
||||
compare_data.erase("5");
|
||||
data.erase("5");
|
||||
|
||||
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();
|
||||
|
||||
std::advance(i_compare, 2);
|
||||
std::advance(i_data, 2);
|
||||
|
||||
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.begin();
|
||||
Data::const_iterator i_data = data.begin();
|
||||
|
||||
std::advance(i_compare, 2);
|
||||
std::advance(i_data, 2);
|
||||
|
||||
bool isEqual = Check_Equal(data.begin(),
|
||||
data.end(),
|
||||
compare_data.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_erase_range)
|
||||
{
|
||||
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::iterator i_compare_end = compare_data.begin();
|
||||
Data::iterator i_data_end = data.begin();
|
||||
|
||||
std::advance(i_compare, 2);
|
||||
std::advance(i_data, 2);
|
||||
|
||||
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::const_iterator i_compare = compare_data.begin();
|
||||
Data::const_iterator i_data = data.begin();
|
||||
|
||||
Compare_Data::const_iterator i_compare_end = compare_data.begin();
|
||||
Data::const_iterator i_data_end = data.begin();
|
||||
|
||||
std::advance(i_compare, 2);
|
||||
std::advance(i_data, 2);
|
||||
|
||||
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_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());
|
||||
|
||||
CHECK_EQUAL(data.count("3"), size_t(1));
|
||||
|
||||
CHECK_EQUAL(data.count("A"), size_t(0));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::iterator it = data.find("3");
|
||||
CHECK_EQUAL(3, it->second);
|
||||
|
||||
it = data.find("A");
|
||||
CHECK_EQUAL(data.end(), it);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_find_const)
|
||||
{
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data::const_iterator it = data.find("3");
|
||||
CHECK_EQUAL(3, it->second);
|
||||
|
||||
it = data.find("A");
|
||||
CHECK_EQUAL(data.end(), it);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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("3");
|
||||
Data::iterator i_data = data.lower_bound("3");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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("3");
|
||||
Data::const_iterator i_data = data.lower_bound("3");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.lower_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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("7");
|
||||
Data::iterator i_data = data.upper_bound("7");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
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("7");
|
||||
Data::const_iterator i_data = data.upper_bound("7");
|
||||
CHECK_EQUAL(i_compare->second, i_data->second);
|
||||
|
||||
i_data = data.upper_bound("A");
|
||||
CHECK_EQUAL(data.end(), i_data);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
@ -146,6 +146,7 @@
|
||||
<ClInclude Include="..\..\iforward_list.h" />
|
||||
<ClInclude Include="..\..\ilist.h" />
|
||||
<ClInclude Include="..\..\ilookup.h" />
|
||||
<ClInclude Include="..\..\imap.h" />
|
||||
<ClInclude Include="..\..\instance_count.h" />
|
||||
<ClInclude Include="..\..\integral_limits.h" />
|
||||
<ClInclude Include="..\..\ipool.h" />
|
||||
@ -159,6 +160,8 @@
|
||||
<ClInclude Include="..\..\log.h" />
|
||||
<ClInclude Include="..\..\lookup.h" />
|
||||
<ClInclude Include="..\..\lookup_base.h" />
|
||||
<ClInclude Include="..\..\map.h" />
|
||||
<ClInclude Include="..\..\map_base.h" />
|
||||
<ClInclude Include="..\..\nullptr.h" />
|
||||
<ClInclude Include="..\..\numeric.h" />
|
||||
<ClInclude Include="..\..\observer.h" />
|
||||
@ -235,6 +238,7 @@
|
||||
<ClCompile Include="..\test_largest.cpp" />
|
||||
<ClCompile Include="..\test_list.cpp" />
|
||||
<ClCompile Include="..\test_lookup.cpp" />
|
||||
<ClCompile Include="..\test_map.cpp" />
|
||||
<ClCompile Include="..\test_maths.cpp" />
|
||||
<ClCompile Include="..\test_numeric.cpp" />
|
||||
<ClCompile Include="..\test_observer.cpp" />
|
||||
|
||||
@ -204,6 +204,15 @@
|
||||
<ClInclude Include="..\..\list_base.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\map.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\imap.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\map_base.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\crc16.h">
|
||||
<Filter>ETL\Maths</Filter>
|
||||
</ClInclude>
|
||||
@ -428,6 +437,9 @@
|
||||
<ClCompile Include="..\test_list.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_map.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_crc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user