FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
co-cpp19/src/array19.lib/array19/SliceOf.test.cpp at develop · basicpp/co-cpp19 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
basicpp
/
co-cpp19
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
14
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
SliceOf.test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (44 loc) · 1.08 KB
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
SliceOf.test.cpp
Copy path
File metadata and controls
57 lines (44 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
include
"
SliceOf.h
"
#
include
"
SliceOf.carray.h
"
#
include
"
SliceOf.store.h
"
#
include
<
gtest/gtest.h
>
using
namespace
array19
;
void
constexpr_SliceOf_test
() {
constexpr
static
int
a[
3
] = {
1
,
2
,
3
};
constexpr
auto
s =
sliceOfCArray
(a);
static_assert
(s.
count
() ==
3
);
static_assert
(s[
1
] ==
2
);
constexpr
auto
sum = [&] {
auto
r =
0
;
for
(
auto
v : s) r += v;
return
r;
}();
static_assert
(sum ==
6
);
}
TEST
(SliceOf, Access) {
int
a[
3
] = {
1
,
2
,
3
};
auto
s =
sliceOfCArray
(a);
EXPECT_EQ
(s.
count
(),
3u
);
EXPECT_EQ
(s[
1
],
2
);
auto
sum =
0
;
for
(
auto
v : s) sum += v;
EXPECT_EQ
(sum,
6
);
}
void
mutable_SliceOf_test
() {
constexpr
auto
sa = [] {
int
a[] = {
1
,
2
,
3
};
auto
s =
amendSliceOfCArray
(a);
s[
1
] =
5
;
return
storeSlice<
3
>(s);
}();
static_assert
(sa[
1
] ==
5
);
}
TEST
(SliceOf, Mutate) {
int
a[] = {
1
,
2
,
3
,
4
};
auto
s =
amendSliceOfCArray
(a);
s[
1
] =
5
;
EXPECT_EQ
(a[
1
],
5
);
auto
sa = storeSlice<
4
>(s);
EXPECT_EQ
(sa[
1
],
5
);
EXPECT_EQ
(sa[
3
],
4
);
}
Back
|
FazBrowse Home
|
New Git URL