preCICE v3.1.2
Loading...
Searching...
No Matches
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
14BOOST_AUTO_TEST_CASE(FromDoubleVector)
15{
16 PRECICE_TEST(1_rank);
17 std::vector<double> v{1.0, 2.0, 3.0, 4.0};
18 span<const double> const_span{v};
19 BOOST_TEST(v == const_span, boost::test_tools::per_element());
20 span<double> mut_span{v};
21 BOOST_TEST(v == mut_span, boost::test_tools::per_element());
22}
23
25{
26 PRECICE_TEST(1_rank);
27 std::vector<int> v{1, 2, 3, 4};
28 span<const int> const_span{v};
29 BOOST_TEST(v == const_span, boost::test_tools::per_element());
30 span<int> mut_span{v};
31 BOOST_TEST(v == mut_span, boost::test_tools::per_element());
32}
33
35{
36 PRECICE_TEST(1_rank);
37 std::string s = "hello there";
38 span<const char> const_span{s};
39 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
40}
41
43{
44 PRECICE_TEST(1_rank);
45 std::vector<char> s{'h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e'};
46 span<const char> const_span{s};
47 BOOST_CHECK_EQUAL_COLLECTIONS(
48 s.begin(), s.end(),
49 const_span.begin(), const_span.end());
50}
51
53{
54 PRECICE_TEST(1_rank);
55 std::string s = "hello there";
56 span<const char> const_span{"hello there"}; // Includes the NULL byte
57
58 BOOST_CHECK_EQUAL_COLLECTIONS(s.begin(), ++s.end(),
59 const_span.begin(), const_span.end());
60}
61
63{
64 PRECICE_TEST(1_rank);
65 std::array<char, 11> s{'h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e'};
66 span<const char> const_span{s};
67
68 BOOST_CHECK_EQUAL_COLLECTIONS(
69 s.begin(), s.end(),
70 const_span.begin(), const_span.end());
71}
72
74{
75 PRECICE_TEST(1_rank);
76 char s[] = "hello there";
77 span<const char> const_span{s}; // Includes the NULL byte
78
79 BOOST_CHECK_EQUAL_COLLECTIONS(
80 s, s + 12,
81 const_span.begin(), const_span.end());
82}
83
85{
86 PRECICE_TEST(1_rank);
87 std::string s = "hello there";
88 std::string & sr = s;
89 span<const char> const_span{sr};
90 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
91}
92
93BOOST_AUTO_TEST_CASE(FromConstStringRef)
94{
95 PRECICE_TEST(1_rank);
96 std::string s = "hello there";
97 const std::string &scr = s;
98 span<const char> const_span{scr};
99 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
100}
101
103{
104 PRECICE_TEST(1_rank);
105 std::string s = "hello there";
106 char * sp = s.data();
107 span<const char> const_span{sp};
108 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
109}
110
111BOOST_AUTO_TEST_CASE(FromConstCString)
112{
113 PRECICE_TEST(1_rank);
114 const char * s = "hello there";
115 span<const char> const_span{s};
116 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
117}
118
120{
121 PRECICE_TEST(1_rank);
122 const char * s = "hello there";
123 span<const char> const_span{s};
124 std::string_view sv{const_span.data(), const_span.size()};
125
126 BOOST_TEST(s == std::string(const_span.data(), const_span.size()));
127 BOOST_TEST(s == sv);
128}
129
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(FromDoubleVector)
Definition SpanTests.cpp:14
#define PRECICE_TEST(...)
Definition Testing.hpp:27
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)