-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBaseline.cpp
More file actions
116 lines (93 loc) · 3.62 KB
/
Baseline.cpp
File metadata and controls
116 lines (93 loc) · 3.62 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2020, University of Freiburg
// Authors: Axel Lehmann <[email protected]>.
// This file is part of osm2rdf.
//
// osm2rdf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// osm2rdf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.
#include <algorithm>
#include "gtest/gtest.h"
namespace osm2rdf {
// Misc tests to ensure (external) library functions work as expected
// ____________________________________________________________________________
TEST(Baseline, set_difference) {
{
std::vector<int> i1{1, 2, 3, 4, 3, 2, 1, 1, 1};
std::vector<int> i2{1, 3};
std::vector<int> result;
std::sort(i1.begin(), i1.end());
const auto it1 = std::unique(i1.begin(), i1.end());
i1.resize(std::distance(i1.begin(), it1));
std::sort(i2.begin(), i2.end());
const auto it2 = std::unique(i2.begin(), i2.end());
i2.resize(std::distance(i2.begin(), it2));
std::set_difference(i1.begin(), i1.end(), i1.begin(), i1.end(),
std::back_inserter(result));
ASSERT_EQ(0, result.size());
}
{
std::vector<int> i1{1, 2, 3, 4, 3, 2, 1, 1, 1};
std::vector<int> i2{1, 3};
std::vector<int> result;
std::sort(i1.begin(), i1.end());
const auto it1 = std::unique(i1.begin(), i1.end());
i1.resize(std::distance(i1.begin(), it1));
std::sort(i2.begin(), i2.end());
const auto it2 = std::unique(i2.begin(), i2.end());
i2.resize(std::distance(i2.begin(), it2));
std::set_difference(i2.begin(), i2.end(), i2.begin(), i2.end(),
std::back_inserter(result));
ASSERT_EQ(0, result.size());
}
{
std::vector<int> i1{1, 2, 3, 4, 3, 2, 1, 1, 1};
std::vector<int> i2{1, 3};
std::vector<int> result;
std::sort(i1.begin(), i1.end());
const auto it1 = std::unique(i1.begin(), i1.end());
i1.resize(std::distance(i1.begin(), it1));
std::sort(i2.begin(), i2.end());
const auto it2 = std::unique(i2.begin(), i2.end());
i2.resize(std::distance(i2.begin(), it2));
std::set_difference(i1.begin(), i1.end(), i2.begin(), i2.end(),
std::back_inserter(result));
ASSERT_EQ(2, result.size());
ASSERT_EQ(2, result[0]);
ASSERT_EQ(4, result[1]);
}
{
std::vector<int> i1{1, 2, 3, 4, 3, 2, 1, 1, 1};
std::vector<int> i2{1, 3};
std::vector<int> result;
std::sort(i1.begin(), i1.end());
const auto it1 = std::unique(i1.begin(), i1.end());
i1.resize(std::distance(i1.begin(), it1));
std::sort(i2.begin(), i2.end());
const auto it2 = std::unique(i2.begin(), i2.end());
i2.resize(std::distance(i2.begin(), it2));
std::set_difference(i2.begin(), i2.end(), i1.begin(), i1.end(),
std::back_inserter(result));
ASSERT_EQ(0, result.size());
}
}
// ____________________________________________________________________________
TEST(Baseline, stdoutRedirectionCOUT) {
// Capture std::cout
std::stringstream buffer;
std::streambuf* sbuf = std::cout.rdbuf();
std::cout.rdbuf(buffer.rdbuf());
std::cout << "Lorem ipsum";
ASSERT_EQ("Lorem ipsum", buffer.str());
// Restore std::cout
std::cout.rdbuf(sbuf);
}
} // namespace osm2rdf