Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
fdbc31d8
Commit
fdbc31d8
authored
4 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add tests
parent
cacad917
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SimoxUtility/tests/algorithm/CMakeLists.txt
+2
-1
2 additions, 1 deletion
SimoxUtility/tests/algorithm/CMakeLists.txt
SimoxUtility/tests/algorithm/get_map_keys_values.cpp
+101
-0
101 additions, 0 deletions
SimoxUtility/tests/algorithm/get_map_keys_values.cpp
with
103 additions
and
1 deletion
SimoxUtility/tests/algorithm/CMakeLists.txt
+
2
−
1
View file @
fdbc31d8
ADD_SU_TEST
(
apply
)
ADD_SU_TEST
(
for_each_if
)
ADD_SU_TEST
(
string_tools
)
ADD_SU_TEST
(
fuzzy_find
)
ADD_SU_TEST
(
get_map_keys_values
)
ADD_SU_TEST
(
string_tools
)
This diff is collapsed.
Click to expand it.
SimoxUtility/tests/algorithm/get_map_keys_values.cpp
0 → 100644
+
101
−
0
View file @
fdbc31d8
/**
* @package SimoxUtility
* @author Rainer Kartmann
* @copyright 2021 Rainer Kartmann
*/
#define BOOST_TEST_MODULE SimoxUtility/algorithm/get_map_keys_values
#include
<boost/test/included/unit_test.hpp>
#include
<SimoxUtility/algorithm/get_map_keys_values.h>
namespace
get_map_keys_values_test
{
struct
Fixture
{
std
::
map
<
int
,
std
::
string
>
map
{
{
1
,
"one"
},
{
2
,
"two"
},
{
3
,
"three"
},
};
const
std
::
map
<
int
,
std
::
string
>&
const_map
()
{
return
map
;
}
};
template
<
class
R
,
class
V
,
class
K
>
void
check_equal
(
const
std
::
vector
<
R
>&
values
,
const
std
::
map
<
K
,
V
>&
map
)
{
BOOST_CHECK_EQUAL
(
map
.
size
(),
values
.
size
());
auto
itv
=
values
.
begin
();
for
(
auto
itm
=
map
.
begin
();
itm
!=
map
.
end
();
++
itm
,
++
itv
)
{
if
constexpr
(
std
::
is_same_v
<
R
,
V
*>
||
std
::
is_same_v
<
R
,
const
V
*>
)
{
BOOST_CHECK_EQUAL
(
&
itm
->
second
,
*
itv
);
}
else
{
static_assert
(
std
::
is_same_v
<
R
,
V
>
,
"Expecting types to be equal."
);
BOOST_CHECK_EQUAL
(
itm
->
second
,
*
itv
);
}
}
}
}
BOOST_FIXTURE_TEST_SUITE
(
get_map_keys_values_test
,
get_map_keys_values_test
::
Fixture
)
BOOST_AUTO_TEST_CASE
(
test_get_values
)
{
std
::
vector
<
std
::
string
>
values
=
simox
::
alg
::
get_values
(
map
);
check_equal
(
values
,
map
);
}
BOOST_AUTO_TEST_CASE
(
test_get_values_unary_fn
)
{
std
::
vector
<
std
::
stringstream
>
values
;
// const
values
=
simox
::
alg
::
get_values
(
const_map
(),
[](
const
std
::
string
&
value
)
{
std
::
stringstream
ss
;
ss
<<
value
;
return
ss
;
});
// non-const
values
=
simox
::
alg
::
get_values
(
map
,
[](
std
::
string
&
value
)
{
std
::
stringstream
ss
;
ss
<<
value
;
return
ss
;
});
}
BOOST_AUTO_TEST_CASE
(
test_get_value_ptrs_const
)
{
std
::
vector
<
const
std
::
string
*>
values
=
simox
::
alg
::
get_value_ptrs
(
const_map
());
check_equal
(
values
,
const_map
());
}
BOOST_AUTO_TEST_CASE
(
test_get_value_ptrs_non_const
)
{
std
::
vector
<
std
::
string
*>
values
=
simox
::
alg
::
get_value_ptrs
(
map
);
check_equal
(
values
,
map
);
}
BOOST_AUTO_TEST_CASE
(
test_get_value_cptrs_non_const
)
{
std
::
vector
<
const
std
::
string
*>
values
=
simox
::
alg
::
get_value_cptrs
(
map
);
check_equal
(
values
,
map
);
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment