Skip to content
Snippets Groups Projects
Commit 4d3c7301 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add test for conversion of deque, valarray and unordered_set

parent 74b93636
No related branches found
No related tags found
1 merge request!11Feature/mpi
...@@ -106,6 +106,7 @@ class Array ...@@ -106,6 +106,7 @@ class Array
~Array() = default; ~Array() = default;
}; };
// map, multimap, unordered_map and stack cannot be copied this way
template <typename Container> template <typename Container>
PASTIS_INLINE PASTIS_INLINE
Array<std::remove_const_t<typename Container::value_type>> Array<std::remove_const_t<typename Container::value_type>>
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <list> #include <list>
#include <deque>
#include <valarray>
#include <unordered_set>
// Instantiate to ensure full coverage is performed // Instantiate to ensure full coverage is performed
template class Array<int>; template class Array<int>;
...@@ -176,6 +179,15 @@ TEST_CASE("Array", "[utils]") { ...@@ -176,6 +179,15 @@ TEST_CASE("Array", "[utils]") {
} }
} }
{
std::valarray<int> v{1,2,5,3};
Array<int> v_array = convert_to_array(v);
REQUIRE(v_array.size() == v.size());
REQUIRE(((v_array[0] == 1) and (v_array[1] == 2) and
(v_array[2] == 5) and (v_array[3] == 3)));
}
{ {
std::set<int> s{4,2,5,3,1,3,2}; std::set<int> s{4,2,5,3,1,3,2};
Array<int> s_array = convert_to_array(s); Array<int> s_array = convert_to_array(s);
...@@ -186,6 +198,20 @@ TEST_CASE("Array", "[utils]") { ...@@ -186,6 +198,20 @@ TEST_CASE("Array", "[utils]") {
(s_array[4] == 5))); (s_array[4] == 5)));
} }
{
std::unordered_set<int> us{4,2,5,3,1,3,2};
Array<int> us_array = convert_to_array(us);
REQUIRE(us_array.size() == us.size());
std::set<int> s;
for (size_t i=0; i<us_array.size(); ++i) {
REQUIRE((us.find(us_array[i]) != us.end()));
s.insert(us_array[i]);
}
REQUIRE(s.size() == us_array.size());
}
{ {
std::multiset<int> ms{4,2,5,3,1,3,2}; std::multiset<int> ms{4,2,5,3,1,3,2};
Array<int> ms_array = convert_to_array(ms); Array<int> ms_array = convert_to_array(ms);
...@@ -206,6 +232,17 @@ TEST_CASE("Array", "[utils]") { ...@@ -206,6 +232,17 @@ TEST_CASE("Array", "[utils]") {
(l_array[2] == 5) and (l_array[3] == 6) and (l_array[2] == 5) and (l_array[3] == 6) and
(l_array[4] == 2))); (l_array[4] == 2)));
} }
{
std::deque<int> q{1,3,5,6,2};
q.push_front(2);
Array<int> q_array = convert_to_array(q);
REQUIRE(q_array.size() == q.size());
REQUIRE(((q_array[0] == 2) and (q_array[1] == 1) and
(q_array[2] == 3) and (q_array[3] == 5) and
(q_array[4] == 6) and (q_array[5] == 2)));
}
} }
#ifndef NDEBUG #ifndef NDEBUG
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment