CARLA
test_listview.cpp
Go to the documentation of this file.
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 
20 template <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 
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};
39  std::set<int> set = {0, 1, 2, 3, 4, 5};
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 }
A view over a range of elements in a container.
TEST(listview, sequence)
static void TestSequence(carla::ListView< Iterator > view)
static auto MakeListView(Iterator begin, Iterator end)