preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpanTests.cpp
Go to the documentation of this file.
1#include <array>
2#include <string>
3#include <string_view>
4#include <vector>
5
6#include "precice/span.hpp"
7#include "testing/Testing.hpp"
8
9BOOST_AUTO_TEST_SUITE(PreciceTests)
11
12using precice::span;
13
15BOOST_AUTO_TEST_CASE(FromDoubleVector)
16{
18 std::vector<double> v{1.0, 2.0, 3.0, 4.0};
19 span<const double> const_span{v};
20 BOOST_TEST(v == const_span, boost::test_tools::per_element());
21 span<double> mut_span{v};
22 BOOST_TEST(v == mut_span, boost::test_tools::per_element());
23}
24
27{
29 std::vector<int> v{1, 2, 3, 4};
30 span<const int> const_span{v};
31 BOOST_TEST(v == const_span, boost::test_tools::per_element());
32 span<int> mut_span{v};
33 BOOST_TEST(v == mut_span, boost::test_tools::per_element());
34}
35
38{
40 std::string s = "hello there";
41 span<const char> const_span{s};
42 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
43}
44
47{
49 std::vector<char> s{'h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e'};
50 span<const char> const_span{s};
51 BOOST_CHECK_EQUAL_COLLECTIONS(
52 s.begin(), s.end(),
53 const_span.begin(), const_span.end());
54}
55
58{
60 std::string s = "hello there";
61 span<const char> const_span{"hello there"}; // Includes the NULL byte
62
63 BOOST_CHECK_EQUAL_COLLECTIONS(s.begin(), ++s.end(),
64 const_span.begin(), const_span.end());
65}
66
69{
71 std::array<char, 11> s{'h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e'};
72 span<const char> const_span{s};
73
74 BOOST_CHECK_EQUAL_COLLECTIONS(
75 s.begin(), s.end(),
76 const_span.begin(), const_span.end());
77}
78
81{
83 char s[] = "hello there";
84 span<const char> const_span{s}; // Includes the NULL byte
85
86 BOOST_CHECK_EQUAL_COLLECTIONS(
87 s, s + 12,
88 const_span.begin(), const_span.end());
89}
90
93{
95 std::string s = "hello there";
96 std::string &sr = s;
97 span<const char> const_span{sr};
98 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
99}
100
101PRECICE_TEST_SETUP(1_rank)
102BOOST_AUTO_TEST_CASE(FromConstStringRef)
103{
104 PRECICE_TEST();
105 std::string s = "hello there";
106 const std::string &scr = s;
107 span<const char> const_span{scr};
108 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
109}
110
111PRECICE_TEST_SETUP(1_rank)
113{
114 PRECICE_TEST();
115 std::string s = "hello there";
116 char *sp = s.data();
117 span<const char> const_span{sp};
118 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
119}
120
121PRECICE_TEST_SETUP(1_rank)
122BOOST_AUTO_TEST_CASE(FromConstCString)
123{
124 PRECICE_TEST();
125 const char *s = "hello there";
126 span<const char> const_span{s};
127 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
128}
129
130PRECICE_TEST_SETUP(1_rank)
132{
133 PRECICE_TEST();
134 const char *s = "hello there";
135 span<const char> const_span{s};
136 std::string_view sv{const_span.data(), const_span.size()};
137
138 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
139 BOOST_TEST(s == sv);
140}
141
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(FromDoubleVector)
Definition SpanTests.cpp:15
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
T begin(T... args)
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
T data(T... args)
T end(T... args)