CARLA
载入中...
搜索中...
未找到
LibCarla
source
test
common
test_listview.cpp
浏览该文件的文档.
1
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
test.h
"
8
9
#include <
carla/ListView.h
>
10
11
#include <array>
12
#include <cstring>
13
#include <list>
14
#include <set>
15
#include <string>
16
#include <vector>
17
18
using
carla::MakeListView
;
19
20
template
<
typename
Iterator>
21
static
void
TestSequence
(
carla::ListView<Iterator>
view) {
22
int
count = 0;
23
for
(
auto
&&x : view) {
24
ASSERT_EQ(x, count);
25
++count;
26
}
27
ASSERT_EQ(count, 6);
28
}
29
30
TEST
(listview, sequence) {
31
int
array[] = {0, 1, 2, 3, 4, 5};
32
TestSequence
(MakeListView(array));
33
std::array<int, 6u> std_array = {0, 1, 2, 3, 4, 5};
34
TestSequence
(MakeListView(std_array));
35
std::vector<int> vector = {0, 1, 2, 3, 4, 5};
36
TestSequence
(MakeListView(vector));
37
std::list<int> list = {0, 1, 2, 3, 4, 5};
38
TestSequence
(MakeListView(list));
39
std::set<int> set = {0, 1, 2, 3, 4, 5};
40
TestSequence
(MakeListView(set));
41
}
42
43
TEST
(listview,
string
) {
44
std::string str =
"Hello list view!"
;
45
std::string result;
46
for
(
char
c : MakeListView(str)) {
47
result += c;
48
}
49
ASSERT_EQ(result, str);
50
char
hello[6u] = {0};
51
auto
begin = std::begin(hello);
52
for
(
char
c : MakeListView(str.begin(), str.begin() + 5u)) {
53
*begin = c;
54
++begin;
55
}
56
ASSERT_EQ(std::strcmp(hello,
"Hello"
), 0);
57
}
ListView.h
carla::ListView
A view over a range of elements in a container.
Definition
LibCarla/source/carla/ListView.h:19
carla::MakeListView
static auto MakeListView(Iterator begin, Iterator end)
Definition
LibCarla/source/carla/ListView.h:78
test.h
TEST
TEST(listview, sequence)
Definition
test_listview.cpp:30
TestSequence
static void TestSequence(carla::ListView< Iterator > view)
Definition
test_listview.cpp:21
制作者
1.10.0