Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
span_tests.cpp File Reference
#include <sysio/vm/span.hpp>
#include <catch2/catch.hpp>
Include dependency graph for span_tests.cpp:

Go to the source code of this file.

Namespaces

namespace  sysio
 
namespace  sysio::vm
 

Functions

 TEST_CASE ("span static_extent tests", "[span_static_extent]")
 
 TEST_CASE ("default constructor", "[span_dynamic_extent]")
 
 TEST_CASE ("array constructor", "[span]")
 
 TEST_CASE ("std::array constructor", "[span]")
 
template<typename T , std::size_t Extent>
bool sysio::vm::operator== (const span< T, Extent > &lhs, const span< T, Extent > &rhs)
 
 TEST_CASE ("span dynamic_extent tests", "[span_dynamic_extent]")
 

Function Documentation

◆ TEST_CASE() [1/5]

TEST_CASE ( "array constructor" ,
"" [span] )

Definition at line 31 of file span_tests.cpp.

31 {
32 static_assert(std::is_constructible_v<span<int>, int(&)[1]>);
33 static_assert(std::is_constructible_v<span<const int>, int(&)[1]>);
34 static_assert(std::is_constructible_v<span<const int>, const int(&)[1]>);
35 static_assert(std::is_constructible_v<span<int, 1>, int(&)[1]>);
36 static_assert(std::is_constructible_v<span<const int, 1>, int(&)[1]>);
37 static_assert(std::is_constructible_v<span<const int, 1>, const int(&)[1]>);
38 static_assert(!std::is_constructible_v<span<int>, long(&)[1]>);
39 static_assert(!std::is_constructible_v<span<int, 1>, int(&)[2]>);
40 static_assert(!std::is_constructible_v<span<int>, const int(&)[1]>);
41 static_assert(!std::is_constructible_v<span<int, 1>, const int(&)[1]>);
42 int a1[1];
43 span<int> s1(a1);
44 CHECK(s1.data() == a1);
45 CHECK(s1.size() == 1);
46}
#define CHECK(cond)
Definition util.h:80
Here is the call graph for this function:

◆ TEST_CASE() [2/5]

TEST_CASE ( "default constructor" ,
"" [span_dynamic_extent] )

Definition at line 22 of file span_tests.cpp.

22 {
23 //static_assert(std::is_constructible_v<span<int, 0>>);
24 static_assert(!std::is_constructible_v<span<int, 1>>);
25 static_assert(std::is_constructible_v<span<int>>);
27 CHECK(s.size() == 0);
28 CHECK(s.data() == nullptr);
29}
char * s

◆ TEST_CASE() [3/5]

TEST_CASE ( "span dynamic_extent tests" ,
"" [span_dynamic_extent] )

Definition at line 72 of file span_tests.cpp.

72 {
73 // currently we only support a static extent of 1
74 int a[10] = {1};
75 span<int> s(a, 10);
76
77 CHECK(s.data() == a);
78 CHECK(s.front() == a[0]);
79 s.front() += 3;
80 CHECK(s.front() == a[0]);
81 CHECK(4 == a[0]);
82
83 span<int> test_a(a, 3);
84 span<int> test_b(a + 7, 3);
85
86 for ( auto& elem : s ) {
87 elem = 7;
88 }
89
90 for ( int i=0; i < 10; i++ ) {
91 CHECK(a[i] == s[i]);
92 }
93
94 CHECK(s.first(3) == span<int>(a, 3));
95 CHECK(s.last(3) == span<int>(a+7, 3));
96 CHECK(s.subspan(3, 3) == span<int>(a+3, 3));
97 CHECK(s.subspan(3, sysio::vm::dynamic_extent) == span<int>(a+3, 7));
98}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ TEST_CASE() [4/5]

TEST_CASE ( "span static_extent tests" ,
"" [span_static_extent] )

Definition at line 7 of file span_tests.cpp.

7 {
8 // currently we only support a static extent of 1
9 int a = 0;
10 span<int, 1> s(&a, 1);
11
12 CHECK(s.data() == std::addressof(a));
13 CHECK(s.front() == a);
14 s.front() += 3;
15 CHECK(s.front() == a);
16 CHECK(3 == a);
17
18 int* lta = &a;
19 CHECK_THROWS_AS(span<int>(&a, lta-1), sysio::vm::span_exception);
20}
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203

◆ TEST_CASE() [5/5]

TEST_CASE ( "std::array constructor" ,
"" [span] )

Definition at line 48 of file span_tests.cpp.

48 {
49 static_assert(std::is_constructible_v<span<int>, std::array<int, 1>&>);
50 static_assert(std::is_constructible_v<span<const int>, std::array<int, 1>&>);
51 static_assert(std::is_constructible_v<span<const int>, const std::array<int, 1>&>);
52 static_assert(std::is_constructible_v<span<int, 1>, std::array<int, 1>&>);
53 static_assert(std::is_constructible_v<span<const int, 1>, std::array<int, 1>&>);
54 static_assert(std::is_constructible_v<span<const int, 1>, const std::array<int, 1>&>);
55 static_assert(!std::is_constructible_v<span<int>, std::array<long, 1>&>);
56 static_assert(!std::is_constructible_v<span<int, 1>, std::array<int, 2>&>);
57 static_assert(!std::is_constructible_v<span<int>, const std::array<int, 1>&>);
58 static_assert(!std::is_constructible_v<span<int, 1>, const std::array<int, 1>&>);
59 std::array<int, 1> a1;
60 span<int> s1(a1);
61 CHECK(s1.data() == a1.data());
62 CHECK(s1.size() == 1);
63}
Here is the call graph for this function: