CARLA
 
载入中...
搜索中...
未找到
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
19
20template <typename Iterator>
22 int count = 0;
23 for (auto &&x : view) {
24 ASSERT_EQ(x, count);
25 ++count;
26 }
27 ASSERT_EQ(count, 6);
28}
29
30TEST(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
43TEST(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}
A view over a range of elements in a container.
static auto MakeListView(Iterator begin, Iterator end)
TEST(listview, sequence)
static void TestSequence(carla::ListView< Iterator > view)